Skip to content

Commit

Permalink
업스트림 숑숑
Browse files Browse the repository at this point in the history
  • Loading branch information
Daolove0323 committed Nov 15, 2024
1 parent fe1bcd2 commit 02d8614
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package org.ktc2.cokaen.wouldyouin.advertisement.api.dto;

import java.time.LocalDateTime;
import java.util.Optional;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.ktc2.cokaen.wouldyouin.advertisement.persist.Advertisement;
import org.ktc2.cokaen.wouldyouin.image.persist.AdvertisementImage;
import org.ktc2.cokaen.wouldyouin.image.persist.Image;

@Builder
@EqualsAndHashCode
Expand All @@ -21,7 +24,10 @@ public static AdvertisementResponse from(Advertisement advertisement) {
return AdvertisementResponse.builder()
.id(advertisement.getId())
.title(advertisement.getTitle())
.imageUrl(advertisement.getAdvertisementImage().getName())
.imageUrl(Optional.of(advertisement)
.map((ad) -> advertisement.getAdvertisementImage())
.map(Image::getName)
.orElse(""))
.startTime(advertisement.getStartTime())
.endTime(advertisement.getEndTime())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,16 @@
import lombok.Builder;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;

@Getter
@RequiredArgsConstructor
@Builder
@ToString
public class OauthResourcesResponse {

private final String nickname;
private final String email;
private final String socialId;
private final String profileImageUrl;

@Override
public String toString() {
return "OauthResourcesResponse{" +
"nickname='" + nickname + '\'' +
", email='" + email + '\'' +
", socialId='" + socialId + '\'' +
", profileImageUrl='" + profileImageUrl + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ public class CurationCreateRequest {
private List<Long> eventIds;

@AssertTrue(message = "큐레이션 카드의 개수는 1개 이상 10개 이하이어야 합니다.")
public boolean isCurationCardsSizeValid() {
if (this.curationCards == null) {
return false;
}
return 1 <= this.curationCards.size() && this.curationCards.size() <= 10;
private boolean isCurationCardsSizeValid() {
return curationCards != null && 1 <= this.curationCards.size() && this.curationCards.size() <= 10;
}

public Curation toEntity(Curator curator, List<CurationCard> curationCards,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ public class Curation {
public Curation(Curator curator, String title, String content, List<CurationCard> curationCards,
Area area, List<String> hashtags,
List<Event> events, String thumbnailUrl) {
this.curator = curator;
this.title = title;
this.content = content;
Optional.ofNullable(curator).ifPresent(this::setCurator);
Optional.ofNullable(title).ifPresent(this::setTitle);
Optional.ofNullable(content).ifPresent(this::setContent);
Optional.ofNullable(curationCards).ifPresent(this::setCurationCards);
this.area = area;
Optional.ofNullable(area).ifPresent(this::setArea);
Optional.ofNullable(hashtags).ifPresent(this::setHashtags);
Optional.ofNullable(events).ifPresent(this::setEvents);
Optional.ofNullable(thumbnailUrl).ifPresent(this::setThumbnailUrl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public class CurationCard {

@Builder
public CurationCard(String subtitle, String content, Curation curation, List<CurationImage> images) {
this.subtitle = subtitle;
this.content = content;
this.curation = curation;
Optional.ofNullable(subtitle).ifPresent(this::setSubtitle);
Optional.ofNullable(content).ifPresent(this::setContent);
Optional.ofNullable(curation).ifPresent(this::setCuration);
Optional.ofNullable(images).ifPresent(this::setCurationImages);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ public interface CurationRepository extends JpaRepository<Curation, Long> {
@Query("SELECT C FROM Curation C JOIN FETCH C.curator "
+ "WHERE C.curator.id = :curatorId AND C.id < :lastId "
+ "ORDER BY C.id DESC")
Slice<Curation> findAllByCuratorOrderByCreatedDateDesc(Long curatorId, Long lastId,
Pageable pageable);
Slice<Curation> findAllByCuratorOrderByCreatedDateDesc(Long curatorId, Long lastId, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public class EventCreateRequest {
@NotNull(message = "카테고리는 필수입니다.")
private Category category;

// TODO : 이미지 not null 고민, 큐레이션도!
private List<Long> imageIds;

@AssertTrue(message = "종료 시간은 시작 시간 이후여야 합니다.")
Expand All @@ -75,7 +74,7 @@ private boolean isEndTimeAfterStartTime() {

@AssertTrue(message = "이미지는 최대 5개까지 등록할 수 있습니다.")
private boolean isImageSizeValid() {
return imageIds.size() <= 5;
return imageIds == null || imageIds.size() <= 5;
}

public Event toEntity(Host host, List<EventImage> images, String thumbnailUrl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ private boolean isEndTimeAfterStartTime() {

@AssertTrue(message = "이미지는 최대 5개까지 등록할 수 있습니다.")
private boolean isImageSizeValid() {
return imageIds.size() <= 5;
return imageIds == null || imageIds.size() <= 5;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package org.ktc2.cokaen.wouldyouin.event.api.dto.relationResonse;

import java.time.LocalDateTime;
import java.util.Optional;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import org.ktc2.cokaen.wouldyouin._common.vo.Location;
import org.ktc2.cokaen.wouldyouin.event.persist.Event;
import org.ktc2.cokaen.wouldyouin.member.persist.BaseMember;

@Getter
@Builder
Expand All @@ -29,7 +31,10 @@ public static CurationEventResponse from(Event event) {
.location(event.getLocation())
.startTime(event.getStartTime())
.thumbnailImageUrl(event.getThumbnailUrl())
.hostProfileImageUrl(event.getHost().getProfileImageUrl())
.hostProfileImageUrl(Optional.of(event)
.map(Event::getHost)
.map(BaseMember::getProfileImageUrl)
.orElse(""))
.hostNickname(event.getHost().getNickname())
.build();
}
Expand Down
24 changes: 11 additions & 13 deletions src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public class Event {
@Enumerated(EnumType.STRING)
private Category category;

// Todo: 이미지를 사용하는 모든 엔티티 thumnail 설정
@Column(name = "thumbnail_url")
private String thumbnailUrl;

Expand All @@ -118,22 +117,21 @@ public class Event {
protected Event(String title, String content, Host host, Area area, Location location,
LocalDateTime startTime, LocalDateTime endTime, Integer price, Integer totalSeat,
Category category, List<EventImage> images, String thumbnailUrl) {
this.title = title;
this.content = content;
this.host = host;
this.area = area;
this.location = location;
this.startTime = startTime;
this.endTime = endTime;
this.price = price;
this.totalSeat = totalSeat;
this.leftSeat = totalSeat;
this.category = category;
Optional.ofNullable(title).ifPresent(this::setTitle);
Optional.ofNullable(content).ifPresent(this::setContent);
Optional.ofNullable(host).ifPresent(this::setHost);
Optional.ofNullable(area).ifPresent(this::setArea);
Optional.ofNullable(location).ifPresent(this::setLocation);
Optional.ofNullable(startTime).ifPresent(this::setStartTime);
Optional.ofNullable(endTime).ifPresent(this::setEndTime);
Optional.ofNullable(price).ifPresent(this::setPrice);
Optional.ofNullable(totalSeat).ifPresent(this::setTotalSeat);
Optional.ofNullable(leftSeat).ifPresent(this::setLeftSeat);
Optional.ofNullable(category).ifPresent(this::setCategory);
Optional.ofNullable(images).ifPresent(this::setImages);
Optional.of(thumbnailUrl).ifPresent(this::setThumbnailUrl);
}

// Todo: oneToMany 연관관계에서 모든 null 처리
public void updateFrom(EventEditRequest eventEditRequest, List<EventImage> images, String thumbnailUrl) {
Optional.ofNullable(eventEditRequest.getTitle()).ifPresent(this::setTitle);
Optional.ofNullable(eventEditRequest.getContent()).ifPresent(this::setContent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static EventHostResponse from(Host host) {
.profileImageUrl(Optional.of(host)
.map(BaseMember::getProfileImage)
.map(Image::getName)
.orElse(null)
.orElse("")
)
.intro(host.getIntro())
.likes(host.getLikes())
Expand Down

0 comments on commit 02d8614

Please sign in to comment.