-
Notifications
You must be signed in to change notification settings - Fork 0
[FEAT] 사용자 마이페이지 정보 조회/수정 api 구현 #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
990f4b6
cd3f9b8
6ca24ea
97f8d4e
23428e8
eca0412
1b50db1
51f0c68
767c68b
bf50ce8
09ee15f
8917088
6f9150a
371b3c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package konkuk.chacall.domain.user.application; | ||
|
|
||
| import konkuk.chacall.domain.user.domain.model.User; | ||
| import konkuk.chacall.domain.user.domain.repository.UserRepository; | ||
| import konkuk.chacall.domain.user.presentation.dto.request.UpdateUserInfoRequest; | ||
| import konkuk.chacall.domain.user.presentation.dto.response.UserResponse; | ||
| import konkuk.chacall.global.common.exception.EntityNotFoundException; | ||
| import konkuk.chacall.global.common.exception.code.ErrorCode; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| public class UserService { | ||
|
|
||
| private final UserRepository userRepository; | ||
|
|
||
| public UserResponse getUserInfo(Long userId) { | ||
| return userRepository.findById(userId) | ||
| .map(UserResponse::from) | ||
| .orElseThrow(() -> new EntityNotFoundException(ErrorCode.USER_NOT_FOUND)); | ||
| } | ||
|
|
||
| @Transactional | ||
| public void updateUserInfo(Long userId, UpdateUserInfoRequest request) { | ||
| User user = userRepository.findById(userId) | ||
| .orElseThrow(() -> new EntityNotFoundException(ErrorCode.USER_NOT_FOUND)); | ||
|
|
||
| user.update(request.name(), request.profileImageUrl(), request.email(), request.gender(), request.termAgreed()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package konkuk.chacall.domain.user.presentation; | ||
|
|
||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.Parameter; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.validation.Valid; | ||
| import konkuk.chacall.domain.user.application.UserService; | ||
| import konkuk.chacall.domain.user.presentation.dto.request.UpdateUserInfoRequest; | ||
| import konkuk.chacall.domain.user.presentation.dto.response.UserResponse; | ||
| import konkuk.chacall.global.common.annotation.ExceptionDescription; | ||
| import konkuk.chacall.global.common.annotation.UserId; | ||
| import konkuk.chacall.global.common.dto.BaseResponse; | ||
| import konkuk.chacall.global.common.swagger.SwaggerResponseDescription; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.web.bind.annotation.*; | ||
|
|
||
| @Tag(name = "User API", description = "전체 사용자(마이페이지) 관련 API") | ||
| @RestController | ||
| @RequestMapping("/users") | ||
| @RequiredArgsConstructor | ||
| public class UserController { | ||
|
|
||
| private final UserService userService; | ||
|
|
||
| @Operation(summary = "[마이페이지] 회원 정보 조회", description = "사용자(고객)의 정보를 조회합니다. (사장님, 일반유저 무관)") | ||
| @ExceptionDescription(SwaggerResponseDescription.GET_USER_INFO) | ||
| @GetMapping("/me") | ||
| public BaseResponse<UserResponse> getUserInfo( | ||
| @Parameter(hidden = true) @UserId final Long userId | ||
| ) { | ||
| return BaseResponse.ok(userService.getUserInfo(userId)); | ||
| } | ||
|
|
||
| @Operation(summary = "[마이페이지] 회원 정보 수정", description = "사용자(고객)의 정보를 수정합니다. (사장님, 일반유저 무관)") | ||
| @ExceptionDescription(SwaggerResponseDescription.UPDATE_USER_INFO) | ||
| @PutMapping("/me") | ||
| public BaseResponse<Void> updateUserInfo( | ||
| @RequestBody @Valid final UpdateUserInfoRequest request, | ||
| @Parameter(hidden = true) @UserId final Long userId | ||
| ) { | ||
| userService.updateUserInfo(userId, request); | ||
|
buzz0331 marked this conversation as resolved.
|
||
|
|
||
| return BaseResponse.ok(null); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package konkuk.chacall.domain.user.presentation.dto.request; | ||
|
|
||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import jakarta.validation.constraints.Email; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.NotNull; | ||
|
|
||
| @Schema(description = "사용자 정보 수정 요청 DTO") | ||
| public record UpdateUserInfoRequest( | ||
|
|
||
| @Schema(description = "프로필 이미지 URL", example = "https://example.com/profile.jpg") | ||
| @NotBlank(message = "프로필 이미지 URL은 비어 있을 수 없습니다.") | ||
| String profileImageUrl, | ||
|
|
||
| @Schema(description = "사용자 이름", example = "홍길동") | ||
| @NotBlank(message = "이름은 비어 있을 수 없습니다.") | ||
| String name, | ||
|
|
||
| @Schema(description = "사용자 이메일", example = "chacall@kokuk.ac.kr") | ||
| @NotBlank(message = "이메일은 비어 있을 수 없습니다.") | ||
| @Email(message = "올바른 이메일 형식이 아닙니다.") | ||
| String email, | ||
|
|
||
| @Schema(description = "사용자 성별", example = "남성") | ||
| @NotBlank(message = "성별은 비어 있을 수 없습니다.") | ||
| String gender, | ||
|
|
||
| @Schema(description = "약관 동의 여부", example = "true") | ||
| @NotNull(message = "약관 동의 여부는 비어 있을 수 없습니다.") | ||
| Boolean termAgreed | ||
| ) { | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,21 @@ | ||||||||||||||||||||||||||||||
| package konkuk.chacall.domain.user.presentation.dto.response; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| import konkuk.chacall.domain.user.domain.model.User; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| public record UserResponse( | ||||||||||||||||||||||||||||||
| String profileImageUrl, | ||||||||||||||||||||||||||||||
| String name, | ||||||||||||||||||||||||||||||
| String email, | ||||||||||||||||||||||||||||||
| String gender, | ||||||||||||||||||||||||||||||
| boolean termAgreed | ||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||
|
Comment on lines
+5
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chain응답 필드명 일관성: termAgreed → termsAgreed로 변경 권장 도메인( 아래 diff 적용 후, 해당 접근자( public record UserResponse(
String profileImageUrl,
String name,
String email,
String gender,
- boolean termAgreed
+ boolean termsAgreed
) {검증 스크립트: 🏁 Script executed: #!/bin/bash
# 'termAgreed' 잔존 사용처 점검
rg -nP -C2 '\btermAgreed\b|\.termAgreed\(\)'Length of output: 1782 필드명 일관성 확보 — termAgreed → termsAgreed로 전파 (필수) 아래 파일들이 아직 termAgreed를 사용중이므로 UserResponse 필드명 변경 시 모든 참조(요청 DTO, 서비스 호출, 테스트, 문서 등)를 일괄 갱신해야 함.
원본 diff(적용 필요): public record UserResponse(
String profileImageUrl,
String name,
String email,
String gender,
- boolean termAgreed
+ boolean termsAgreed
) {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
| public static UserResponse from(User user) { | ||||||||||||||||||||||||||||||
| return new UserResponse( | ||||||||||||||||||||||||||||||
| user.getProfileImageUrl(), | ||||||||||||||||||||||||||||||
| user.getName(), | ||||||||||||||||||||||||||||||
| user.getEmail(), | ||||||||||||||||||||||||||||||
| user.getGender() == null ? null : user.getGender().getValue(), | ||||||||||||||||||||||||||||||
| user.isTermsAgreed() | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
기존 데이터가 있는 테이블에 NOT NULL 컬럼 추가 시 마이그레이션 필요
nullable=false boolean 컬럼 추가는 운영 DB에서 실패할 수 있습니다. 기본값/백필 전략을 포함한 마이그레이션을 선반영하세요.
예시 SQL(선반영 후 제약 강화):
🤖 Prompt for AI Agents