From 156ab91aac37a196e72b24235f6aa52fb5f2b2b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=ED=99=8D=EC=8B=9D?= <90020593+Daolove0323@users.noreply.github.com> Date: Mon, 11 Nov 2024 23:04:02 +0900 Subject: [PATCH] [Weekly/11] Image/delete (#110) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: ImageService delete * refactor: 해시태그 컨버터 사용 --- .../wouldyouin/_common/error/ErrorCode.java | 2 + .../wouldyouin/_common/vo/Location.java | 1 + .../api/dto/CurationCreateRequest.java | 4 +- .../curation/api/dto/CurationEditRequest.java | 2 +- .../curation/api/dto/CurationResponse.java | 2 +- .../wouldyouin/curation/persist/Curation.java | 12 ++-- .../curation/persist/CurationCard.java | 3 +- .../wouldyouin/event/api/EventController.java | 6 +- .../event/api/dto/EventCreateRequest.java | 4 +- .../event/api/dto/LocationFilter.java | 26 +++++++- ...UserLocation.java => LocationRequest.java} | 4 +- .../event/application/EventService.java | 4 +- .../wouldyouin/event/persist/Event.java | 20 +++--- .../wouldyouin/like/api/dto/LikeResponse.java | 2 +- .../member/api/dto/MemberResponse.java | 2 +- .../api/dto/relation/EventHostResponse.java | 2 +- .../CurationCuratorResponse.java | 2 +- .../api/dto/request/edit/HostEditRequest.java | 7 +- .../member/application/CuratorService.java | 66 +++++++++---------- .../member/application/HostService.java | 2 +- .../wouldyouin/member/persist/BaseMember.java | 2 - .../wouldyouin/member/persist/Curator.java | 21 +++++- .../wouldyouin/member/persist/Host.java | 12 +++- .../member/persist/LikeableMember.java | 6 +- .../wouldyouin/member/persist/Member.java | 9 +-- .../reservation/persist/Reservation.java | 10 +-- .../cokaen/wouldyouin/_global/TestData.java | 24 +++---- .../event/EventControllerUnitTest.java | 6 +- .../event/EventServiceUnitTest.java | 4 +- .../wouldyouin/image/ImageControllerTest.java | 46 +++++++------ .../application/HostServiceUnitTest.java | 3 +- 31 files changed, 183 insertions(+), 133 deletions(-) rename src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/{UserLocation.java => LocationRequest.java} (96%) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java index 9140ed01..6e5f7737 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/error/ErrorCode.java @@ -6,6 +6,8 @@ @Getter public enum ErrorCode { + // TODO: status,code, message 수정 + UNEXPECTED(HttpStatus.BAD_REQUEST.value(), "-1", "예상치 못한 오류가 발생했습니다."), ENTITY_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "-10404", "엔티티를 찾을 수 없습니다."), diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/vo/Location.java b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/vo/Location.java index 240d31d5..459f2f7b 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/_common/vo/Location.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/_common/vo/Location.java @@ -14,4 +14,5 @@ public class Location { Double longitude; Double latitude; + String detailAddress; } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java index 4e584fa6..5000fcec 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationCreateRequest.java @@ -30,7 +30,7 @@ public class CurationCreateRequest { @NotNull(message = "지역은 필수입니다.") private Area area; - private List hashTag; + private List hashTags; private List eventIds; @@ -49,7 +49,7 @@ public Curation toEntity(Curator curator, List curationCards, List .content(this.content) .curationCards(curationCards) .area(this.area) - .hashTag(this.hashTag) + .hashTags(this.hashTags) .events(events) .build(); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationEditRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationEditRequest.java index 2a691007..1d4051d5 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationEditRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationEditRequest.java @@ -26,7 +26,7 @@ public class CurationEditRequest { @NotNull(message = "지역은 필수입니다.") private Area area; - private List hashTag; + private List hashTags; private List eventIds; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java index 7bd2e697..98675d27 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/api/dto/CurationResponse.java @@ -33,7 +33,7 @@ public static CurationResponse from(Curation curation) { .curationCards(curation.getCurationCards().stream() .map(CurationCardResponse::from).toList()) .area(curation.getArea()) - .hashTag(curation.getHashTag()) + .hashTag(curation.getHashTags()) .eventsInfo(curation.getEvents().stream() .map(CurationEventResponse::from).toList()) .createdTime(curation.getCreatedDate()) diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java index 3eb150e1..216ca700 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/Curation.java @@ -69,7 +69,7 @@ public class Curation { @Column(name = "hashtag") @Convert(converter = HashtagConverter.class) - private List hashTag = new ArrayList<>(); + private List hashTags = new ArrayList<>(); @ManyToMany(fetch = FetchType.LAZY) @JoinTable( @@ -88,22 +88,22 @@ public class Curation { private LocalDateTime modifiedDate; @Builder - public Curation(Curator curator, String title, String content, List curationCards, Area area, List hashTag, + public Curation(Curator curator, String title, String content, List curationCards, Area area, List hashTags, List events) { this.curator = curator; this.title = title; this.content = content; - this.curationCards = curationCards; + Optional.ofNullable(curationCards).ifPresent(this::setCurationCards); this.area = area; - this.hashTag = hashTag; - this.events = events; + Optional.ofNullable(hashTags).ifPresent(this::setHashTags); + Optional.ofNullable(events).ifPresent(this::setEvents); } public void updateFrom(CurationEditRequest curationEditRequest, List curationCards, List events) { Optional.ofNullable(curationEditRequest.getTitle()).ifPresent(this::setTitle); Optional.ofNullable(curationEditRequest.getContent()).ifPresent(this::setContent); Optional.ofNullable(curationEditRequest.getArea()).ifPresent(this::setArea); - Optional.ofNullable(curationEditRequest.getHashTag()).ifPresent(this::setHashTag); + Optional.ofNullable(curationEditRequest.getHashTags()).ifPresent(this::setHashTags); Optional.ofNullable(curationCards).ifPresent(this::setCurationCards); Optional.ofNullable(events).ifPresent(this::setEvents); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java index 56403eee..127bfad5 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/curation/persist/CurationCard.java @@ -11,6 +11,7 @@ import jakarta.persistence.OneToMany; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -48,6 +49,6 @@ public CurationCard(String subtitle, String content, Curation curation, List> getEventsByFilterOrderByDistanceAsc( - @ModelAttribute LocationFilter locationFilter, - @Valid @ModelAttribute UserLocation currentLocation, + @Valid @ModelAttribute LocationFilter locationFilter, + @Valid @ModelAttribute LocationRequest currentLocation, @RequestParam(defaultValue = ParamDefaults.TITLE) String title, @RequestParam(defaultValue = ParamDefaults.CATEGORY) Category category, @RequestParam(defaultValue = ParamDefaults.AREA) Area area, diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java index e276a6e2..aec20b45 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/EventCreateRequest.java @@ -8,6 +8,7 @@ import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.Size; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; import lombok.Builder; import lombok.Getter; @@ -53,6 +54,7 @@ public class EventCreateRequest { @NotNull(message = "카테고리는 필수입니다.") private Category category; + // TODO : 이미지 not null 고민, 큐레이션도! private List imageIds; @AssertTrue(message = "종료 시간은 시작 시간 이후여야 합니다.") @@ -65,7 +67,7 @@ public boolean isEndTimeAfterStartTime() { @AssertTrue(message = "이미지는 최대 5개까지 등록할 수 있습니다.") public boolean isImageSizeValid() { - return imageIds == null || imageIds.size() <= 5; + return imageIds.size() <= 5; } public Event toEntity(Host host, List images) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationFilter.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationFilter.java index fa1e923b..4f97fbc5 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationFilter.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationFilter.java @@ -1,5 +1,8 @@ package org.ktc2.cokaen.wouldyouin.event.api.dto; +import jakarta.validation.constraints.AssertTrue; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -11,8 +14,29 @@ @AllArgsConstructor public class LocationFilter { + @Min(value = -90, message = "시작 위도는 -90 이상이어야 합니다.") + @Max(value = 90, message = "시작 위도는 90 이하여야 합니다.") private Double startLatitude = -90.0; + + @Min(value = -180, message = "시작 경도는 -180 이상이어야 합니다.") + @Max(value = 180, message = "시작 경도는 180 이하여야 합니다.") private Double startLongitude = -180.0; + + @Min(value = -90, message = "끝 위도는 -90 이상이어야 합니다.") + @Max(value = 90, message = "끝 위도는 90 이하여야 합니다.") private Double endLatitude = 90.0; + + @Min(value = -180, message = "끝 경도는 -180 이상이어야 합니다.") + @Max(value = 180, message = "끝 경도는 180 이하여야 합니다.") private Double endLongitude = 180.0; -} + + @AssertTrue(message = "시작 위도는 끝 위도보다 작아야 합니다.") + public boolean isStartLatitudeLessThanEndLatitude() { + return startLatitude <= endLatitude; + } + + @AssertTrue(message = "시작 경도는 끝 경도보다 작아야 합니다.") + public boolean isStartLongitudeLessThanEndLongitude() { + return startLongitude <= endLongitude; + } +} \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/UserLocation.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java similarity index 96% rename from src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/UserLocation.java rename to src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java index be0efccd..c6605b2e 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/UserLocation.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/api/dto/LocationRequest.java @@ -12,7 +12,7 @@ @Setter @AllArgsConstructor @NoArgsConstructor -public class UserLocation { +public class LocationRequest { @NotNull(message = "위도 값은 필수입니다.") @Min(value = -90, message = "위도는 -90 이상이어야 합니다.") @@ -23,4 +23,4 @@ public class UserLocation { @Min(value = -180, message = "경도는 -180 이상이어야 합니다.") @Max(value = 180, message = "경도는 180 이하여야 합니다.") private Double longitude; -} +} \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java index eeea3bb2..a5c6c976 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/application/EventService.java @@ -9,7 +9,7 @@ import org.ktc2.cokaen.wouldyouin._common.exception.UnauthorizedException; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin._common.vo.Category; -import org.ktc2.cokaen.wouldyouin.event.api.dto.UserLocation; +import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; @@ -43,7 +43,7 @@ public EventResponse getById(Long id) { } @Transactional(readOnly = true) - public EventSliceResponse getAllByFilterOrderByDistanceAsc(LocationFilter location, UserLocation currentLocation, String title, + public EventSliceResponse getAllByFilterOrderByDistanceAsc(LocationFilter location, LocationRequest currentLocation, String title, Category category, Area area, Pageable pageable, Long beforeLastId) { Slice events = eventRepository.findAllByFilterOrderByDistance( location.getStartLatitude(), location.getStartLongitude(), location.getEndLatitude(), diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java index d715b313..309e37c5 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java @@ -124,16 +124,16 @@ protected Event(String title, String content, Host host, Area area, Location loc // Todo: oneToMany 연관관계에서 모든 null 처리 public void updateFrom(EventEditRequest eventEditRequest, List images) { - this.title = eventEditRequest.getTitle(); - this.content = eventEditRequest.getContent(); - this.area = eventEditRequest.getArea(); - this.location = eventEditRequest.getLocation(); - this.startTime = eventEditRequest.getStartTime(); - this.endTime = eventEditRequest.getEndTime(); - this.price = eventEditRequest.getPrice(); - this.totalSeat = eventEditRequest.getTotalSeat(); - this.category = eventEditRequest.getCategory(); - this.images = images; + Optional.ofNullable(eventEditRequest.getTitle()).ifPresent(this::setTitle); + Optional.ofNullable(eventEditRequest.getContent()).ifPresent(this::setContent); + Optional.ofNullable(eventEditRequest.getArea()).ifPresent(this::setArea); + Optional.ofNullable(eventEditRequest.getLocation()).ifPresent(this::setLocation); + Optional.ofNullable(eventEditRequest.getStartTime()).ifPresent(this::setStartTime); + Optional.ofNullable(eventEditRequest.getEndTime()).ifPresent(this::setEndTime); + Optional.ofNullable(eventEditRequest.getPrice()).ifPresent(this::setPrice); + Optional.ofNullable(eventEditRequest.getTotalSeat()).ifPresent(this::setTotalSeat); + Optional.ofNullable(eventEditRequest.getCategory()).ifPresent(this::setCategory); + Optional.ofNullable(images).ifPresent(this::setImages); } public void decreaseLeftSeat(Integer count) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeResponse.java index f21ac18d..5530179d 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/like/api/dto/LikeResponse.java @@ -23,7 +23,7 @@ public static LikeResponse from(LikeableMember member) { .memberId(member.getId()) .nickname(member.getNickname()) .intro(member.getIntro()) - .hashtags(member.getHashTagList()) + .hashtags(member.getHashtags()) .profileImageUrl(member.getProfileImageUrl()) .build(); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java index 201653e2..5ba6a985 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/MemberResponse.java @@ -51,7 +51,7 @@ public static MemberResponse from(final Host host) { .memberType(host.getMemberType()) .intro(host.getIntro()) .likes(host.getLikes()) - .hashtag(host.getHashTagList()) + .hashtag(host.getHashtags()) .build(); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relation/EventHostResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relation/EventHostResponse.java index f3e9d42b..8d5ffb3f 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relation/EventHostResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relation/EventHostResponse.java @@ -25,7 +25,7 @@ public static EventHostResponse from(Host host) { .profileImageUrl(host.getProfileImage().getName()) .intro(host.getIntro()) .likes(host.getLikes()) - .hashtags(host.getHashTagList()) + .hashtags(host.getHashtags()) .build(); } } \ No newline at end of file diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/CurationCuratorResponse.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/CurationCuratorResponse.java index ed5e85de..123d0eee 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/CurationCuratorResponse.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/relationResponse/CurationCuratorResponse.java @@ -26,7 +26,7 @@ public static CurationCuratorResponse from(Curator curator) { .profileImageUrl(curator.getProfileImageUrl()) .intro(curator.getIntro()) .likes(curator.getLikes()) - .hashtags(curator.getHashTagList()) + .hashtags(curator.getHashtags()) .build(); } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/HostEditRequest.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/HostEditRequest.java index 2e816e36..f9228913 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/HostEditRequest.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/api/dto/request/edit/HostEditRequest.java @@ -2,6 +2,7 @@ import jakarta.annotation.Nullable; +import java.util.List; import lombok.Builder; import lombok.Getter; @@ -9,13 +10,13 @@ public class HostEditRequest extends MemberEditRequestBase { @Nullable private final String intro; - @Nullable private final String hashtag; + @Nullable private final List hashtags; @Builder public HostEditRequest(@Nullable String nickname, @Nullable String phoneNumber, @Nullable Long profileImageId, - @Nullable String intro, @Nullable String hashtag) { + @Nullable String intro, @Nullable List hashtags) { super(nickname, phoneNumber, profileImageId); this.intro = intro; - this.hashtag = hashtag; + this.hashtags = hashtags; } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java index da78d2c7..0332e871 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/CuratorService.java @@ -1,10 +1,11 @@ package org.ktc2.cokaen.wouldyouin.member.application; -import java.util.Optional; import lombok.RequiredArgsConstructor; import org.ktc2.cokaen.wouldyouin.Image.application.MemberImageService; -import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.CuratorEditRequest; +import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; +import org.ktc2.cokaen.wouldyouin._common.exception.EntityNotFoundException; import org.ktc2.cokaen.wouldyouin.member.api.dto.MemberResponse; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.CuratorEditRequest; import org.ktc2.cokaen.wouldyouin.member.persist.BaseMemberRepository; import org.ktc2.cokaen.wouldyouin.member.persist.Curator; import org.ktc2.cokaen.wouldyouin.member.persist.CuratorRepository; @@ -23,10 +24,32 @@ public class CuratorService implements MemberServiceCommonBehavior, LikeableMemb private final BaseMemberRepository baseMemberRepository; private final MemberImageService memberImageService; + @Override + public LikeableMemberService getLikeableMemberService() { + return this; + } + + @Override + @Transactional(readOnly = true) + public MemberResponse getMemberResponseById(Long id) { + return MemberResponse.from(getByIdOrThrow(id)); + } + + @Override + public MemberType getTargetMemberType() { + return MemberType.curator; + } + + @Transactional(readOnly = true) + public Curator getByIdOrThrow(Long id) { + return curatorRepository.findById(id). + orElseThrow(() -> new EntityNotFoundException("해당하는 큐레이터 정보를 찾을 수 없습니다.")); + } + @Transactional public MemberResponse createCurator(Long normalMemberId) { - //TODO: 커스텀 예외 필요 - Member member = memberRepository.findById(normalMemberId).orElseThrow(RuntimeException::new); + Member member = memberRepository.findById(normalMemberId) + .orElseThrow(() -> new EntityNotFoundException("해당하는 멤버 정보를 찾을 수 없습니다.")); // 일반 멤버 정보로 큐레이터 생성 후, 기존 일반멤버 및 BaseMember 정보는 데이터베이스에서 제거 Curator curator = Curator.curatorBuilder() @@ -52,18 +75,13 @@ public MemberResponse createCurator(Long normalMemberId) { return MemberResponse.from(curator); } + // TODO : 반대방향 연관관계 설정 setter? @Transactional public MemberResponse updateCurator(Long curatorId, CuratorEditRequest request) { Curator curator = getByIdOrThrow(curatorId); - - Optional.ofNullable(request.getPhoneNumber()).ifPresent(curator::setPhone); - Optional.ofNullable(request.getNickname()).ifPresent(curator::setNickname); - Optional.ofNullable(request.getArea()).ifPresent(curator::setArea); - Optional.ofNullable(request.getIntro()).ifPresent(curator::setIntro); - Optional.ofNullable(request.getProfileImageId()) - .map(memberImageService::getById) - .ifPresent(curator::setProfileImage); - + MemberImage image = memberImageService.getById(request.getProfileImageId()); + curator.updateFrom(request, image); + image.setBaseMember(curator); return MemberResponse.from(curator); } @@ -72,26 +90,4 @@ public MemberResponse updateCurator(Long curatorId, CuratorEditRequest request) public void deleteById(Long id) { curatorRepository.delete(getByIdOrThrow(id)); } - - @Override - @Transactional(readOnly = true) - public MemberResponse getMemberResponseById(Long id) { - return MemberResponse.from(getByIdOrThrow(id)); - } - - @Transactional(readOnly = true) - public Curator getByIdOrThrow(Long id) { - //TODO: 커스텀 예외 필요 - return curatorRepository.findById(id).orElseThrow(RuntimeException::new); - } - - @Override - public MemberType getTargetMemberType() { - return MemberType.curator; - } - - @Override - public LikeableMemberService getLikeableMemberService() { - return this; - } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java index abc8c8f8..1182a9ff 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/application/HostService.java @@ -39,7 +39,7 @@ public MemberResponse updateHost(Long hostId, HostEditRequest request) { Optional.ofNullable(request.getPhoneNumber()).ifPresent(host::setPhone); Optional.ofNullable(request.getProfileImageId()).map(memberImageService::getById).ifPresent(host::setProfileImage); Optional.ofNullable(request.getIntro()).ifPresent(host::setIntro); - Optional.ofNullable(request.getHashtag()).ifPresent(host::setHashtag); + Optional.ofNullable(request.getHashtags()).ifPresent(host::setHashtags); return MemberResponse.from(host); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java index 9f6d513f..e45dc1c8 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/BaseMember.java @@ -11,7 +11,6 @@ import jakarta.persistence.Inheritance; import jakarta.persistence.InheritanceType; import jakarta.persistence.OneToOne; -import jakarta.persistence.PrimaryKeyJoinColumn; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; @@ -49,7 +48,6 @@ public abstract class BaseMember { @Column(nullable = false) private String phone; - @PrimaryKeyJoinColumn @OneToOne(mappedBy = "baseMember") private MemberImage profileImage; diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java index 25431476..2c74d6bf 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Curator.java @@ -1,19 +1,25 @@ package org.ktc2.cokaen.wouldyouin.member.persist; import jakarta.persistence.Column; +import jakarta.persistence.Convert; import jakarta.persistence.DiscriminatorValue; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.OneToMany; +import java.util.ArrayList; import java.util.List; +import java.util.Optional; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.experimental.SuperBuilder; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; +import org.ktc2.cokaen.wouldyouin._common.converter.HashtagConverter; import org.ktc2.cokaen.wouldyouin._common.vo.Area; import org.ktc2.cokaen.wouldyouin.curation.persist.Curation; +import org.ktc2.cokaen.wouldyouin.member.api.dto.request.edit.CuratorEditRequest; @Getter @Setter @@ -29,10 +35,11 @@ public class Curator extends Member implements LikeableMember { private Integer likes; @Column(nullable = false) - private String hashtag; + @Convert(converter = HashtagConverter.class) + private List hashtags; @OneToMany(mappedBy = "curator", fetch = FetchType.LAZY) - private List curations; + private List curations = new ArrayList<>(); @Builder(builderMethodName = "curatorBuilder") public Curator(AccountType accountType, String email, String nickname, String phone, MemberImage profileImage, Area area, String gender, @@ -40,6 +47,14 @@ public Curator(AccountType accountType, String email, String nickname, String ph super(accountType, MemberType.curator, email, nickname, phone, profileImage, area, gender, socialId); this.intro = ""; this.likes = 0; - this.hashtag = ""; + hashtags = new ArrayList<>(); + } + + public void updateFrom(CuratorEditRequest request, MemberImage image) { + Optional.ofNullable(request.getPhoneNumber()).ifPresent(this::setPhone); + Optional.ofNullable(request.getNickname()).ifPresent(this::setNickname); + Optional.ofNullable(request.getArea()).ifPresent(this::setArea); + Optional.ofNullable(request.getIntro()).ifPresent(this::setIntro); + Optional.ofNullable(image).ifPresent(this::setProfileImage); } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java index 1ef6efee..14d9c80b 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Host.java @@ -1,17 +1,22 @@ package org.ktc2.cokaen.wouldyouin.member.persist; import jakarta.persistence.Column; +import jakarta.persistence.Convert; import jakarta.persistence.DiscriminatorValue; import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.OneToMany; +import java.util.ArrayList; import java.util.List; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.experimental.Helper; +import lombok.experimental.SuperBuilder; import org.ktc2.cokaen.wouldyouin.Image.persist.MemberImage; +import org.ktc2.cokaen.wouldyouin._common.converter.HashtagConverter; import org.ktc2.cokaen.wouldyouin.event.persist.Event; @Getter @@ -31,10 +36,11 @@ public class Host extends BaseMember implements LikeableMember { private Integer likes; @Column(nullable = false) - private String hashtag; + @Convert(converter = HashtagConverter.class) + private List hashtags; @OneToMany(mappedBy = "host", fetch = FetchType.LAZY) - private List events; + private List events = new ArrayList<>(); @Builder protected Host(String email, String nickname, String phone, String hashedPassword, MemberImage profileImage) { @@ -42,6 +48,6 @@ protected Host(String email, String nickname, String phone, String hashedPasswor this.hashedPassword = hashedPassword; this.intro = ""; this.likes = 0; - this.hashtag = ""; + this.hashtags = new ArrayList<>(); } } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/LikeableMember.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/LikeableMember.java index 5fdc4608..9b94d3df 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/LikeableMember.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/LikeableMember.java @@ -17,7 +17,7 @@ public interface LikeableMember { void setLikes(Integer likes); - String getHashtag(); + List getHashtags(); default void increaseLikes() { setLikes(getLikes() + 1); @@ -27,10 +27,6 @@ default void decreaseLikes() { setLikes(getLikes() - 1); } - default List getHashTagList() { - return Arrays.stream(getHashtag().split("#")).toList(); - } - static List getLikeableMemberTypes() { return List.of(MemberType.host, MemberType.curator); } diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java index b5f4d46a..5607afcc 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/member/persist/Member.java @@ -5,6 +5,7 @@ import jakarta.persistence.Entity; import jakarta.persistence.FetchType; import jakarta.persistence.OneToMany; +import java.util.ArrayList; import java.util.List; import lombok.AccessLevel; import lombok.Builder; @@ -40,16 +41,16 @@ public class Member extends BaseMember { private String refreshToken; @OneToMany(mappedBy = "member", fetch = FetchType.LAZY) - private List curatorLikes; + private List curatorLikes = new ArrayList<>(); @OneToMany(mappedBy = "member", fetch = FetchType.LAZY) - private List hostLikes; + private List hostLikes = new ArrayList<>(); @OneToMany(mappedBy = "member", fetch = FetchType.LAZY) - private List reservations; + private List reservations = new ArrayList<>(); @OneToMany(mappedBy = "member", fetch = FetchType.LAZY) - private List reviews; + private List reviews = new ArrayList<>(); // for Curator protected Member(AccountType accountType, MemberType memberType, String email, String nickname, String phone, MemberImage profileImage, Area area, String gender, String socialId) { diff --git a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/Reservation.java b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/Reservation.java index 14d3bbf6..e72ea3d6 100644 --- a/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/Reservation.java +++ b/src/main/java/org/ktc2/cokaen/wouldyouin/reservation/persist/Reservation.java @@ -1,6 +1,5 @@ package org.ktc2.cokaen.wouldyouin.reservation.persist; -import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EntityListeners; @@ -13,6 +12,7 @@ import jakarta.persistence.OneToOne; import jakarta.validation.constraints.NotNull; import java.time.LocalDateTime; +import java.util.Optional; import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; @@ -58,9 +58,9 @@ public class Reservation { @Builder protected Reservation(Member member, Event event, Integer price, Integer quantity) { - this.member = member; - this.event = event; - this.price = price; - this.quantity = quantity; + Optional.ofNullable(member).ifPresent(this::setMember); + Optional.ofNullable(event).ifPresent(this::setEvent); + Optional.ofNullable(price).ifPresent(this::setPrice); + Optional.ofNullable(quantity).ifPresent(this::setQuantity); } } \ No newline at end of file diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java index fc50424b..15e07439 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/_global/TestData.java @@ -109,11 +109,11 @@ public static ImageResponse createValidImageResponse2() { } public static MockMultipartFile createValidMultipartFile1() { - return new MockMultipartFile("image1", "image1.jpg", MediaType.IMAGE_JPEG_VALUE, "imageData1".getBytes()); + return new MockMultipartFile("images", "image1.jpg", MediaType.IMAGE_JPEG_VALUE, "imageData1".getBytes()); } public static MockMultipartFile createValidMultipartFile2() { - return new MockMultipartFile("image2", "image2.png", MediaType.IMAGE_JPEG_VALUE, "imageData2".getBytes()); + return new MockMultipartFile("images", "image2.png", MediaType.IMAGE_JPEG_VALUE, "imageData2".getBytes()); } } @@ -156,7 +156,7 @@ public static Curator createValidCurator() { .build(); ReflectionTestUtils.setField(ret, "Id", validCuratorId); ReflectionTestUtils.setField(ret, "intro", "큐레이터 자기소개입니다."); - ReflectionTestUtils.setField(ret, "hashtag", "#큐레이터#해시태그#입니다"); + ReflectionTestUtils.setField(ret, "hashtags", List.of("#큐레이터", "#해시태그", "#입니다")); ReflectionTestUtils.setField(memberImage, "baseMember", ret); return ret; } @@ -172,7 +172,7 @@ public static Host createValidHost() { .build(); ReflectionTestUtils.setField(ret, "Id", validHostId); ReflectionTestUtils.setField(ret, "intro", "주최자 자기소개입니다."); - ReflectionTestUtils.setField(ret, "hashtag", "#주최자#해시태그#입니다"); + ReflectionTestUtils.setField(ret, "hashtags", List.of("#주최자", "#해시태그", "#입니다")); ReflectionTestUtils.setField(memberImage, "baseMember", ret); return ret; } @@ -212,7 +212,7 @@ public static Event createValidEvent() { .title("title") .content("content") .area(Area.전체) - .location(new Location(132.0, 43.0)) + .location(new Location(132.0, 43.0, "광주 북구 용봉로77")) .startTime(LocalDateTime.now()) .endTime(LocalDateTime.now()) .price(10000) @@ -228,7 +228,7 @@ public static EventCreateRequest createValidEventCreateRequest() { .title("title") .content("content 조홍식씨 최소글자 20자라고 해놓고 안 지켰어요.") .area(Area.전체) - .location(new Location(132.0, 43.0)) + .location(new Location(132.0, 43.0, "광주 북구 용봉로 77")) .startTime(LocalDateTime.of(2025, 10, 1, 9, 0)) .endTime(LocalDateTime.of(2025, 10, 1, 10, 0)) .price(10000) @@ -243,7 +243,7 @@ public static EventEditRequest createValidEventEditRequest() { .title("modifiedTitle") .content("modifiedContent 조홍식씨 최소글자 20자라고 해놓고 안 지켰어요. ") .area(Area.광주) - .location(new Location(232.0, 143.0)) + .location(new Location(232.0, 143.0, "광주 북구 용봉로 77")) .startTime(LocalDateTime.of(2024, 10, 2, 17, 0)) .endTime(LocalDateTime.of(2024, 10, 2, 18, 0)) .price(20000) @@ -257,7 +257,7 @@ public static CurationEventResponse createValidCurationEventResponse() { return CurationEventResponse.builder() .id(1L) .title("title") - .location(new Location(132.0, 43.0)) + .location(new Location(132.0, 43.0, "광주 북구 용봉로 77")) .thumbnailImageUrl("thumbnailImageUrl") .hostProfileImageUrl("hostProfileImageUrl") .hostNickname("nick_curator_12") @@ -321,7 +321,7 @@ public static Curation createValidCuration() { .content("content") .curationCards(List.of()) .area(Area.전체) - .hashTag(List.of("#해시태그1", "#해시태그2")) + .hashTags(List.of("#해시태그1", "#해시태그2")) .events(List.of(EventDomain.createValidEvent())) .build(); } @@ -364,7 +364,7 @@ public static CurationCreateRequest createValidCurationCreateRequest() { .content("큐레이션 카드 내용1 입니다. 큐레이션 카드의 내용은 최소 20자 최대 1000자 입니다.") .curationCards(List.of(createValidCurationCardRequest1())) .area(Area.광주) - .hashTag(List.of("#광주밴드", "#전남대")) + .hashTags(List.of("#광주밴드", "#전남대")) .eventIds(List.of(1L, 2L)) .build(); } @@ -375,7 +375,7 @@ public static CurationEditRequest createValidCurationEditRequest() { .content("큐레이션 내용2 입니다.") .curationCards(List.of(createValidCurationCardRequest2())) .area(Area.서울) - .hashTag(List.of("#서울밴드", "#서울대")) + .hashTags(List.of("#서울밴드", "#서울대")) .eventIds(List.of(3L, 4L)) .build(); } @@ -389,7 +389,7 @@ public static CurationCuratorResponse createCurationCuratorResponse() { .profileImageUrl(curator.getProfileImageUrl()) .intro(curator.getIntro()) .likes(curator.getLikes()) - .hashtags(curator.getHashTagList()) + .hashtags(curator.getHashtags()) .build(); } diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java index 590cdbfb..b19b6299 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventControllerUnitTest.java @@ -32,7 +32,7 @@ import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventSliceResponse; -import org.ktc2.cokaen.wouldyouin.event.api.dto.UserLocation; +import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationRequest; import org.ktc2.cokaen.wouldyouin.event.application.EventService; import org.ktc2.cokaen.wouldyouin._global.TestData.EventDomain; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost; @@ -90,7 +90,7 @@ public void setup() throws Exception { void getEventsByFilterOrderByDistanceAsc() throws Exception { // given LocationFilter locationFilter = new LocationFilter(0.0, 0.0, 10.0, 10.0); - UserLocation currentLocation = new UserLocation(3.0, 2.0); + LocationRequest currentLocation = new LocationRequest(3.0, 2.0); String title = "testTitle"; Category category = Category.공예; Area area = Area.광주; @@ -129,7 +129,7 @@ void getEventsByFilterOrderByDistanceAsc() throws Exception { // then then(eventService).should(times(1)).getAllByFilterOrderByDistanceAsc( any(LocationFilter.class), - any(UserLocation.class), + any(LocationRequest.class), eq(title), eq(category), eq(area), diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java index f36ac5a3..1590e5ec 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/event/EventServiceUnitTest.java @@ -22,7 +22,7 @@ import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventCreateRequest; import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest; -import org.ktc2.cokaen.wouldyouin.event.api.dto.UserLocation; +import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationRequest; import org.ktc2.cokaen.wouldyouin.event.application.EventService; import org.ktc2.cokaen.wouldyouin.event.persist.Event; import org.ktc2.cokaen.wouldyouin.event.persist.EventRepository; @@ -60,7 +60,7 @@ void setUp() { void getAllByFilterOrderByDistanceAsc() { // given LocationFilter location = new LocationFilter(); - UserLocation currentLocation = new UserLocation(3.0, 2.0); + LocationRequest currentLocation = new LocationRequest(3.0, 2.0); String title = "testTitle"; Category category = Category.공예; Area area = Area.광주; diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java index 7ef5f13b..c41c2a58 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/image/ImageControllerTest.java @@ -1,27 +1,35 @@ package org.ktc2.cokaen.wouldyouin.image; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.times; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import java.nio.file.Paths; +import java.util.List; import java.util.UUID; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.ktc2.cokaen.wouldyouin.Image.api.ImageController; +import org.ktc2.cokaen.wouldyouin.Image.api.ImageDomain; import org.ktc2.cokaen.wouldyouin.Image.application.CurationImageService; import org.ktc2.cokaen.wouldyouin.Image.application.ImageServiceFactory; import org.ktc2.cokaen.wouldyouin.Image.application.ImageStorageService; +import org.ktc2.cokaen.wouldyouin._global.TestData.ImageData; import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember; import org.ktc2.cokaen.wouldyouin.auth.application.JwtAuthFilter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.mock.web.MockMultipartFile; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; @@ -84,28 +92,26 @@ void getImage() throws Exception { @WithMockMember void uploadImages() throws Exception { // // given -// MockMultipartFile image1 = ImageData.createValidMultipartFile1(); -// MockMultipartFile image2 = ImageData.createValidMultipartFile2(); -// given((CurationImageService) imageServiceFactory.getImageService(ImageDomain.CURATION)).willReturn(curationImageService); -// given(curationImageService.saveImages(List.of(image1, image2))) -// .willReturn(List.of(ImageData.createValidImageResponse1(), ImageData.createValidImageResponse2())); -// -//// // when -// mockMvc.perform(multipart("/api/images") -// .file(ImageData.createValidMultipartFile1()) -// .file(ImageData.createValidMultipartFile2()) -// .contentType(MediaType.MULTIPART_FORM_DATA) -// .param("type", ImageDomain.CURATION.name()) -// .with(csrf())) -// .andDo(print()) -// .andExpect(status().isOk()); -// .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON)) // 응답 콘텐츠 타입 확인 -// .andExpect(MockMvcResultMatchers.jsonPath("$.data[0].imageName").value("image1.png")) // 첫 번째 이미지 이름 확인 -// .andExpect(MockMvcResultMatchers.jsonPath("$.data[1].imageName").value("image2.jpg")); // 두 번째 이미지 이름 확인 + MockMultipartFile image1 = ImageData.createValidMultipartFile1(); + MockMultipartFile image2 = ImageData.createValidMultipartFile2(); + given((CurationImageService) imageServiceFactory.getImageService(ImageDomain.CURATION)).willReturn(curationImageService); + given(curationImageService.saveImages(List.of(image1, image2))) + .willReturn(List.of(ImageData.createValidImageResponse1(), ImageData.createValidImageResponse2())); + +// // when + mockMvc.perform(multipart("/api/images?type=CURATION") + .file(ImageData.createValidMultipartFile1()) + .file(ImageData.createValidMultipartFile2()) + .contentType(MediaType.MULTIPART_FORM_DATA) + .param("type", ImageDomain.CURATION.name()) + .with(csrf())) + .andDo(print()) + .andExpect(status().isOk()); + // ArgumentCaptor captor = ArgumentCaptor.forClass(CurationCreateRequest.class); // CurationCreateRequest request = CurationDomain.createValidCurationCreateRequest(); -// -// // when + + // when // mockMvc.perform(post("/api/curations") // .with(csrf()) // .contentType(MediaType.APPLICATION_JSON) diff --git a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java index 3d3c7921..25c13d4c 100644 --- a/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java +++ b/src/test/java/org/ktc2/cokaen/wouldyouin/member/application/HostServiceUnitTest.java @@ -7,6 +7,7 @@ import static org.mockito.BDDMockito.then; import static org.mockito.Mockito.times; +import java.util.List; import java.util.Optional; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -94,7 +95,7 @@ void updateHost() { .phoneNumber(TestUtil.getOrNull("010-1010-8888")) .profileImageId(TestUtil.getOrNull(newProfileImageId)) .intro(TestUtil.getOrNull("new intro")) - .hashtag(TestUtil.getOrNull("#new#hashtag")) + .hashtags(TestUtil.getOrNull(List.of("#new", "#hashtag"))) .build(); given(hostRepository.findById(validHost.getId())).willReturn(Optional.of(validHost));