-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/97 봉사자 프로필 수정 #103
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
0bc38be
8d674f8
84b18be
6a5a286
80a5e62
74b535f
9c15bec
8ce6885
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,53 @@ | ||
| package com.somemore.volunteer.controller; | ||
|
|
||
| import com.somemore.global.common.response.ApiResponse; | ||
| import com.somemore.imageupload.dto.ImageUploadRequestDto; | ||
| import com.somemore.imageupload.usecase.ImageUploadUseCase; | ||
| import com.somemore.volunteer.dto.request.VolunteerProfileUpdateRequestDto; | ||
| import com.somemore.volunteer.usecase.UpdateVolunteerProfileUseCase; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.security.access.annotation.Secured; | ||
| import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
| import org.springframework.web.bind.annotation.PutMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestPart; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import org.springframework.web.multipart.MultipartFile; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| import static org.springframework.http.MediaType.MULTIPART_FORM_DATA_VALUE; | ||
|
|
||
| @RestController | ||
| @Slf4j | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/profile") | ||
| @Tag(name = "PUT Volunteer", description = "봉사자 프로필 수정") | ||
| public class VolunteerProfileCommandController { | ||
|
|
||
| private final UpdateVolunteerProfileUseCase updateVolunteerProfileUseCase; | ||
| private final ImageUploadUseCase imageUploadUseCase; | ||
|
|
||
| @Secured("ROLE_VOLUNTEER") | ||
| @Operation(summary = "프로필 수정", description = "현재 로그인된 사용자의 프로필을 수정합니다.") | ||
| @PutMapping(consumes = MULTIPART_FORM_DATA_VALUE) | ||
| public ApiResponse<String> updateProfile( | ||
| @AuthenticationPrincipal String volunteerId, | ||
| @Valid @RequestPart("data") VolunteerProfileUpdateRequestDto requestDto, | ||
| @RequestPart(value = "img_file", required = false) MultipartFile image) { | ||
|
|
||
| String imgUrl = imageUploadUseCase.uploadImage(new ImageUploadRequestDto(image)); | ||
|
|
||
| updateVolunteerProfileUseCase.update( | ||
| UUID.fromString(volunteerId), | ||
| requestDto, | ||
| imgUrl | ||
| ); | ||
|
|
||
| return ApiResponse.ok("프로필 수정 성공"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package com.somemore.volunteer.dto.request; | ||
|
|
||
| import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
| import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
| import io.swagger.v3.oas.annotations.media.Schema; | ||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.Size; | ||
| import lombok.Builder; | ||
|
|
||
| @Builder | ||
| @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
| public record VolunteerProfileUpdateRequestDto( | ||
|
|
||
| @Schema(description = "봉사자 닉네임", example = "making") | ||
| @NotBlank(message = "닉네임은 필수 값입니다.") | ||
| @Size(max = 10, message = "닉네임은 최대 10자까지 입력 가능합니다.") | ||
| String nickname, | ||
|
|
||
| @Schema(description = "봉사자 소개글", example = "저는 다양한 봉사활동에 관심이 많은 봉사자입니다.") | ||
| @NotBlank(message = "소개글은 필수 값입니다.") | ||
| @Size(max = 100, message = "소개글은 최대 100자까지 입력 가능합니다.") | ||
| String introduce | ||
| ) { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,8 +7,8 @@ | |
| import io.swagger.v3.oas.annotations.media.Schema; | ||
|
|
||
| @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
| @Schema(description = "봉사자 응답 DTO") | ||
| public record VolunteerResponseDto( | ||
| @Schema(description = "봉사자 프로필 응답 DTO") | ||
| public record VolunteerProfileResponseDto( | ||
| @Schema(description = "봉사자 ID", example = "123e4567-e89b-12d3-a456-426614174000") | ||
| String volunteerId, | ||
|
|
||
|
|
@@ -30,30 +30,30 @@ public record VolunteerResponseDto( | |
| @Schema(description = "총 봉사 횟수", example = "20") | ||
| Integer totalVolunteerCount, | ||
|
|
||
| @Schema(description = "봉사자 상세 정보", implementation = VolunteerDetailResponseDto.class) | ||
| VolunteerDetailResponseDto volunteerDetailResponseDto | ||
| @Schema(description = "봉사자 상세 정보", implementation = VolunteerDetailProfileResponseDto.class) | ||
| VolunteerDetailProfileResponseDto volunteerDetailProfileResponseDto | ||
| ) { | ||
|
Collaborator
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. API 응답에서 필드명으로 "key": "value"로 나가서
Collaborator
Author
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. 좋아요! 명세에 적은 details로 변경하면 깔끔할 것 같습니다. 감사합니다 |
||
|
|
||
| public static VolunteerResponseDto from( | ||
| public static VolunteerProfileResponseDto from( | ||
| Volunteer volunteer, | ||
| VolunteerDetail volunteerDetail | ||
| ) { | ||
| return new VolunteerResponseDto( | ||
| return new VolunteerProfileResponseDto( | ||
| volunteer.getId().toString(), | ||
| volunteer.getNickname(), | ||
| volunteer.getImgUrl(), | ||
| volunteer.getIntroduce(), | ||
| volunteer.getTier().name(), | ||
| volunteer.getTotalVolunteerHours(), | ||
| volunteer.getTotalVolunteerCount(), | ||
| VolunteerDetailResponseDto.from(volunteerDetail) | ||
| VolunteerDetailProfileResponseDto.from(volunteerDetail) | ||
| ); | ||
| } | ||
|
|
||
| public static VolunteerResponseDto from( | ||
| public static VolunteerProfileResponseDto from( | ||
| Volunteer volunteer | ||
| ) { | ||
| return new VolunteerResponseDto( | ||
| return new VolunteerProfileResponseDto( | ||
| volunteer.getId().toString(), | ||
| volunteer.getNickname(), | ||
| volunteer.getImgUrl(), | ||
|
|
@@ -66,8 +66,8 @@ public static VolunteerResponseDto from( | |
| } | ||
|
|
||
| @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
| @Schema(description = "봉사자 상세 응답 DTO") | ||
| private record VolunteerDetailResponseDto( | ||
| @Schema(description = "봉사자 상세 프로필 응답 DTO") | ||
| private record VolunteerDetailProfileResponseDto( | ||
| @Schema(description = "이름", example = "홍길동") | ||
| String name, | ||
|
|
||
|
|
@@ -83,10 +83,10 @@ private record VolunteerDetailResponseDto( | |
| @Schema(description = "연락처", example = "010-1234-5678") | ||
| String contactNumber | ||
| ) { | ||
| public static VolunteerDetailResponseDto from( | ||
| public static VolunteerDetailProfileResponseDto from( | ||
| VolunteerDetail volunteerDetail | ||
| ) { | ||
| return new VolunteerDetailResponseDto( | ||
| return new VolunteerDetailProfileResponseDto( | ||
| volunteerDetail.getName(), | ||
| volunteerDetail.getEmail(), | ||
| volunteerDetail.getGender().name(), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package com.somemore.volunteer.service; | ||
|
|
||
| import com.somemore.global.exception.BadRequestException; | ||
| import com.somemore.volunteer.domain.Volunteer; | ||
| import com.somemore.volunteer.dto.request.VolunteerProfileUpdateRequestDto; | ||
| import com.somemore.volunteer.repository.VolunteerRepository; | ||
| import com.somemore.volunteer.usecase.UpdateVolunteerProfileUseCase; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_VOLUNTEER; | ||
|
|
||
| @Slf4j | ||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional | ||
| public class UpdateVolunteerProfileService implements UpdateVolunteerProfileUseCase { | ||
|
|
||
| private final VolunteerRepository volunteerRepository; | ||
|
|
||
| @Override | ||
| public void update(UUID volunteerId, VolunteerProfileUpdateRequestDto requestDto, String imgUrl) { | ||
| Volunteer volunteer = volunteerRepository.findById(volunteerId) | ||
| .orElseThrow(() -> new BadRequestException(NOT_EXISTS_VOLUNTEER)); | ||
|
|
||
| volunteer.updateWith(requestDto, imgUrl); | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.somemore.volunteer.usecase; | ||
|
|
||
| import com.somemore.volunteer.dto.request.VolunteerProfileUpdateRequestDto; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| public interface UpdateVolunteerProfileUseCase { | ||
|
|
||
| void update(UUID volunteerId, VolunteerProfileUpdateRequestDto requestDto, String imgUrl); | ||
| } |
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.
Good 입니다