Skip to content

Commit

Permalink
refactor: 코드 리뷰 사항 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
SonMinGyu committed Aug 17, 2023
1 parent d0c9a62 commit c6db02d
Show file tree
Hide file tree
Showing 17 changed files with 125 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
@UtilityClass
public class CustomListUtils {

private static final int minimumImageSize = 1;

public static <T, R> List<R> mapTo(final List<T> list, final Function<T, R> mappingFunction) {
if (isEmpty(list)) {
return List.of();
Expand All @@ -35,8 +37,8 @@ public static <T> boolean isEmpty(final List<T> list) {
}

public static <T> String joiningToString(final List<T> list, final String delimiter) {
if (list.size() < 1) {
return null;
if (list.size() < minimumImageSize) {
return "";
}
return list.stream()
.map(Object::toString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ public interface ImageRepositoryCustom {

Map<Long, Image> findByIdInToMap(List<Long> imageIds);

boolean isExistIdIn(final List<Long> imageIds);

boolean isNotExistIdIn(final List<Long> imageIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Map<Long, Image> findByIdInToMap(final List<Long> imageIds) {
}

@Override
public boolean isExistIdIn(final List<Long> imageIds) {
public boolean isNotExistIdIn(final List<Long> imageIds) {
List<Long> existImageIds = queryFactory
.selectFrom(image)
.where(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ public Member(final String nickname, final String email, final Role role, String
this.loginHistory = LoginHistory.init();
}

public static Member defaultOf() {
return Member.builder()
.nickname("알 수 없음")
.email("[email protected]")
.build();
}

public String getEmail() {
return email.getValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private List<ReviewTag> getReviewTagsRelatedToPlace(final List<Review> reviews)
}

private void checkExistImage(final List<Long> imageIds) {
if (imageRepository.isExistIdIn(imageIds)) {
if (imageRepository.isNotExistIdIn(imageIds)) {
throw new NotFoundImageException(imageIds);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.prography.kagongsillok.common.utils.CustomListUtils;
import org.prography.kagongsillok.image.application.dto.ImageDto;
import org.prography.kagongsillok.image.domain.Image;
import org.prography.kagongsillok.place.domain.BusinessHour;
import org.prography.kagongsillok.place.domain.Link;
import org.prography.kagongsillok.place.domain.Place;
import org.prography.kagongsillok.review.application.dto.ReviewTagDto;
import org.prography.kagongsillok.review.domain.ReviewTag;

@Getter
Expand All @@ -22,11 +24,11 @@ public class PlaceDto {
private String address;
private Double latitude;
private Double longitude;
private List<Image> images;
private List<ImageDto> images;
private String phone;
private List<LinkDto> links;
private List<BusinessHourDto> businessHours;
private List<ReviewTag> reviewTags;
private List<ReviewTagDto> reviewTags;

@Builder
public PlaceDto(
Expand All @@ -35,11 +37,11 @@ public PlaceDto(
final String address,
final Double latitude,
final Double longitude,
final List<Image> images,
final List<ImageDto> images,
final String phone,
final List<LinkDto> links,
final List<BusinessHourDto> businessHours,
final List<ReviewTag> reviewTags
final List<ReviewTagDto> reviewTags
) {
this.id = id;
this.name = name;
Expand Down Expand Up @@ -73,7 +75,7 @@ public static PlaceDto of(final Place place, final List<Image> images) {
.address(place.getAddress())
.latitude(place.getLatitude())
.longitude(place.getLongitude())
.images(images)
.images(CustomListUtils.mapTo(images, ImageDto::from))
.phone(place.getPhone())
.links(CustomListUtils.mapTo(place.getLinks().getValues(), LinkDto::from))
.businessHours(CustomListUtils.mapTo(place.getBusinessHours().getValues(), BusinessHourDto::from))
Expand All @@ -87,11 +89,11 @@ public static PlaceDto of(final Place place,final List<Image> images, final List
.address(place.getAddress())
.latitude(place.getLatitude())
.longitude(place.getLongitude())
.images(images)
.images(CustomListUtils.mapTo(images, ImageDto::from))
.phone(place.getPhone())
.links(CustomListUtils.mapTo(place.getLinks().getValues(), LinkDto::from))
.businessHours(CustomListUtils.mapTo(place.getBusinessHours().getValues(), BusinessHourDto::from))
.reviewTags(reviewTags)
.reviewTags(CustomListUtils.mapTo(reviewTags, ReviewTagDto::from))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.prography.kagongsillok.place.infrastructure;

import java.util.List;
import java.util.Map;
import org.prography.kagongsillok.place.domain.Location;
import org.prography.kagongsillok.place.domain.Place;

Expand All @@ -15,4 +16,6 @@ List<Place> findByLocationAround(
List<Place> findByNameContains(final String name);

List<Place> findByIdIn(final List<Long> placeIds);

Map<Long, Place> findByIdInToMap(final List<Long> placeIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.prography.kagongsillok.place.domain.Location;
import org.prography.kagongsillok.place.domain.Place;
Expand Down Expand Up @@ -66,6 +69,18 @@ public List<Place> findByIdIn(final List<Long> placeIds) {
.fetch();
}

@Override
public Map<Long, Place> findByIdInToMap(final List<Long> placeIds) {
return queryFactory
.selectFrom(place)
.where(
idIn(placeIds),
isNotDeleted()
)
.stream()
.collect(Collectors.toMap(Place::getId, Function.identity()));
}

private BooleanExpression nameContains(final String name) {
if (Objects.isNull(name)) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.prography.kagongsillok.common.utils.CustomListUtils;
import org.prography.kagongsillok.image.application.dto.ImageDto;
import org.prography.kagongsillok.image.domain.Image;
import org.prography.kagongsillok.place.application.dto.PlaceDto;
import org.prography.kagongsillok.place.application.dto.PlaceDto.BusinessHourDto;
import org.prography.kagongsillok.place.application.dto.PlaceDto.LinkDto;
import org.prography.kagongsillok.review.application.dto.ReviewTagDto;
import org.prography.kagongsillok.review.domain.ReviewTag;

@Getter
Expand All @@ -23,11 +25,11 @@ public class PlaceResponse {
private String address;
private Double latitude;
private Double longitude;
private List<Image> images;
private List<ImageDto> images;
private String phone;
private List<LinkResponse> links;
private List<BusinessHourResponse> businessHours;
private List<ReviewTag> reviewTags;
private List<ReviewTagDto> reviewTags;

@Builder
public PlaceResponse(
Expand All @@ -36,11 +38,11 @@ public PlaceResponse(
final String address,
final Double latitude,
final Double longitude,
final List<Image> images,
final List<ImageDto> images,
final String phone,
final List<LinkResponse> links,
final List<BusinessHourResponse> businessHours,
final List<ReviewTag> reviewTags
final List<ReviewTagDto> reviewTags
) {
this.id = id;
this.name = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.prography.kagongsillok.common.utils.CustomListUtils;
import org.prography.kagongsillok.common.utils.CustomStringUtils;
import org.prography.kagongsillok.image.application.exception.NotFoundImageException;
import org.prography.kagongsillok.image.domain.Image;
import org.prography.kagongsillok.image.domain.ImageRepository;
Expand All @@ -17,7 +16,6 @@
import org.prography.kagongsillok.record.application.exception.NotFoundStudyRecordException;
import org.prography.kagongsillok.record.domain.StudyRecord;
import org.prography.kagongsillok.record.domain.StudyRecordRepository;
import org.prography.kagongsillok.review.domain.Review;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -78,7 +76,7 @@ public void deleteStudyRecord(final Long id) {
}

private void checkExistImage(final List<Long> imageIds) {
if (imageRepository.isExistIdIn(imageIds)) {
if (imageRepository.isNotExistIdIn(imageIds)) {
throw new NotFoundImageException(imageIds);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.prography.kagongsillok.common.utils.CustomListUtils;
import org.prography.kagongsillok.image.application.dto.ImageDto;
import org.prography.kagongsillok.image.domain.Image;
import org.prography.kagongsillok.record.domain.StudyRecord;

Expand All @@ -22,7 +24,7 @@ public class StudyRecordDto {
private LocalDate studyDate;
private String description;
private int duration;
private List<Image> images;
private List<ImageDto> images;
private ZonedDateTime writtenAt;

@Builder
Expand All @@ -32,7 +34,7 @@ public StudyRecordDto(
final LocalDate studyDate,
final String description,
final int duration,
final List<Image> images,
final List<ImageDto> images,
final ZonedDateTime writtenAt
) {
this.id = id;
Expand All @@ -51,7 +53,7 @@ public static StudyRecordDto of(final StudyRecord studyRecord, final List<Image>
.studyDate(studyRecord.getStudyDate())
.duration(studyRecord.getDuration())
.description(studyRecord.getDescription())
.images(images)
.images(CustomListUtils.mapTo(images, ImageDto::from))
.writtenAt(studyRecord.getWrittenAt())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.prography.kagongsillok.image.application.dto.ImageDto;
import org.prography.kagongsillok.image.domain.Image;
import org.prography.kagongsillok.record.application.dto.StudyRecordDto;

Expand All @@ -19,7 +20,7 @@ public class StudyRecordResponse {
private LocalDate studyDate;
private String description;
private int duration;
private List<Image> images;
private List<ImageDto> images;
private ZonedDateTime writtenAt;

@Builder
Expand All @@ -29,7 +30,7 @@ public StudyRecordResponse(
final LocalDate studyDate,
final String description,
final int duration,
final List<Image> images,
final List<ImageDto> images,
final ZonedDateTime writtenAt
) {
this.id = id;
Expand Down
Loading

0 comments on commit c6db02d

Please sign in to comment.