Skip to content

Commit

Permalink
[Weekly/11] Image/delete (#110)
Browse files Browse the repository at this point in the history
* refactor: ImageService delete

* refactor: 해시태그 컨버터 사용
  • Loading branch information
Daolove0323 authored Nov 11, 2024
1 parent bf3ce84 commit 156ab91
Show file tree
Hide file tree
Showing 31 changed files with 183 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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", "엔티티를 찾을 수 없습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
public class Location {
Double longitude;
Double latitude;
String detailAddress;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class CurationCreateRequest {
@NotNull(message = "지역은 필수입니다.")
private Area area;

private List<String> hashTag;
private List<String> hashTags;

private List<Long> eventIds;

Expand All @@ -49,7 +49,7 @@ public Curation toEntity(Curator curator, List<CurationCard> curationCards, List
.content(this.content)
.curationCards(curationCards)
.area(this.area)
.hashTag(this.hashTag)
.hashTags(this.hashTags)
.events(events)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class CurationEditRequest {
@NotNull(message = "지역은 필수입니다.")
private Area area;

private List<String> hashTag;
private List<String> hashTags;

private List<Long> eventIds;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class Curation {

@Column(name = "hashtag")
@Convert(converter = HashtagConverter.class)
private List<String> hashTag = new ArrayList<>();
private List<String> hashTags = new ArrayList<>();

@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(
Expand All @@ -88,22 +88,22 @@ public class Curation {
private LocalDateTime modifiedDate;

@Builder
public Curation(Curator curator, String title, String content, List<CurationCard> curationCards, Area area, List<String> hashTag,
public Curation(Curator curator, String title, String content, List<CurationCard> curationCards, Area area, List<String> hashTags,
List<Event> 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<CurationCard> curationCards, List<Event> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,6 +49,6 @@ public CurationCard(String subtitle, String content, Curation curation, List<Cur
this.subtitle = subtitle;
this.content = content;
this.curation = curation;
this.curationImages = images;
Optional.ofNullable(images).ifPresent(this::setCurationImages);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.ktc2.cokaen.wouldyouin._common.api.ParamDefaults;
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.auth.Authorize;
import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier;
import org.ktc2.cokaen.wouldyouin.event.api.dto.LocationFilter;
Expand Down Expand Up @@ -39,8 +39,8 @@ public class EventController {

@GetMapping
public ResponseEntity<ApiResponseBody<EventSliceResponse>> 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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,6 +54,7 @@ public class EventCreateRequest {
@NotNull(message = "카테고리는 필수입니다.")
private Category category;

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

@AssertTrue(message = "종료 시간은 시작 시간 이후여야 합니다.")
Expand All @@ -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<EventImage> images) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class UserLocation {
public class LocationRequest {

@NotNull(message = "위도 값은 필수입니다.")
@Min(value = -90, message = "위도는 -90 이상이어야 합니다.")
Expand All @@ -23,4 +23,4 @@ public class UserLocation {
@Min(value = -180, message = "경도는 -180 이상이어야 합니다.")
@Max(value = 180, message = "경도는 180 이하여야 합니다.")
private Double longitude;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Event> events = eventRepository.findAllByFilterOrderByDistance(
location.getStartLatitude(), location.getStartLongitude(), location.getEndLatitude(),
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/org/ktc2/cokaen/wouldyouin/event/persist/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<EventImage> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@


import jakarta.annotation.Nullable;
import java.util.List;
import lombok.Builder;
import lombok.Getter;

@Getter
public class HostEditRequest extends MemberEditRequestBase {

@Nullable private final String intro;
@Nullable private final String hashtag;
@Nullable private final List<String> hashtags;

@Builder
public HostEditRequest(@Nullable String nickname, @Nullable String phoneNumber, @Nullable Long profileImageId,
@Nullable String intro, @Nullable String hashtag) {
@Nullable String intro, @Nullable List<String> hashtags) {
super(nickname, phoneNumber, profileImageId);
this.intro = intro;
this.hashtag = hashtag;
this.hashtags = hashtags;
}
}
Loading

0 comments on commit 156ab91

Please sign in to comment.