diff --git a/src/main/java/com/server/bbo_gak/domain/user/controller/UserController.java b/src/main/java/com/server/bbo_gak/domain/user/controller/UserController.java index a9c63b3..f469fe7 100644 --- a/src/main/java/com/server/bbo_gak/domain/user/controller/UserController.java +++ b/src/main/java/com/server/bbo_gak/domain/user/controller/UserController.java @@ -1,7 +1,9 @@ package com.server.bbo_gak.domain.user.controller; import com.server.bbo_gak.domain.user.dto.request.UserJobUpdateRequest; +import com.server.bbo_gak.domain.user.dto.request.UserOnboardStatusUpdateRequest; import com.server.bbo_gak.domain.user.dto.response.UserInfoResponse; +import com.server.bbo_gak.domain.user.dto.response.UserOnboardStatusGetResponse; import com.server.bbo_gak.domain.user.entity.User; import com.server.bbo_gak.domain.user.service.UserService; import com.server.bbo_gak.global.annotation.AuthUser; @@ -34,4 +36,20 @@ public ResponseEntity updateMemberJob( return ResponseEntity.ok(null); } + @GetMapping("/onboard-status") + public ResponseEntity getMemberOnboardStatus( + @AuthUser User user + ) { + return ResponseEntity.ok(userService.getUserOnboardStatus(user)); + } + + @PutMapping("/onboard-status") + public ResponseEntity updateMemberOnboardStatus( + @AuthUser User user, + @RequestBody UserOnboardStatusUpdateRequest request + ) { + userService.updateUserOnboardStatus(user, request.onboardStatus()); + return ResponseEntity.ok(null); + } + } diff --git a/src/main/java/com/server/bbo_gak/domain/user/dto/request/UserOnboardStatusUpdateRequest.java b/src/main/java/com/server/bbo_gak/domain/user/dto/request/UserOnboardStatusUpdateRequest.java new file mode 100644 index 0000000..d05443a --- /dev/null +++ b/src/main/java/com/server/bbo_gak/domain/user/dto/request/UserOnboardStatusUpdateRequest.java @@ -0,0 +1,4 @@ +package com.server.bbo_gak.domain.user.dto.request; + +public record UserOnboardStatusUpdateRequest(String onboardStatus) { +} diff --git a/src/main/java/com/server/bbo_gak/domain/user/dto/response/UserOnboardStatusGetResponse.java b/src/main/java/com/server/bbo_gak/domain/user/dto/response/UserOnboardStatusGetResponse.java new file mode 100644 index 0000000..73096a1 --- /dev/null +++ b/src/main/java/com/server/bbo_gak/domain/user/dto/response/UserOnboardStatusGetResponse.java @@ -0,0 +1,7 @@ +package com.server.bbo_gak.domain.user.dto.response; + +public record UserOnboardStatusGetResponse( + String onboardStatus +) { + +} diff --git a/src/main/java/com/server/bbo_gak/domain/user/entity/OnboardStatus.java b/src/main/java/com/server/bbo_gak/domain/user/entity/OnboardStatus.java new file mode 100644 index 0000000..1777eea --- /dev/null +++ b/src/main/java/com/server/bbo_gak/domain/user/entity/OnboardStatus.java @@ -0,0 +1,23 @@ +package com.server.bbo_gak.domain.user.entity; + +import com.server.bbo_gak.global.error.exception.ErrorCode; +import com.server.bbo_gak.global.error.exception.NotFoundException; +import java.util.Arrays; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum OnboardStatus { + NOT_STARTED("온보딩_미완료"), + COMPLETED("온보딩_완료"); + + private final String value; + + public static OnboardStatus findByValue(String value) { + return Arrays.stream(OnboardStatus.values()) + .filter(onboardStatus -> onboardStatus.getValue().equals(value)) + .findFirst() + .orElseThrow((() -> new NotFoundException(ErrorCode.ONBOARD_STATUS_NOT_FOUND))); + } +} diff --git a/src/main/java/com/server/bbo_gak/domain/user/entity/User.java b/src/main/java/com/server/bbo_gak/domain/user/entity/User.java index 3c04048..5ad67a3 100644 --- a/src/main/java/com/server/bbo_gak/domain/user/entity/User.java +++ b/src/main/java/com/server/bbo_gak/domain/user/entity/User.java @@ -40,16 +40,24 @@ public class User extends BaseEntity { @Enumerated(EnumType.STRING) private Job job; + @Enumerated(EnumType.STRING) + private OnboardStatus onboardStatus; + // User 생성 팩토리 메서드 public static User from(OauthInfo oauthInfo) { return User.builder() .role(UserRole.USER) .oauthInfo(oauthInfo) .job(Job.UNDEFINE) + .onboardStatus(OnboardStatus.NOT_STARTED) .build(); } public void updateJob(Job job) { this.job = job; } + + public void updateOnboardStatus(OnboardStatus onboardStatus) { + this.onboardStatus = onboardStatus; + } } diff --git a/src/main/java/com/server/bbo_gak/domain/user/service/UserService.java b/src/main/java/com/server/bbo_gak/domain/user/service/UserService.java index bef4c4b..81e470b 100644 --- a/src/main/java/com/server/bbo_gak/domain/user/service/UserService.java +++ b/src/main/java/com/server/bbo_gak/domain/user/service/UserService.java @@ -1,6 +1,7 @@ package com.server.bbo_gak.domain.user.service; import com.server.bbo_gak.domain.auth.dto.response.oauth.OauthUserInfoResponse; +import com.server.bbo_gak.domain.user.dto.response.UserOnboardStatusGetResponse; import com.server.bbo_gak.domain.user.entity.User; public interface UserService { @@ -11,8 +12,12 @@ public interface UserService { void updateUserJob(User user, String job); + void updateUserOnboardStatus(User user, String onboardStatus); + void getUser(); + UserOnboardStatusGetResponse getUserOnboardStatus(User user); + void deleteUser(); diff --git a/src/main/java/com/server/bbo_gak/domain/user/service/UserServiceImpl.java b/src/main/java/com/server/bbo_gak/domain/user/service/UserServiceImpl.java index 264069d..aa17091 100644 --- a/src/main/java/com/server/bbo_gak/domain/user/service/UserServiceImpl.java +++ b/src/main/java/com/server/bbo_gak/domain/user/service/UserServiceImpl.java @@ -1,7 +1,9 @@ package com.server.bbo_gak.domain.user.service; import com.server.bbo_gak.domain.auth.dto.response.oauth.OauthUserInfoResponse; +import com.server.bbo_gak.domain.user.dto.response.UserOnboardStatusGetResponse; import com.server.bbo_gak.domain.user.entity.Job; +import com.server.bbo_gak.domain.user.entity.OnboardStatus; import com.server.bbo_gak.domain.user.entity.User; import com.server.bbo_gak.domain.user.entity.UserRepository; import lombok.RequiredArgsConstructor; @@ -34,11 +36,22 @@ public void updateUserJob(User user, String job) { userRepository.save(user); } + @Transactional + public void updateUserOnboardStatus(User user, String onboardStatus){ + user.updateOnboardStatus(OnboardStatus.findByValue(onboardStatus)); + userRepository.save(user); + } + @Override public void getUser() { } + @Override + public UserOnboardStatusGetResponse getUserOnboardStatus(User user) { + return new UserOnboardStatusGetResponse(user.getOnboardStatus().getValue()); + } + @Override public void deleteUser() { diff --git a/src/main/java/com/server/bbo_gak/global/error/exception/ErrorCode.java b/src/main/java/com/server/bbo_gak/global/error/exception/ErrorCode.java index 98d8633..04ab3c2 100644 --- a/src/main/java/com/server/bbo_gak/global/error/exception/ErrorCode.java +++ b/src/main/java/com/server/bbo_gak/global/error/exception/ErrorCode.java @@ -33,6 +33,7 @@ public enum ErrorCode { //User USER_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 유저를 찾을 수 없습니다."), JOB_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 직업을 찾을 수 없습니다"), + ONBOARD_STATUS_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 온보딩 상태를 찾을 수 없습니다"), //Image IMAGE_FILE_EXTENSION_NOT_FOUND(HttpStatus.BAD_REQUEST, "지원하지 않는 파일 확장자입니다."), diff --git a/src/test/java/com/server/bbo_gak/domain/user/controller/UserControllerTest.java b/src/test/java/com/server/bbo_gak/domain/user/controller/UserControllerTest.java index e2ae63f..6ad2516 100644 --- a/src/test/java/com/server/bbo_gak/domain/user/controller/UserControllerTest.java +++ b/src/test/java/com/server/bbo_gak/domain/user/controller/UserControllerTest.java @@ -3,6 +3,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.server.bbo_gak.domain.user.dto.request.UserJobUpdateRequest; +import com.server.bbo_gak.domain.user.dto.request.UserOnboardStatusUpdateRequest; +import com.server.bbo_gak.domain.user.dto.response.UserOnboardStatusGetResponse; import com.server.bbo_gak.global.AbstractRestDocsTests; import com.server.bbo_gak.global.RestDocsFactory; import org.junit.jupiter.api.Nested; @@ -40,4 +42,54 @@ class 직군선택 { } } + + @Nested + class 온보딩상태_조회 { + + @Test + public void 성공_온보딩_완료_상태() throws Exception { + + //given + UserOnboardStatusGetResponse response = new UserOnboardStatusGetResponse("온보딩_완료"); + + //then + mockMvc.perform(restDocsFactory.createRequest(DEFAULT_URL + "/onboard-status", null, HttpMethod.GET, + objectMapper)) + .andExpect(status().isOk()) + .andDo(restDocsFactory.getSuccessResource("[온보딩상태_조회] 성공", "온보딩상태 조회", "user", null, response)); + + } + + @Test + public void 성공_온보딩_미완료_상태() throws Exception { + + //given + UserOnboardStatusGetResponse response = new UserOnboardStatusGetResponse("온보딩_미완료"); + + //then + mockMvc.perform(restDocsFactory.createRequest(DEFAULT_URL + "/onboard-status", null, HttpMethod.GET, + objectMapper)) + .andExpect(status().isOk()) + .andDo(restDocsFactory.getSuccessResource("[온보딩상태_조회] 성공", "온보딩상태 조회", "user", null, response)); + + } + } + + @Nested + class 온보딩상태_업데이트 { + + @Test + public void 성공() throws Exception { + + //given + UserOnboardStatusUpdateRequest request = new UserOnboardStatusUpdateRequest("온보딩_완료"); + + //then + mockMvc.perform(restDocsFactory.createRequest(DEFAULT_URL + "/onboard-status", request, HttpMethod.PUT, + objectMapper)) + .andExpect(status().isOk()) + .andDo(restDocsFactory.getSuccessResource("[온보딩상태_업데이트] 성공", "온보딩상태 업데이트", "user", request, null)); + + } + } } diff --git a/src/test/resources/user-test-data.sql b/src/test/resources/user-test-data.sql index b39437a..894d2c1 100644 --- a/src/test/resources/user-test-data.sql +++ b/src/test/resources/user-test-data.sql @@ -17,12 +17,14 @@ from recruit_season; delete from users; -INSERT INTO users (deleted, created_at, update_at, user_id, dtype, email, login_id, name, password, role, job) +INSERT INTO users (deleted, created_at, update_at, user_id, dtype, email, login_id, name, password, role, job, + onboard_status) VALUES (false, '2024-07-24 21:27:20.000000', '2024-07-24 21:27:21.000000', 1, 'AuthTestUser', 'email', 'test', 'test', - 'test123', 'USER', 'UNDEFINE'); + 'test123', 'USER', 'UNDEFINE', 'NOT_STARTED'); -INSERT INTO users( deleted, created_at, update_at, user_id, dtype, role, oauth_id, name, email, provider, job) -VALUES(false, '2024-07-24 21:27:20.000000', '2024-07-24 21:27:21.000000', 2, 'User', 'USER', 'oauthId', 'name', 'email', 'GOOGLE', 'UNDEFINE'); +INSERT INTO users( deleted, created_at, update_at, user_id, dtype, role, oauth_id, name, email, provider, job, onboard_status) +VALUES(false, '2024-07-24 21:27:20.000000', '2024-07-24 21:27:21.000000', 2, 'User', 'USER', 'oauthId', 'name', + 'email', 'GOOGLE', 'DEVELOPER', 'COMPLETED'); INSERT INTO refresh_token (id, token) VALUES (1, 'abcd1234');