Skip to content

Commit

Permalink
[featy][#93] 온보딩 상태 조회 & 온보딩 상태 업데이트 api 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-june-young committed Aug 30, 2024
1 parent 25a7a06 commit 0e678a3
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -34,4 +36,20 @@ public ResponseEntity<UserInfoResponse> updateMemberJob(
return ResponseEntity.ok(null);
}

@GetMapping("/onboard-status")
public ResponseEntity<UserOnboardStatusGetResponse> getMemberOnboardStatus(
@AuthUser User user
) {
return ResponseEntity.ok(userService.getUserOnboardStatus(user));
}

@PutMapping("/onboard-status")
public ResponseEntity<Void> updateMemberOnboardStatus(
@AuthUser User user,
@RequestBody UserOnboardStatusUpdateRequest request
) {
userService.updateUserOnboardStatus(user, request.onboardStatus());
return ResponseEntity.ok(null);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.server.bbo_gak.domain.user.dto.request;

public record UserOnboardStatusUpdateRequest(String onboardStatus) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.server.bbo_gak.domain.user.dto.response;

public record UserOnboardStatusGetResponse(
String onboardStatus
) {

}
Original file line number Diff line number Diff line change
@@ -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)));
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/server/bbo_gak/domain/user/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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();


Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, "지원하지 않는 파일 확장자입니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));

}
}
}
10 changes: 6 additions & 4 deletions src/test/resources/user-test-data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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');

0 comments on commit 0e678a3

Please sign in to comment.