Skip to content

Commit

Permalink
[merge] 호스트 프로필 수정 API 구현
Browse files Browse the repository at this point in the history
[feat] 호스트 프로필 수정 API 구현
  • Loading branch information
lreowy authored Sep 3, 2024
2 parents 55efb5d + 958640d commit a8e1b95
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package com.pickple.server.api.host.controller;

import com.pickple.server.api.host.dto.request.HostUpdateRequest;
import com.pickple.server.api.host.dto.response.HostByMoimResponse;
import com.pickple.server.api.host.dto.response.HostGetResponse;
import com.pickple.server.api.host.dto.response.HostIntroGetResponse;
import com.pickple.server.api.host.service.HostCommandService;
import com.pickple.server.api.host.service.HostQueryService;
import com.pickple.server.global.common.annotation.HostId;
import com.pickple.server.global.response.ApiResponseDto;
import com.pickple.server.global.response.enums.SuccessCode;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -19,6 +24,7 @@
public class HostController implements HostControllerDocs {

private final HostQueryService hostQueryService;
private final HostCommandService hostCommandService;

@GetMapping("/v2/host")
public ApiResponseDto<HostGetResponse> getHost(@HostId Long hostId) {
Expand All @@ -35,4 +41,11 @@ public ApiResponseDto<HostByMoimResponse> getMoimHost(@PathVariable Long hostId)
public ApiResponseDto<HostIntroGetResponse> getHostIntro(@PathVariable Long hostId) {
return ApiResponseDto.success(SuccessCode.HOSTINTRO_GET_SUCCESS, hostQueryService.getHostIntro(hostId));
}

@PatchMapping("v2/host/{hostId}")
public ApiResponseDto<HostUpdateRequest> updateHostProfile(@PathVariable final Long hostId,
@RequestBody @Valid HostUpdateRequest hostUpdateRequest) {
hostCommandService.updateHostProfile(hostId, hostUpdateRequest);
return ApiResponseDto.success(SuccessCode.HOST_PROFILE_UPDATE_SUCCESS);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.pickple.server.api.host.controller;

import com.pickple.server.api.host.dto.request.HostUpdateRequest;
import com.pickple.server.api.host.dto.response.HostByMoimResponse;
import com.pickple.server.api.host.dto.response.HostGetResponse;
import com.pickple.server.api.host.dto.response.HostIntroGetResponse;
Expand All @@ -13,6 +14,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

@Tag(name = "Host", description = "Host 관련 API")
public interface HostControllerDocs {
Expand Down Expand Up @@ -51,4 +53,16 @@ ApiResponseDto<HostByMoimResponse> getMoimHost(
ApiResponseDto<HostIntroGetResponse> getHostIntro(
@PathVariable Long hostId
);

@Operation(summary = "호스트 프로필 수정")
@ApiResponses(
value = {
@ApiResponse(responseCode = "20035", description = "호스트 프로필 수정 성공"),
@ApiResponse(responseCode = "40405", description = "존재하지 않는 호스트입니다.")
}
)
ApiResponseDto<HostUpdateRequest> updateHostProfile(
@PathVariable final Long hostId,
@RequestBody HostUpdateRequest hostUpdateRequest
);
}
9 changes: 9 additions & 0 deletions src/main/java/com/pickple/server/api/host/domain/Host.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,13 @@ public class Host extends BaseTimeEntity {

@OneToMany(mappedBy = "host", cascade = CascadeType.REMOVE)
private List<Moim> moims = new ArrayList<>();

public void updateHostProfile(String imageUrl, String nickname, String userKeyword, String description,
String link) {
this.imageUrl = imageUrl;
this.nickname = nickname;
this.userKeyword = userKeyword;
this.description = description;
this.link = link;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.pickple.server.api.host.dto.request;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;

public record HostUpdateRequest(

@NotBlank(message = "이미지가 비어있습니다.")
String profileUrl,

@Size(max = 50)
@NotBlank(message = "닉네임이 비어있습니다.")
String nickname,

@Size(max = 50)
@NotBlank(message = "호칭이 비어있습니다.")
String keyword,

@Size(max = 70)
@NotBlank(message = "소개글이 비어있습니다.")
String description,

@Size(max = 50)
@NotBlank(message = "소셜 링크가 비어있습니다.")
String socialLink
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.pickple.server.api.host.service;


import com.pickple.server.api.guest.repository.GuestRepository;
import com.pickple.server.api.host.domain.Host;
import com.pickple.server.api.host.dto.request.HostUpdateRequest;
import com.pickple.server.api.host.repository.HostRepository;
import com.pickple.server.api.submitter.repository.SubmitterRepository;
import com.pickple.server.global.exception.CustomException;
import com.pickple.server.global.response.enums.ErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Transactional
public class HostCommandService {

private final HostRepository hostRepository;
private final GuestRepository guestRepository;
private final SubmitterRepository submitterRepository;

public void updateHostProfile(Long hostId, HostUpdateRequest hostUpdateRequest) {
Host host = hostRepository.findHostByIdOrThrow(hostId);
if (hostRepository.existsByNickname(hostUpdateRequest.nickname()) || guestRepository.existsByNickname(
hostUpdateRequest.nickname()) || submitterRepository.existsByNickname(hostUpdateRequest.nickname())) {
throw new CustomException(ErrorCode.DUPLICATION_NICKNAME);
}
host.updateHostProfile(hostUpdateRequest.profileUrl(), hostUpdateRequest.nickname(),
hostUpdateRequest.keyword(),
hostUpdateRequest.description(), hostUpdateRequest.socialLink());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public enum S3BucketDirectory {
MOIM_PREFIX("moim/"),
NOTICE_PREFIX("notice/"),
REVIEW_PREFIX("review/"),
;
HOST_PROFILE_PREFIX("host/");

private final String name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public enum SuccessCode {
COMMENT_LIST_BY_NOTICE_GET_SUCCESS(20032, HttpStatus.OK, "공지사항에 해당하는 댓글 전체 조회 성공"),
MOIM_SUBMISSION_ALL_GET_SUCCESS(20033, HttpStatus.OK, "모임 참여 신청 전체 조회 성공"),
GUEST_PROFILE_UPDATE_SUCCESS(20034, HttpStatus.OK, "게스트 프로필 수정 성공"),
HOST_PROFILE_UPDATE_SUCCESS(20035, HttpStatus.OK, "호스트 프로필 수정 성공"),
COMMENT_DELETE_SUCCESS(20036, HttpStatus.OK, "공지사항 댓글 삭제 성공"),
REVIEW_LIST_BY_MOIM_GET_SUCCESS(20037, HttpStatus.OK, "모임에 해당하는 리뷰 조회 성공"),
REVIEW_LIST_BY_HOST_GET_SUCCESS(20038, HttpStatus.OK, "호스트에 해당하는 리뷰 전체 조회 성공"),
Expand Down

0 comments on commit a8e1b95

Please sign in to comment.