Skip to content
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

[Feature] 모집자 프로필 수정 API 수정 #199

Merged
merged 3 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public ResponseEntity<List<IntermediaryGetDogStatusesResponse>> getIntermediaryD
return ResponseEntity.ok(response);
}

@Operation(summary = "이동봉사 중개 - 홈 화면 정보 조회", description = "홈 화면 정보를 조회합니다.",
@Operation(summary = "모집자 - 홈 화면 정보 조회", description = "홈 화면 정보를 조회합니다.",
security = { @SecurityRequirement(name = "bearer-key") },
responses = {@ApiResponse(responseCode = "200", description = "이동봉사 중개 홈 화면 정보 조회 성공")
, @ApiResponse(responseCode = "400"
Expand All @@ -138,7 +138,7 @@ public ResponseEntity<IntermediaryGetHomeResponse> getIntermediaryHome(@Authenti
return ResponseEntity.ok(response);
}

@Operation(summary = "이동봉사 중개 - 마이페이지 프로필 수정", description = "마이페이지 프로필을 수정합니다.",
@Operation(summary = "모집자 - 마이페이지 프로필 수정", description = "마이페이지 프로필을 수정합니다.",
security = { @SecurityRequirement(name = "bearer-key") },
responses = {@ApiResponse(responseCode = "204", description = "마이페이지 프로필 수정 성공")
, @ApiResponse(responseCode = "400"
Expand All @@ -148,7 +148,7 @@ public ResponseEntity<IntermediaryGetHomeResponse> getIntermediaryHome(@Authenti
@PatchMapping("/intermediaries/my/profile")
public ResponseEntity<Void> intermediaryMyProfile(@AuthenticationPrincipal UserDetails loginUser,
@RequestPart @Valid IntermediaryMyProfileRequest request,
@RequestPart(name = "profileImage", required = false) MultipartFile profileImage) {
@RequestPart(name = "files", required = false) MultipartFile profileImage) {
intermediaryService.intermediaryMyProfile(loginUser.getUsername(), request, profileImage);
return ResponseEntity.noContent().build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.pawwithu.connectdog.domain.intermediary.dto.request;

import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;

public record IntermediaryMyProfileRequest(
@Pattern(regexp = "^(http|https)://[a-zA-Z0-9-.]+\\.[a-zA-Z]{2,}(/\\S*)?$",
message = "url 형식을 입력해 주세요.")
String url,
@Size(max=50, message = "한줄 소개는 50자 이하로 입력해 주세요.")
String intro,
@Size(max=50, message = "문의 받을 연락처는 50자 이하로 입력해 주세요.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,16 @@ public void passwordEncode(PasswordEncoder passwordEncoder) {
this.password = passwordEncoder.encode(this.password);
}

public void updateProfile(String profileImage, String intro, String contact, String guide) {
public void updateProfile(String profileImage, String url, String intro, String contact, String guide) {
this.profileImage = profileImage;
this.url = url;
this.intro = intro;
this.contact = contact;
this.guide = guide;
}

public void updateProfileWithoutImage(String intro, String contact, String guide) {
public void updateProfileWithoutImage(String url, String intro, String contact, String guide) {
this.url = url;
this.intro = intro;
this.contact = contact;
this.guide = guide;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,16 @@ public IntermediaryGetHomeResponse getIntermediaryHome(String email) {
public void intermediaryMyProfile(String email, IntermediaryMyProfileRequest intermediaryMyProfileRequest, MultipartFile profileFile) {
Intermediary intermediary = intermediaryRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(INTERMEDIARY_NOT_FOUND));

String url = intermediaryMyProfileRequest.url();
String intro = intermediaryMyProfileRequest.intro();
String contact = intermediaryMyProfileRequest.contact();
String guide = intermediaryMyProfileRequest.guide();

String profileImage = fileService.uploadFile(profileFile, "intermediary/profileImage");
if (profileImage != null) {
intermediary.updateProfile(profileImage, intro, contact, guide);
intermediary.updateProfile(profileImage, url, intro, contact, guide);
} else {
intermediary.updateProfileWithoutImage(intro, contact, guide);
intermediary.updateProfileWithoutImage(url, intro, contact, guide);
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pawwithu.connectdog.domain.intermediary.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.pawwithu.connectdog.domain.dog.entity.DogSize;
import com.pawwithu.connectdog.domain.intermediary.dto.request.IntermediaryMyProfileRequest;
import com.pawwithu.connectdog.domain.intermediary.dto.request.IntermediaryPasswordRequest;
Expand Down Expand Up @@ -264,17 +265,18 @@ void setUp() {
}

@Test
void 이동봉사_중개_마이페이지_프로필_수정() throws Exception {
void 모집자_마이페이지_프로필_수정() throws Exception {
// given
IntermediaryMyProfileRequest request = new IntermediaryMyProfileRequest("한줄 소개 변경", "문의 받을 연락처 변경", "안내사항 변경");
MockMultipartFile profileImage = new MockMultipartFile("profileImage", "profileImage.png", "multipart/form-data", "uploadFile".getBytes(StandardCharsets.UTF_8));
MockMultipartFile intermediaryMyProfileRequest = new MockMultipartFile("request", null, "application/json", objectMapper.writeValueAsString(request).getBytes(StandardCharsets.UTF_8));
IntermediaryMyProfileRequest intermediaryMyProfileRequest = new IntermediaryMyProfileRequest("https://connectdog2.site", "한줄 소개 변경", "문의 받을 연락처 변경", "안내사항 변경");

MockMultipartFile files = new MockMultipartFile("files", "image1.png", "multipart/form-data", "uploadFile".getBytes(StandardCharsets.UTF_8));
MockMultipartFile request = new MockMultipartFile("request", "", "application/json", objectMapper.registerModule(new JavaTimeModule()).writeValueAsString(intermediaryMyProfileRequest).getBytes(StandardCharsets.UTF_8));

// when
ResultActions result = mockMvc.perform(MockMvcRequestBuilders
.multipart(HttpMethod.PATCH, "/intermediaries/my/profile")
.file(profileImage)
.file(intermediaryMyProfileRequest)
.file(request)
.file(files)
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.MULTIPART_FORM_DATA));

Expand Down
Loading