Skip to content

Commit

Permalink
feat: 향수 API 수정
Browse files Browse the repository at this point in the history
가격, 용량 정보 제거
카테고리 설명 대신 태그로 대체
thumbnailUrl -> thumbnail
  • Loading branch information
oliviarla committed Nov 27, 2023
1 parent 8e25cac commit f5aecc9
Show file tree
Hide file tree
Showing 24 changed files with 69 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class QCategoryJpaEntity extends EntityPathBase<CategoryJpaEntity> {

public final StringPath name = createString("name");

public final StringPath tags = createString("tags");

public final NumberPath<Long> thumbnailId = createNumber("thumbnailId", Long.class);

//inherited
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ public class QPerfumeJpaEntity extends EntityPathBase<PerfumeJpaEntity> {

public final NumberPath<Long> brandId = createNumber("brandId", Long.class);

public final NumberPath<Long> capacity = createNumber("capacity", Long.class);

public final NumberPath<Long> categoryId = createNumber("categoryId", Long.class);

public final EnumPath<io.perfume.api.perfume.domain.Concentration> concentration = createEnum("concentration", io.perfume.api.perfume.domain.Concentration.class);
Expand All @@ -41,8 +39,6 @@ public class QPerfumeJpaEntity extends EntityPathBase<PerfumeJpaEntity> {

public final StringPath perfumeShopUrl = createString("perfumeShopUrl");

public final NumberPath<Long> price = createNumber("price", Long.class);

public final StringPath story = createString("story");

public final NumberPath<Long> thumbnailId = createNumber("thumbnailId", Long.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
import io.perfume.api.perfume.domain.Concentration;
import java.util.List;

public record CreatePerfumeRequestDto(String name, String story, Concentration concentration,
Long price, Long capacity, Long brandId, Long categoryId, Long thumbnailId, String perfumeShopUrl,
List<Long> topNoteIds, List<Long> middleNoteIds, List<Long> baseNoteIds) {
public record CreatePerfumeRequestDto(String name, String story, Concentration concentration, Long brandId, Long categoryId, Long thumbnailId,
String perfumeShopUrl, List<Long> topNoteIds, List<Long> middleNoteIds, List<Long> baseNoteIds) {

public CreatePerfumeCommand toCommand() {
return new CreatePerfumeCommand(name, story, concentration, price, capacity, brandId,
return new CreatePerfumeCommand(name, story, concentration, brandId,
categoryId, thumbnailId, perfumeShopUrl, topNoteIds, middleNoteIds, baseNoteIds);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.perfume.api.perfume.application.port.in.dto.PerfumeNoteResult;
import java.util.List;

public record NoteResponseDto(Long id, String name, String thumbnailUrl) {
public record NoteResponseDto(Long id, String name, String thumbnail) {
public static List<NoteResponseDto> of(List<PerfumeNoteResult> noteResults) {
return noteResults.stream()
.map(noteResult -> new NoteResponseDto(noteResult.id(), noteResult.name(), noteResult.thumbnail()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,21 @@
import lombok.Builder;

@Builder
public record PerfumeResponseDto(String name, String story, Concentration concentration, Long price, Long capacity,
String perfumeShopUrl, String brandName, String categoryName, String categoryDescription,
String thumbnailUrl, List<NoteResponseDto> topNotes, List<NoteResponseDto> middleNotes,
public record PerfumeResponseDto(String name, String story, Concentration concentration,
String perfumeShopUrl, String brandName, String categoryName, String categoryTags,
String thumbnail, List<NoteResponseDto> topNotes, List<NoteResponseDto> middleNotes,
List<NoteResponseDto> baseNotes) {

public static PerfumeResponseDto of(PerfumeResult perfumeResult) {
return PerfumeResponseDto.builder()
.name(perfumeResult.name())
.story(perfumeResult.story())
.concentration(perfumeResult.concentration())
.capacity(perfumeResult.capacity())
.price(perfumeResult.price())
.perfumeShopUrl(perfumeResult.perfumeShopUrl())
.categoryName(perfumeResult.categoryName())
.categoryDescription(perfumeResult.categoryDescription())
.categoryTags(perfumeResult.categoryTags())
.brandName(perfumeResult.brandName())
.thumbnailUrl(perfumeResult.thumbnailUrl())
.thumbnail(perfumeResult.thumbnail())
.topNotes(NoteResponseDto.of(perfumeResult.notePyramidResult().topNotes()))
.middleNotes(NoteResponseDto.of(perfumeResult.notePyramidResult().middleNotes()))
.baseNotes(NoteResponseDto.of(perfumeResult.notePyramidResult().baseNotes()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import io.perfume.api.perfume.application.port.in.dto.SimplePerfumeResult;

public record SimplePerfumeResponseDto(Long id, String name, String thumbnailUrl, String brandName, String strength, String duration) {
public record SimplePerfumeResponseDto(Long id, String name, String thumbnail, String brandName, String strength, String duration) {
public static SimplePerfumeResponseDto of(SimplePerfumeResult simplePerfumeResult) {
return new SimplePerfumeResponseDto(
simplePerfumeResult.id(),
simplePerfumeResult.name(),
simplePerfumeResult.thumbnailUrl(),
simplePerfumeResult.thumbnail(),
simplePerfumeResult.brandName(),
simplePerfumeResult.concentration().getStrength(),
simplePerfumeResult.concentration().getDuration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ public class PerfumeJpaEntity extends BaseTimeEntity {
@Enumerated(EnumType.STRING)
private Concentration concentration;

private Long price;

private Long capacity;
private String perfumeShopUrl;
@NotNull
private Long brandId;
Expand All @@ -51,16 +48,14 @@ public class PerfumeJpaEntity extends BaseTimeEntity {

@Builder
public PerfumeJpaEntity(
Long id, String name, String story, Concentration concentration, Long price, Long capacity, String perfumeShopUrl,
Long id, String name, String story, Concentration concentration, String perfumeShopUrl,
Long brandId, Long categoryId, Long thumbnailId, LocalDateTime createdAt, LocalDateTime updatedAt,
LocalDateTime deletedAt) {
super(createdAt, updatedAt, deletedAt);
this.id = id;
this.name = name;
this.story = story;
this.concentration = concentration;
this.price = price;
this.capacity = capacity;
this.perfumeShopUrl = perfumeShopUrl;
this.brandId = brandId;
this.categoryId = categoryId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
package io.perfume.api.perfume.adapter.out.persistence.perfume.mapper;

import static io.perfume.api.brand.adapter.out.persistence.QBrandEntity.brandEntity;
import static io.perfume.api.file.adapter.out.persistence.file.QFileJpaEntity.fileJpaEntity;
import static io.perfume.api.note.adapter.out.persistence.note.QNoteJpaEntity.noteJpaEntity;
import static io.perfume.api.perfume.adapter.out.persistence.perfume.QPerfumeJpaEntity.perfumeJpaEntity;
import static io.perfume.api.perfume.adapter.out.persistence.perfumeNote.QPerfumeNoteEntity.perfumeNoteEntity;

import com.querydsl.core.Tuple;
import io.perfume.api.perfume.adapter.out.persistence.perfume.PerfumeJpaEntity;
import io.perfume.api.perfume.adapter.out.persistence.perfumeNote.NoteLevel;
import io.perfume.api.perfume.adapter.out.persistence.perfumeNote.PerfumeNoteEntity;
import io.perfume.api.perfume.application.port.in.dto.SimplePerfumeResult;
import io.perfume.api.perfume.domain.NotePyramid;
import io.perfume.api.perfume.domain.NotePyramidIds;
import io.perfume.api.perfume.domain.Perfume;
import io.perfume.api.perfume.domain.PerfumeNote;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.springframework.stereotype.Component;

Expand All @@ -29,9 +25,7 @@ public Perfume toPerfume(PerfumeJpaEntity perfumeJpaEntity) {
.id(perfumeJpaEntity.getId())
.name(perfumeJpaEntity.getName())
.story(perfumeJpaEntity.getStory())
.price(perfumeJpaEntity.getPrice())
.concentration(perfumeJpaEntity.getConcentration())
.capacity(perfumeJpaEntity.getCapacity())
.perfumeShopUrl(perfumeJpaEntity.getPerfumeShopUrl())
.brandId(perfumeJpaEntity.getBrandId())
.categoryId(perfumeJpaEntity.getCategoryId())
Expand All @@ -47,9 +41,7 @@ public Perfume toPerfume(PerfumeJpaEntity perfumeJpaEntity, List<PerfumeNoteEnti
.id(perfumeJpaEntity.getId())
.name(perfumeJpaEntity.getName())
.story(perfumeJpaEntity.getStory())
.price(perfumeJpaEntity.getPrice())
.concentration(perfumeJpaEntity.getConcentration())
.capacity(perfumeJpaEntity.getCapacity())
.perfumeShopUrl(perfumeJpaEntity.getPerfumeShopUrl())
.brandId(perfumeJpaEntity.getBrandId())
.categoryId(perfumeJpaEntity.getCategoryId())
Expand Down Expand Up @@ -95,7 +87,7 @@ public NotePyramid toNotePyramid(List<Tuple> fetchedTuples) {

fetchedTuples.forEach(
tuple -> {
switch (tuple.get(perfumeNoteEntity.noteLevel)) {
switch (Objects.requireNonNull(tuple.get(perfumeNoteEntity.noteLevel))) {
case TOP:
topPerfumeNotes.add(toPerfumeNote(tuple));
break;
Expand All @@ -122,8 +114,6 @@ public PerfumeJpaEntity toPerfumeJpaEntity(Perfume perfume) {
.name(perfume.getName())
.story(perfume.getStory())
.concentration(perfume.getConcentration())
.price(perfume.getPrice())
.capacity(perfume.getCapacity())
.perfumeShopUrl(perfume.getPerfumeShopUrl())
.brandId(perfume.getBrandId())
.categoryId(perfume.getCategoryId())
Expand All @@ -139,14 +129,14 @@ public List<PerfumeNoteEntity> toPerfumeNoteEntities(Long perfumeId,
toPerfumeNoteEntities(notePyramidIds.getBaseNoteIds(), perfumeId, NoteLevel.BASE)
)
.flatMap(List::stream)
.collect(Collectors.toList());
.toList();
}

private List<PerfumeNoteEntity> toPerfumeNoteEntities(List<Long> noteIds, Long perfumeId,
NoteLevel noteLevel) {
return noteIds.stream()
.map(toPerfumeNoteEntity(perfumeId, noteLevel))
.collect(Collectors.toList());
.toList();
}

private Function<Long, PerfumeNoteEntity> toPerfumeNoteEntity(Long perfumeId,
Expand All @@ -157,20 +147,4 @@ private Function<Long, PerfumeNoteEntity> toPerfumeNoteEntity(Long perfumeId,
.noteLevel(noteLevel)
.build();
}

public List<SimplePerfumeResult> toSimplePerfumeResults(List<Tuple> fetchedTuples) {
return fetchedTuples.stream()
.map(this::toSimplePerfumeResult)
.toList();
}

private SimplePerfumeResult toSimplePerfumeResult(Tuple tuple) {
return SimplePerfumeResult.builder()
.id(tuple.get(perfumeJpaEntity.id))
.name(tuple.get(perfumeJpaEntity.name))
.concentration(tuple.get(perfumeJpaEntity.concentration))
.brandName(tuple.get(brandEntity.name))
.thumbnailUrl(tuple.get(fileJpaEntity.url))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.perfume.api.perfume.domain.Concentration;
import java.util.List;

public record CreatePerfumeCommand(String name, String story, Concentration concentration, Long price, Long capacity, Long brandId,
Long categoryId, Long thumbnailId, String perfumeShopUrl, List<Long> topNoteIds, List<Long> middleNoteIds,
List<Long> baseNoteIds) {
public record CreatePerfumeCommand(String name, String story, Concentration concentration, Long brandId, Long categoryId, Long thumbnailId,
String perfumeShopUrl, List<Long> topNoteIds, List<Long> middleNoteIds, List<Long> baseNoteIds) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

public record PerfumeNoteResult(Long id, String name, String thumbnail) {
public static PerfumeNoteResult from(PerfumeNote perfumeNote) {
return new PerfumeNoteResult(perfumeNote.noteId(), perfumeNote.name(), "perfumeNote.thumbnailUrl()");
return new PerfumeNoteResult(perfumeNote.noteId(), perfumeNote.name(), "perfumeNote.thumbnail()");
}

public static List<PerfumeNoteResult> from(List<PerfumeNote> perfumeNotes) {
return perfumeNotes.stream()
.map(PerfumeNoteResult::from)
.collect(Collectors.toList());
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
import lombok.Builder;

@Builder
public record PerfumeResult(String name, String story, Concentration concentration, Long price, Long capacity, String perfumeShopUrl,
String brandName, String categoryName, String categoryDescription, String thumbnailUrl,
public record PerfumeResult(String name, String story, Concentration concentration, String perfumeShopUrl,
String brandName, String categoryName, String categoryTags, String thumbnail,
NotePyramidResult notePyramidResult) {

public static PerfumeResult from(Perfume perfume, CategoryResult categoryResult, BrandForPerfumeResult brandResult, NotePyramid notePyramid) {
public static PerfumeResult from(Perfume perfume, CategoryResult categoryResult, BrandForPerfumeResult brandResult, String thumbnail,
NotePyramid notePyramid) {
return PerfumeResult.builder()
.name(perfume.getName())
.story(perfume.getStory())
.concentration(perfume.getConcentration())
.price(perfume.getPrice())
.capacity(perfume.getCapacity())
.perfumeShopUrl(perfume.getPerfumeShopUrl())
.brandName(brandResult.name())
.categoryName(categoryResult.name())
.categoryDescription(categoryResult.description())
.categoryTags(categoryResult.tags())
.thumbnail(thumbnail)
.notePyramidResult(NotePyramidResult.from(notePyramid))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
package io.perfume.api.perfume.application.port.in.dto;

import io.perfume.api.brand.application.port.in.dto.BrandForPerfumeResult;
import io.perfume.api.perfume.domain.Concentration;
import io.perfume.api.perfume.domain.Perfume;
import lombok.Builder;

@Builder
public record SimplePerfumeResult(Long id, String name, Concentration concentration, String brandName, String thumbnailUrl) {
public static SimplePerfumeResult from(Perfume perfume, BrandForPerfumeResult brandResult) {
return SimplePerfumeResult.builder()
.id(perfume.getId())
.name(perfume.getName())
.concentration(perfume.getConcentration())
.brandName(brandResult.name())
.thumbnailUrl(null) // TODO: 썸네일 추가
.build();
}
public record SimplePerfumeResult(Long id, String name, Concentration concentration, String brandName, String thumbnail) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public void createPerfume(CreatePerfumeCommand createPerfumeCommand) {
.name(createPerfumeCommand.name())
.story(createPerfumeCommand.story())
.concentration(createPerfumeCommand.concentration())
.price(createPerfumeCommand.price())
.capacity(createPerfumeCommand.capacity())
.brandId(createPerfumeCommand.brandId())
.categoryId(createPerfumeCommand.categoryId())
.thumbnailId(createPerfumeCommand.thumbnailId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import io.perfume.api.brand.application.port.in.dto.BrandForPerfumeResult;
import io.perfume.api.common.page.CustomPage;
import io.perfume.api.common.page.CustomSlice;
import io.perfume.api.file.application.port.in.FindFileUseCase;
import io.perfume.api.file.domain.File;
import io.perfume.api.note.application.port.in.FindCategoryUseCase;
import io.perfume.api.note.application.port.in.dto.CategoryResult;
import io.perfume.api.perfume.application.exception.PerfumeNotFoundException;
Expand All @@ -15,6 +17,7 @@
import io.perfume.api.perfume.domain.NotePyramid;
import io.perfume.api.perfume.domain.Perfume;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
Expand All @@ -26,16 +29,21 @@ public class FindPerfumeService implements FindPerfumeUseCase {
private final PerfumeQueryRepository perfumeQueryRepository;
private final FindCategoryUseCase findCategoryUseCase;
private final FindBrandUseCase findBrandUseCase;
private final FindFileUseCase findFileUseCase;

@Override
public PerfumeResult findPerfumeById(Long id) {
Perfume perfume = perfumeQueryRepository.findPerfumeById(id).orElseThrow(() -> new PerfumeNotFoundException(id));
CategoryResult categoryResult = findCategoryUseCase.findCategoryById(perfume.getCategoryId());
BrandForPerfumeResult brandResult = findBrandUseCase.findBrandForPerfume(perfume.getBrandId());
NotePyramid notePyramid = perfumeQueryRepository.getNotePyramidByPerfume(perfume.getId());
// TODO: file의 thumbnail을 얻어와야 한다.
Optional<File> fileById = findFileUseCase.findFileById(perfume.getThumbnailId());
String thumbnail = "";
if(fileById.isPresent()) {
thumbnail = fileById.get().getUrl();
}

return PerfumeResult.from(perfume, categoryResult, brandResult, notePyramid);
return PerfumeResult.from(perfume, categoryResult, brandResult, thumbnail, notePyramid);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,21 @@ public class Perfume extends BaseTimeDomain {
private String name;
private String story;
private Concentration concentration;
private Long price;
private Long capacity; // ML
private String perfumeShopUrl;
private Long brandId;
private Long categoryId;
private Long thumbnailId;
private NotePyramidIds notePyramidIds;

@Builder
public Perfume(Long id, String name, String story, Concentration concentration, Long price, Long capacity, String perfumeShopUrl, Long brandId,
public Perfume(Long id, String name, String story, Concentration concentration, String perfumeShopUrl, Long brandId,
Long thumbnailId, NotePyramidIds notePyramidIds, Long categoryId, LocalDateTime createdAt, LocalDateTime updatedAt,
LocalDateTime deletedAt) {
super(createdAt, updatedAt, deletedAt);
this.id = id;
this.name = name;
this.story = story;
this.concentration = concentration;
this.price = price;
this.capacity = capacity;
this.perfumeShopUrl = perfumeShopUrl;
this.brandId = brandId;
this.categoryId = categoryId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import io.perfume.api.user.application.port.in.dto.UserProfileResult;

public record UserProfileDto(Long userId, String username, String thumbnailUrl) {
public record UserProfileDto(Long userId, String username, String thumbnail) {
public static UserProfileDto of(UserProfileResult userProfileResult) {
return new UserProfileDto(userProfileResult.userId(), userProfileResult.username(), userProfileResult.thumbnailUrl());
return new UserProfileDto(userProfileResult.userId(), userProfileResult.username(), userProfileResult.thumbnail());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.perfume.api.user.application.port.in.dto;

public record UserProfileResult(Long userId, String username, String thumbnailUrl) {
public record UserProfileResult(Long userId, String username, String thumbnail) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table perfume drop price;
alter table perfume drop capacity;
Loading

0 comments on commit f5aecc9

Please sign in to comment.