Skip to content

Commit a993e29

Browse files
authored
[FEAT] 유저 정보 조회 API 개발 (#56)
* 🩹fix: h2 엔드포인트 인가 무시 적용 * 🩹fix: phone_number 필드 삭제 * ✨feat: 사용자 정보 조회 API 개발 - api/v1/user/{userId} 엔드포인트 개발 - 비정규화 컬럼 추가 - .http 테스트 추가 * ✨feat: 코드리뷰 피드백 적용
1 parent a686741 commit a993e29

File tree

13 files changed

+153
-27
lines changed

13 files changed

+153
-27
lines changed

src/main/java/team/wego/wegobackend/auth/application/AuthService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public SignupResponse signup(SignupRequest request) {
4747

4848
User user = User.builder().email(request.getEmail())
4949
.password(passwordEncoder.encode(request.getPassword())).nickName(request.getNickName())
50-
.phoneNumber(request.getPhoneNumber()).role(Role.ROLE_USER) //default
50+
.role(Role.ROLE_USER) //default
5151
.build();
5252

5353
userRepository.save(user);

src/main/java/team/wego/wegobackend/auth/application/dto/request/SignupRequest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,4 @@ public class SignupRequest {
2020
@NotBlank(message = "이름은 필수입니다")
2121
private String nickName;
2222

23-
@NotBlank(message = "전화번호는 필수입니다")
24-
@Pattern(regexp = "^01[016789]-?\\d{3,4}-?\\d{4}$", message = "올바른 전화번호 형식이 아닙니다")
25-
private String phoneNumber;
2623
}

src/main/java/team/wego/wegobackend/auth/application/dto/response/SignupResponse.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,13 @@ public class SignupResponse {
2222

2323
private String nickName;
2424

25-
private String phoneNumber;
26-
2725
private LocalDateTime createdAt;
2826

2927
public static SignupResponse from(User user) {
3028
return SignupResponse.builder()
3129
.userId(user.getId())
3230
.email(user.getEmail())
3331
.nickName(user.getNickName())
34-
.phoneNumber(user.getPhoneNumber())
3532
.createdAt(user.getCreatedAt())
3633
.build();
3734
}

src/main/java/team/wego/wegobackend/common/security/SecurityConfig.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
2929

3030
http
3131
.authorizeHttpRequests((auth) -> auth
32-
.requestMatchers("/h2-console/**").permitAll()
3332
.requestMatchers(SecurityEndpoints.PUBLIC_PATTERNS).permitAll()
3433
.anyRequest().authenticated()
3534
);

src/main/java/team/wego/wegobackend/common/security/SecurityEndpoints.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class SecurityEndpoints {
66
"/api/v*/auth/**",
77
"/api/v*/docs/**",
88
"/api/v*/health",
9+
"/h2-console/**",
910
"/error"
1011
};
1112
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package team.wego.wegobackend.user.application;
2+
3+
import lombok.RequiredArgsConstructor;
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.springframework.stereotype.Service;
6+
import org.springframework.transaction.annotation.Transactional;
7+
import team.wego.wegobackend.user.application.dto.response.UserInfoResponse;
8+
import team.wego.wegobackend.user.domain.User;
9+
import team.wego.wegobackend.user.exception.UserNotFoundException;
10+
import team.wego.wegobackend.user.repository.UserRepository;
11+
12+
@Slf4j
13+
@Service
14+
@RequiredArgsConstructor
15+
public class UserService {
16+
17+
private final UserRepository userRepository;
18+
19+
@Transactional(readOnly = true)
20+
public UserInfoResponse getProfile(Long userId) {
21+
22+
User user = userRepository.findById(userId)
23+
.orElseThrow(UserNotFoundException::new);
24+
25+
return UserInfoResponse.from(user);
26+
}
27+
}

src/main/java/team/wego/wegobackend/user/application/dto/response/UserInfoResponse.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,39 @@ public class UserInfoResponse {
1919

2020
private String email;
2121

22-
private Role role;
23-
2422
private String nickName;
2523

26-
private String phoneNumber;
27-
2824
private String mbti;
2925

3026
private String profileImage;
3127

3228
private String profileMessage;
3329

34-
private Boolean isNotificationEnabled;
30+
private int followeesCnt;
31+
32+
private int followersCnt;
3533

36-
private Boolean isDeleted;
34+
private int groupJoinedCnt;
35+
36+
private int groupCreatedCnt;
37+
38+
private Boolean isNotificationEnabled;
3739

3840
private LocalDateTime createdAt;
3941

4042
public static UserInfoResponse from(User user) {
4143
return UserInfoResponse.builder()
4244
.userId(user.getId())
4345
.email(user.getEmail())
44-
.role(user.getRole())
4546
.nickName(user.getNickName())
46-
.phoneNumber(user.getPhoneNumber())
4747
.mbti(user.getMbti())
4848
.profileImage(user.getProfileImage())
4949
.profileMessage(user.getProfileMessage())
50+
.followeesCnt(user.getFolloweesCnt())
51+
.followersCnt(user.getFollowersCnt())
52+
.groupJoinedCnt(user.getGroupJoinedCnt())
53+
.groupCreatedCnt(user.getGroupCreatedCnt())
5054
.isNotificationEnabled(user.getNotificationEnabled())
51-
.isDeleted(user.getDeleted())
5255
.createdAt(user.getCreatedAt())
5356
.build();
5457
}

src/main/java/team/wego/wegobackend/user/domain/User.java

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ public class User extends BaseTimeEntity {
4040
@Column(name = "nick_name", length = 50, nullable = false, unique = true)
4141
private String nickName;
4242

43-
@Column(name = "phone_number", length = 20)
44-
private String phoneNumber;
45-
4643
@Column(name = "mbti", length = 10)
4744
private String mbti;
4845

@@ -52,19 +49,72 @@ public class User extends BaseTimeEntity {
5249
@Column(name = "profile_message", length = 500)
5350
private String profileMessage;
5451

52+
@Column(name = "followee_count")
53+
private int followeesCnt;
54+
55+
@Column(name = "follower_count")
56+
private int followersCnt;
57+
58+
@Column(name = "group_joined_count")
59+
private int groupJoinedCnt;
60+
61+
@Column(name = "group_created_count")
62+
private int groupCreatedCnt;
63+
5564
@Column(name = "notification_enabled", nullable = false)
5665
private Boolean notificationEnabled = false;
5766

5867
@Column(name = "is_deleted", nullable = false)
5968
private Boolean deleted = false;
6069

6170
@Builder
62-
public User(String email, String password, String nickName, String phoneNumber, Role role) {
71+
public User(String email, String password, String nickName, Role role) {
6372
this.email = email;
6473
this.password = password;
6574
this.nickName = nickName;
66-
this.phoneNumber = phoneNumber;
6775
this.role = role != null ? role : Role.ROLE_USER;
6876
}
6977

78+
// ===== 카운트 증가 메서드 =====
79+
80+
public void increaseFolloweeCount() {
81+
this.followeesCnt++;
82+
}
83+
84+
public void decreaseFolloweeCount() {
85+
if (this.followeesCnt > 0) {
86+
this.followeesCnt--;
87+
}
88+
}
89+
90+
public void increaseFollowerCount() {
91+
this.followersCnt++;
92+
}
93+
94+
public void decreaseFollowerCount() {
95+
if (this.followersCnt > 0) {
96+
this.followersCnt--;
97+
}
98+
}
99+
100+
public void increaseGroupJoinedCount() {
101+
this.groupJoinedCnt++;
102+
}
103+
104+
public void decreaseGroupJoinedCount() {
105+
if (this.groupJoinedCnt > 0) {
106+
this.groupJoinedCnt--;
107+
}
108+
}
109+
110+
public void increaseGroupCreatedCount() {
111+
this.groupCreatedCnt++;
112+
}
113+
114+
public void decreaseGroupCreatedCount() {
115+
if (this.groupCreatedCnt > 0) {
116+
this.groupCreatedCnt--;
117+
}
118+
}
119+
70120
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package team.wego.wegobackend.user.exception;
2+
3+
import team.wego.wegobackend.common.exception.AppErrorCode;
4+
import team.wego.wegobackend.common.exception.AppException;
5+
6+
public class UserNotFoundException extends AppException {
7+
8+
public UserNotFoundException() {
9+
super(AppErrorCode.USER_NOT_FOUND);
10+
}
11+
}

src/main/java/team/wego/wegobackend/user/presentation/UserController.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,25 @@
77
import org.springframework.http.ResponseEntity;
88
import org.springframework.security.core.annotation.AuthenticationPrincipal;
99
import org.springframework.web.bind.annotation.GetMapping;
10+
import org.springframework.web.bind.annotation.PathVariable;
1011
import org.springframework.web.bind.annotation.RequestMapping;
1112
import org.springframework.web.bind.annotation.RestController;
1213
import team.wego.wegobackend.common.response.ApiResponse;
1314
import team.wego.wegobackend.common.security.CustomUserDetails;
15+
import team.wego.wegobackend.user.application.UserService;
16+
import team.wego.wegobackend.user.application.dto.response.UserInfoResponse;
1417

1518
@Slf4j
1619
@RestController
1720
@RequiredArgsConstructor
1821
@RequestMapping("/api/v1/user")
1922
public class UserController {
2023

24+
private final UserService userService;
25+
2126
@GetMapping("/test")
22-
public ResponseEntity<ApiResponse<String>> test(@AuthenticationPrincipal CustomUserDetails userDetails) {
27+
public ResponseEntity<ApiResponse<String>> test(
28+
@AuthenticationPrincipal CustomUserDetails userDetails) {
2329

2430
log.info(LocalDateTime.now() + "test endpoint call, userId -> {}", userDetails.getId());
2531
return ResponseEntity
@@ -30,4 +36,14 @@ public ResponseEntity<ApiResponse<String>> test(@AuthenticationPrincipal CustomU
3036
"Test Success"
3137
));
3238
}
39+
40+
@GetMapping("{userId}")
41+
public ResponseEntity<ApiResponse<UserInfoResponse>> profile(@PathVariable Long userId) {
42+
UserInfoResponse response = userService.getProfile(userId);
43+
44+
return ResponseEntity
45+
.status(HttpStatus.OK)
46+
.body(ApiResponse.success(200,
47+
response));
48+
}
3349
}

0 commit comments

Comments
 (0)