Skip to content

Commit 77fe03b

Browse files
authored
[Feat/#70] 사용자 초대 코드 조회 API 구현 (#71)
## 📌 관련 이슈 - close #70 ## ✨ 변경 사항 - 사용자 초대 코드 조회 API 추가
1 parent 4aee04d commit 77fe03b

4 files changed

Lines changed: 32 additions & 0 deletions

File tree

src/main/java/com/swyp/server/domain/user/controller/UserController.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.swyp.server.domain.user.controller;
22

3+
import com.swyp.server.domain.user.dto.InviteCodeResponse;
34
import com.swyp.server.domain.user.dto.ProfileRequest;
45
import com.swyp.server.domain.user.dto.UserResponse;
56
import com.swyp.server.domain.user.service.UserService;
@@ -47,4 +48,11 @@ public ResponseEntity<ApiResponse<Void>> agreeToTerms(@AuthenticationPrincipal L
4748
userService.agreeToTerms(userId);
4849
return ResponseEntity.ok(ApiResponse.success(null));
4950
}
51+
52+
@Operation(summary = "내 초대 코드 확인")
53+
@GetMapping("me/invite-code")
54+
public ResponseEntity<ApiResponse<InviteCodeResponse>> getInviteCode(
55+
@AuthenticationPrincipal Long userId) {
56+
return ResponseEntity.ok(ApiResponse.success(userService.getInviteCode(userId)));
57+
}
5058
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.swyp.server.domain.user.dto;
2+
3+
import com.swyp.server.domain.user.entity.User;
4+
5+
public record InviteCodeResponse(String inviteCode) {
6+
public static InviteCodeResponse from(User user) {
7+
return new InviteCodeResponse(user.getInviteCode());
8+
}
9+
}

src/main/java/com/swyp/server/domain/user/service/UserService.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.swyp.server.domain.user.service;
22

33
import com.swyp.server.domain.auth.repository.RefreshTokenRepository;
4+
import com.swyp.server.domain.user.dto.InviteCodeResponse;
45
import com.swyp.server.domain.user.dto.UserResponse;
56
import com.swyp.server.domain.user.entity.Role;
67
import com.swyp.server.domain.user.entity.User;
@@ -60,6 +61,19 @@ public UserResponse getMe(Long userId) {
6061
return UserResponse.from(user);
6162
}
6263

64+
@Transactional(readOnly = true)
65+
public InviteCodeResponse getInviteCode(Long userId) {
66+
User user =
67+
userRepository
68+
.findById(userId)
69+
.orElseThrow(() -> new CustomException(ErrorCode.USER_NOT_FOUND));
70+
71+
if (!user.isProfileCompleted()) {
72+
throw new CustomException(ErrorCode.PROFILE_NOT_COMPLETED);
73+
}
74+
return InviteCodeResponse.from(user);
75+
}
76+
6377
@Transactional
6478
public void updateProfile(Long userId, String nickname, UserType userType) {
6579
User user =

src/main/java/com/swyp/server/global/exception/ErrorCode.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public enum ErrorCode {
2121
// User
2222
USER_NOT_FOUND(40401, 404, "사용자를 찾을 수 없습니다."),
2323
DUPLICATE_EMAIL(40901, 409, "이미 사용 중인 이메일입니다."),
24+
PROFILE_NOT_COMPLETED(40026, 400, "프로필 설정 완료 후 이용할 수 있습니다."),
2425

2526
// Todos
2627
TODO_NOT_FOUND(40402, 404, "할 일을 찾을 수 없습니다."),

0 commit comments

Comments
 (0)