Skip to content

Commit

Permalink
Merge pull request #199 from PawWithU/feat/197-patch-intermediary-pro…
Browse files Browse the repository at this point in the history
…file-api

[Feature] 모집자 프로필 수정 API 수정
  • Loading branch information
hojeong2747 authored May 16, 2024
2 parents 6417350 + 2458b1d commit a213b69
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
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

0 comments on commit a213b69

Please sign in to comment.