Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import com.wayble.server.common.config.security.jwt.JwtTokenProvider;
import com.wayble.server.common.exception.ApplicationException;
import com.wayble.server.common.response.CommonResponse;
import com.wayble.server.user.dto.UserInfoRegisterRequestDto;
import com.wayble.server.user.dto.UserLoginRequestDto;
import com.wayble.server.user.dto.UserRegisterRequestDto;
import com.wayble.server.user.dto.token.TokenResponseDto;
import com.wayble.server.user.exception.UserErrorCase;
import com.wayble.server.user.service.UserInfoService;
import com.wayble.server.user.service.UserService;
import com.wayble.server.user.service.auth.AuthService;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -17,6 +19,8 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

Expand All @@ -29,6 +33,7 @@ public class UserController {
private final UserService userService;
private final AuthService authService;
private final JwtTokenProvider jwtProvider;
private final UserInfoService userInfoService;

@PostMapping("/signup")
@Operation(
Expand Down Expand Up @@ -112,4 +117,23 @@ public CommonResponse<String> logout(
return CommonResponse.success("로그아웃에 성공하였습니다.");
}

@PostMapping("/info")
@Operation(summary = "내 정보 등록", description = "유저의 상세 정보를 최초 1회 등록합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "내 정보 등록 완료"),
@ApiResponse(responseCode = "400", description = "이미 등록된 정보가 있습니다."),
@ApiResponse(responseCode = "404", description = "유저를 찾을 수 없습니다."),
@ApiResponse(responseCode = "401", description = "인증 필요")
})
public CommonResponse<String> registerUserInfo(
@RequestBody @Valid UserInfoRegisterRequestDto req
) {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (!(authentication.getPrincipal() instanceof Long userId)) {
throw new ApplicationException(UserErrorCase.FORBIDDEN);
}

userInfoService.registerUserInfo(userId, req);
return CommonResponse.success("내 정보 등록 완료");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.wayble.server.user.dto;


import com.wayble.server.user.entity.Gender;
import com.wayble.server.user.entity.UserType;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Getter;

@Getter
public class UserInfoRegisterRequestDto {
@NotBlank(message = "닉네임은 필수입니다.")
@Size(max = 8, message = "닉네임은 8자 이하여야 합니다.")
private String nickname;

@NotBlank(message = "생년월일은 필수입니다.")
private String birthDate; // YYYY-MM-DD

@NotNull(message = "성별은 필수입니다.")
private Gender gender;

@NotNull(message = "유저 타입은 필수입니다.")
private UserType userType;

private String disabilityType; // 장애 유형, (userType == DISABLED만 값 존재)
private String mobilityAid; // 이동보조수단, (userType == DISABLED만 값 존재)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
import jakarta.validation.constraints.NotNull;

public record UserLoginRequestDto(
@NotBlank(message = "이름 또는 닉네임은 필수입니다")
String name,

@NotBlank(message = "이메일은 필수입니다")
@Email(message = "유효한 이메일 형식이 아닙니다")
String email,
Expand Down
24 changes: 23 additions & 1 deletion src/main/java/com/wayble/server/user/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,17 @@ public class User extends BaseEntity {

@Enumerated(EnumType.STRING)
@Column(name = "user_type", nullable = false)
private UserType userType;
private UserType userType; // DISABLED,COMPANION,GENERAL

@Column(name = "profile_image_url")
private String profileImageUrl;

@Column(name = "disability_type")
private String disabilityType; // 장애 유형 (발달장애,시각장애,지체장애,청각장애)

@Column(name = "mobility_aid")
private String mobilityAid; // 이동 보조 수단 (안내견,지팡이,동행인,휠체어)

@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Review> reviewList = new ArrayList<>();

Expand Down Expand Up @@ -88,4 +94,20 @@ public void updateProfileImageUrl(String profileImageUrl) {
public void setNickname(String nickname) {
this.nickname = nickname;
}

public void setDisabilityType(String disabilityType) {
this.disabilityType = disabilityType;
}
public void setMobilityAid(String mobilityAid) {
this.mobilityAid = mobilityAid;
}
public void setBirthDate(LocalDate birthDate) {
this.birthDate = birthDate;
}
public void setGender(Gender gender) {
this.gender = gender;
}
public void setUserType(UserType userType) {
this.userType = userType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public enum UserErrorCase implements ErrorCase {
USER_ALREADY_EXISTS(400, 1005, "이미 존재하는 회원입니다."),
INVALID_CREDENTIALS(400, 1006, "아이디 혹은 비밀번호가 잘못되었습니다."),
FORBIDDEN(403, 1007, "권한이 없습니다."),
KAKAO_AUTH_FAILED(401, 1008, "카카오 인증에 실패하였습니다.");
KAKAO_AUTH_FAILED(401, 1008, "카카오 인증에 실패하였습니다."),
USER_INFO_ALREADY_EXISTS(400,1009, "이미 등록된 정보가 있습니다."),
INVALID_BIRTH_DATE(400, 1010, "생년월일 형식이 올바르지 않습니다.");

private final Integer httpStatusCode;
private final Integer errorCode;
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/com/wayble/server/user/service/UserInfoService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.wayble.server.user.service;


import com.wayble.server.common.exception.ApplicationException;
import com.wayble.server.user.dto.UserInfoRegisterRequestDto;
import com.wayble.server.user.entity.User;
import com.wayble.server.user.entity.UserType;
import com.wayble.server.user.exception.UserErrorCase;
import com.wayble.server.user.repository.UserRepository;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.format.DateTimeParseException;

@Service
@RequiredArgsConstructor
public class UserInfoService {
private final UserRepository userRepository;

@Transactional
public void registerUserInfo(Long userId, UserInfoRegisterRequestDto dto) {
User user = userRepository.findById(userId)
.orElseThrow(() -> new ApplicationException(UserErrorCase.USER_NOT_FOUND));

// 이미 등록된 정보가 있으면 에러 처리
if (user.getNickname() != null) {
throw new ApplicationException(UserErrorCase.USER_INFO_ALREADY_EXISTS);
}

user.setNickname(dto.getNickname());
try {
user.setBirthDate(LocalDate.parse(dto.getBirthDate()));
} catch (DateTimeParseException e) {
throw new ApplicationException(UserErrorCase.INVALID_BIRTH_DATE);
}
user.setGender(dto.getGender());
user.setUserType(dto.getUserType());

if (dto.getUserType() == UserType.DISABLED) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dto의 userType은 String이고 UserType.DISABLED는 구조체값인데 둘이 == 비교 연산이 가능한지 궁금합니다..!
둘의 타입을 다르게 할 거라면 UserType.DISABLED.name()로 String 값 구한 뒤, equals() 연산하는게 맞을 것 같아요..!
(제가 잘못 알고 있을 수도 있습니다!)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재 UserInfoRegisterRequestDto의 userType 필드는 UserType에서 enum 타입이라서 == 비교를 써도 되는거 같다고 생각했는데 혹시 제가 잘못 생각한거일까요!? 추가로 궁금해서 찾아봤더니 만약에 프론트에서 "DISABLED" 같은 String 값이 넘어온다면, 컨트롤러에서 UserType userType으로 받으면 Spring이 알아서 변환해준다고 하는데 그렇다면 이 코드를 고쳐야하는지 그대로 둬도 되는지도 궁금합니다!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 제가 잘못봤네요! register dto에서 disabilityType이 String인데, userType이 String으로 저장된 걸로 잘못 봤어요 ㅎㅎ

// 장애 유형,이동보조수단 설정
user.setDisabilityType(dto.getDisabilityType());
user.setMobilityAid(dto.getMobilityAid());
} else {
user.setDisabilityType(null);
user.setMobilityAid(null);
}

userRepository.save(user);
}
}