Skip to content

Commit

Permalink
Merge pull request #26 from 9oormthon-univ/refactor/#25
Browse files Browse the repository at this point in the history
[REFACTOR] 생년월일 추가
  • Loading branch information
haeun1107 authored Nov 19, 2024
2 parents 157b464 + c08bf08 commit f5d518f
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package danpoong.soenter.domain.user.controller;

import danpoong.soenter.base.ApiResponse;
import danpoong.soenter.domain.user.dto.UserDTO.UserResponse.UpdateBirthResponse;
import danpoong.soenter.domain.user.dto.UserDTO.UserRequest.UpdateBirthRequest;
import danpoong.soenter.domain.user.dto.UserDTO.UserResponse.GetUserDetailResponse;
import danpoong.soenter.domain.user.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/users")
Expand All @@ -26,4 +26,13 @@ public ApiResponse<GetUserDetailResponse> getUserDetail(Authentication authentic
GetUserDetailResponse userDetail = userService.getUserDetail(authentication.getName());
return ApiResponse.onSuccess(userDetail);
}

@PatchMapping("/birth")
@Operation(summary = "회원 생년월일 업데이트 API", description = "사용자의 생년월일을 업데이트합니다.")
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공")
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON400", description = "잘못된 요청입니다.")

public ApiResponse<UpdateBirthResponse> updateBirthDate(Authentication authentication, @RequestBody UpdateBirthRequest request) {
return ApiResponse.onSuccess(userService.updateBirth(authentication.getName(), request));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package danpoong.soenter.domain.user.converter;

import danpoong.soenter.domain.user.dto.UserDTO.UserResponse.UpdateBirthResponse;
import danpoong.soenter.domain.user.dto.UserDTO.UserResponse.GetUserDetailResponse;
import danpoong.soenter.domain.user.entity.User;

Expand All @@ -10,4 +11,14 @@ public static GetUserDetailResponse toGetUserDetailResponse(User user) {
.email(user.getEmail())
.build();
}

public static UpdateBirthResponse toUpdateBirthDateResponse(User user) {
return UpdateBirthResponse.builder()
.userId(user.getUserId())
.name(user.getName())
.email(user.getEmail())
.socialType(user.getSocialType())
.birth(user.getBirth())
.build();
}
}
21 changes: 21 additions & 0 deletions src/main/java/danpoong/soenter/domain/user/dto/UserDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,35 @@

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDate;

public class UserDTO {
public static class UserRequest {
@Getter
@NoArgsConstructor
public static class UpdateBirthRequest {
private LocalDate birth;
}
}

public static class UserResponse {
@Getter
@Builder
public static class GetUserDetailResponse {
private String name;
private String email;
}

@Getter
@Builder
public static class UpdateBirthResponse {
private Long userId;
private String name;
private String email;
private String socialType;
private LocalDate birth;
}
}
}
8 changes: 8 additions & 0 deletions src/main/java/danpoong/soenter/domain/user/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import jakarta.persistence.*;
import lombok.*;

import java.time.LocalDate;

@Entity
@Getter
@Builder
Expand All @@ -23,10 +25,16 @@ public class User {

private String password;

@Column
private LocalDate birth;

@Column
private String socialType;

@Column
private String socialId; // 로그인한 소셜 타입의 식별자 값 (일반 로그인 : null)

public void updateBirthDate(LocalDate birth) {
this.birth = birth;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package danpoong.soenter.domain.user.service;

import danpoong.soenter.domain.user.dto.UserDTO.UserResponse.UpdateBirthResponse;
import danpoong.soenter.domain.user.dto.UserDTO.UserRequest.UpdateBirthRequest;
import danpoong.soenter.domain.user.dto.UserDTO.UserResponse.GetUserDetailResponse;

public interface UserService {
GetUserDetailResponse getUserDetail(String userId);
UpdateBirthResponse updateBirth(String userId, UpdateBirthRequest request);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package danpoong.soenter.domain.user.service;

import danpoong.soenter.domain.user.converter.UserConverter;
import danpoong.soenter.domain.user.dto.UserDTO.UserResponse.UpdateBirthResponse;
import danpoong.soenter.domain.user.dto.UserDTO.UserRequest.UpdateBirthRequest;
import danpoong.soenter.domain.user.dto.UserDTO.UserResponse.GetUserDetailResponse;
import danpoong.soenter.domain.user.entity.User;
import danpoong.soenter.domain.user.repository.UserRepository;
Expand All @@ -20,4 +22,13 @@ public GetUserDetailResponse getUserDetail(String userId) {

return UserConverter.toGetUserDetailResponse(user);
}

@Transactional
public UpdateBirthResponse updateBirth(String userId, UpdateBirthRequest request) {
User user = userRepository.findById(Long.valueOf(userId))
.orElseThrow(() -> new RuntimeException("존재하지 않는 사용자입니다."));

user.updateBirthDate(request.getBirth());
return UserConverter.toUpdateBirthDateResponse(user);
}
}

0 comments on commit f5d518f

Please sign in to comment.