Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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.UserInfoResponseDto;
import com.wayble.server.user.dto.UserInfoUpdateRequestDto;
import com.wayble.server.user.dto.UserRegisterRequestDto;
import com.wayble.server.user.exception.UserErrorCase;
Expand Down Expand Up @@ -67,10 +68,7 @@ public CommonResponse<String> registerUserInfo(
}

@PatchMapping("/info")
@Operation(
summary = "내 정보 수정",
description = "유저가 자신의 정보를 수정합니다."
)
@Operation(summary = "내 정보 수정", description = "유저가 자신의 정보를 수정합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "내 정보 수정 완료"),
@ApiResponse(responseCode = "400", description = "잘못된 요청입니다."),
Expand All @@ -89,4 +87,20 @@ public CommonResponse<String> updateUserInfo(
userInfoService.updateUserInfo(userId, dto);
return CommonResponse.success("내 정보 수정 완료");
}

@GetMapping("/info")
@Operation(summary = "내 정보 조회", description = "현재 로그인된 유저의 상세 정보를 조회합니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "내 정보 조회 성공"),
@ApiResponse(responseCode = "404", description = "유저 정보가 존재하지 않습니다."),
@ApiResponse(responseCode = "401", description = "인증 필요")
})
public CommonResponse<UserInfoResponseDto> getUserInfo() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (!(authentication.getPrincipal() instanceof Long userId)) {
throw new ApplicationException(UserErrorCase.FORBIDDEN);
}
UserInfoResponseDto info = userInfoService.getUserInfo(userId);
return CommonResponse.success(info);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.wayble.server.user.entity.UserType;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.Getter;

Expand All @@ -26,5 +27,10 @@ public class UserInfoRegisterRequestDto {
private UserType userType;

private List<String> disabilityType; // 장애 유형, (userType == DISABLED만 값 존재)

private List<String> mobilityAid; // 이동보조수단, (userType == DISABLED만 값 존재)

// TODO: 현재 와이어프레임에 유저 이미지 등록하는 로직이 없어서 유저 정보 등록에서 이미지 등록 안하면 해당 필드 추후 삭제
@Pattern(regexp = "^(https?://).*", message = "올바른 URL 형식이어야 합니다.")
private String profileImageUrl;
}
20 changes: 20 additions & 0 deletions src/main/java/com/wayble/server/user/dto/UserInfoResponseDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.wayble.server.user.dto;

import com.wayble.server.user.entity.Gender;
import com.wayble.server.user.entity.UserType;
import lombok.Builder;
import lombok.Getter;

import java.util.List;

@Getter
@Builder
public class UserInfoResponseDto {
private String nickname;
private String birthDate;
private Gender gender;
private UserType userType;
private List<String> disabilityType; // 복수 선택 가능
private List<String> mobilityAid; // 복수 선택 가능
private String profileImageUrl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.wayble.server.user.entity.Gender;
import com.wayble.server.user.entity.UserType;
import jakarta.validation.constraints.Pattern;
import lombok.Getter;

import java.util.List;
Expand All @@ -14,4 +15,6 @@ public class UserInfoUpdateRequestDto {
private UserType userType; // GENERAL, DISABLED, COMPANION (nullable)
private List<String> disabilityType; // userType이 DISABLED일 때만 값, 아니면 null
private List<String> mobilityAid; // userType이 DISABLED일 때만 값, 아니면 null
@Pattern(regexp = "^(https?://).*", message = "올바른 URL 형식이어야 합니다.")
private String profileImageUrl; // TODO: 현재 와이어프레임에 유저 이미지 등록하는 로직이 없어서 유저 정보 등록에서 이미지 등록 안하면 해당 필드 추후 삭제
Comment thread
seung-in-Yoo marked this conversation as resolved.
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public enum UserErrorCase implements ErrorCase {
FORBIDDEN(403, 1007, "권한이 없습니다."),
KAKAO_AUTH_FAILED(401, 1008, "카카오 인증에 실패하였습니다."),
USER_INFO_ALREADY_EXISTS(400,1009, "이미 등록된 정보가 있습니다."),
INVALID_BIRTH_DATE(400, 1010, "생년월일 형식이 올바르지 않습니다.");
INVALID_BIRTH_DATE(400, 1010, "생년월일 형식이 올바르지 않습니다."),
USER_INFO_NOT_EXISTS(404,1011, "유저 정보가 존재하지 않습니다.");

private final Integer httpStatusCode;
private final Integer errorCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import com.wayble.server.common.exception.ApplicationException;
import com.wayble.server.user.dto.UserInfoRegisterRequestDto;
import com.wayble.server.user.dto.UserInfoResponseDto;
import com.wayble.server.user.dto.UserInfoUpdateRequestDto;
import com.wayble.server.user.entity.User;
import com.wayble.server.user.entity.UserType;
Expand All @@ -26,7 +27,7 @@ public void registerUserInfo(Long userId, UserInfoRegisterRequestDto dto) {
.orElseThrow(() -> new ApplicationException(UserErrorCase.USER_NOT_FOUND));

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

Expand All @@ -38,6 +39,7 @@ public void registerUserInfo(Long userId, UserInfoRegisterRequestDto dto) {
}
user.setGender(dto.getGender());
user.setUserType(dto.getUserType());
user.updateProfileImageUrl(dto.getProfileImageUrl());

if (dto.getUserType() == UserType.DISABLED) {
// 장애 유형,이동보조수단 설정
Expand Down Expand Up @@ -79,6 +81,11 @@ public void updateUserInfo(Long userId, UserInfoUpdateRequestDto dto) {
user.setUserType(dto.getUserType());
}

// 유저 프로필 이미지 수정
if (dto.getProfileImageUrl() != null) {
user.updateProfileImageUrl(dto.getProfileImageUrl());
}

UserType finalUserType = dto.getUserType() != null ? dto.getUserType() : user.getUserType();
if (finalUserType == UserType.DISABLED) {
if (dto.getDisabilityType() != null) {
Expand All @@ -95,4 +102,22 @@ public void updateUserInfo(Long userId, UserInfoUpdateRequestDto dto) {

userRepository.save(user);
}

@Transactional
public UserInfoResponseDto getUserInfo(Long userId) {
User user = userRepository.findById(userId)
.orElseThrow(() -> new ApplicationException(UserErrorCase.USER_NOT_FOUND));
if (user.getNickname() == null || user.getBirthDate() == null || user.getGender() == null) {
throw new ApplicationException(UserErrorCase.USER_INFO_NOT_EXISTS);
}
return UserInfoResponseDto.builder()
.nickname(user.getNickname())
.birthDate(user.getBirthDate() != null ? user.getBirthDate().toString() : null)
.gender(user.getGender())
.userType(user.getUserType())
.disabilityType(user.getDisabilityType())
.mobilityAid(user.getMobilityAid())
.profileImageUrl(user.getProfileImageUrl())
.build();
}
}
Loading