Skip to content

Commit

Permalink
#201 fix:관리자 경험 선물 등록, 수정 api 변경 / thumnail컬럼 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
leeseunghakhello committed Jan 6, 2024
1 parent ca65d57 commit 8030426
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,26 +77,14 @@ public void registerExperienceGift(UserPrincipal userPrincipal, ShopOwnerExperie
.orElseGet(() -> subtitleRepository.save(new Subtitle(shopOwnerExperienceReq.getSubtitle())));

ExperienceCategory experienceCategory = null;
SituationCategory situationCategory = null;

// 경험 카테고리가 주어졌는지 확인하고 처리
if (StringUtils.hasText(shopOwnerExperienceReq.getExpCategory())) {
experienceCategory = experienceCategoryRepository.findByExpCategory(shopOwnerExperienceReq.getExpCategory())
.orElseThrow(ExpCategoryAlreadyExist::new);
}

// 상황 카테고리가 주어졌는지 확인하고 처리
if (StringUtils.hasText(shopOwnerExperienceReq.getSttCategory())) {
situationCategory = situationCategoryRepository.findBySttCategory(shopOwnerExperienceReq.getSttCategory())
.orElseThrow(SttCategoryAlreadyExist::new);
}

// 두 카테고리가 동시에 주어진 경우 오류 처리
if (experienceCategory != null && situationCategory != null) {
throw new ChooseOnlyOneCategory();
}

ExperienceGift experienceGift = experienceGiftRepository.save(ExperienceGift.toDto(shopOwnerExperienceReq, subtitle, experienceCategory, situationCategory, shopOwner));
ExperienceGift experienceGift = experienceGiftRepository.save(ExperienceGift.toDto(shopOwnerExperienceReq, subtitle, experienceCategory, shopOwner));

List<Explanation> explanations = shopOwnerExperienceReq.getExplanation().stream()
.map(explanationReq -> Explanation.toDto(explanationReq, experienceGift))
Expand Down Expand Up @@ -155,21 +143,14 @@ public void modifyExperienceGift(Long experienceGiftId, UserPrincipal userPrinci


ExperienceCategory experienceCategory = null;
SituationCategory situationCategory = null;

// 경험 카테고리가 주어졌는지 확인하고 처리
if (StringUtils.hasText(shopOwnerExperienceReq.getExpCategory())) {
experienceCategory = experienceCategoryRepository.findByExpCategory(shopOwnerExperienceReq.getExpCategory())
.orElseThrow(ExpCategoryAlreadyExist::new);
}

// 상황 카테고리가 주어졌는지 확인하고 처리
if (StringUtils.hasText(shopOwnerExperienceReq.getSttCategory())) {
situationCategory = situationCategoryRepository.findBySttCategory(shopOwnerExperienceReq.getSttCategory())
.orElseThrow(SttCategoryAlreadyExist::new);
}

experienceGift.update(shopOwnerExperienceReq, subtitle, experienceCategory, situationCategory, shopOwner);
experienceGift.update(shopOwnerExperienceReq, subtitle, experienceCategory, shopOwner);

if (shopOwnerExperienceReq.getExplanation() != null && !shopOwnerExperienceReq.getExplanation().isEmpty()) {
explanationRepository.deleteByExperienceGift(experienceGift);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ public class ExperienceGift extends BaseEntity {
@JoinColumn(name = "subtitle_id")
private Subtitle subtitle;

private String thumbnail;

private Long price;

@ManyToOne(fetch = FetchType.LAZY)
Expand All @@ -52,36 +50,34 @@ public class ExperienceGift extends BaseEntity {
@OneToMany(mappedBy = "experienceGift")
private List<ExperienceGiftImage> imgList = new ArrayList<>();

public static ExperienceGift toDto(ShopOwnerExperienceReq req, Subtitle subtitle, ExperienceCategory experienceCategory, SituationCategory situationCategory, ShopOwner shopOwner) {
public static ExperienceGift toDto(ShopOwnerExperienceReq req, Subtitle subtitle, ExperienceCategory experienceCategory, ShopOwner shopOwner) {
return ExperienceGift.builder()
.title(req.getTitle())
.subtitle(subtitle)
.price(req.getPrice())
.experienceCategory(experienceCategory)
.situationCategory(situationCategory)
.description(req.getDescription())
.shopOwner(shopOwner)
.location(req.getLocation())
.note(req.getNote())
.build();
}

public void update(ShopOwnerExperienceReq shopOwnerExperienceReq, Subtitle subtitle, ExperienceCategory experienceCategory, SituationCategory situationCategory, ShopOwner shopOwner) {
public void update(ShopOwnerExperienceReq shopOwnerExperienceReq, Subtitle subtitle, ExperienceCategory experienceCategory, ShopOwner shopOwner) {
this.title = shopOwnerExperienceReq.getTitle();
this.description = shopOwnerExperienceReq.getDescription();
this.location = shopOwnerExperienceReq.getLocation();
this.price = shopOwnerExperienceReq.getPrice();
this.subtitle = subtitle;
this.experienceCategory = experienceCategory;
this.situationCategory = situationCategory;
this.shopOwner = shopOwner;
this.note=shopOwnerExperienceReq.getNote();
}

@Builder
public ExperienceGift(String title, Subtitle subtitle, String thumbnail, Long price, ExperienceCategory experienceCategory, SituationCategory situationCategory, String description, String giftImgKey, ShopOwner shopOwner, String location, String note, List<ExperienceGiftImage> imgList) {
public ExperienceGift(String title, Subtitle subtitle, Long price, ExperienceCategory experienceCategory, SituationCategory situationCategory, String description, String giftImgKey, ShopOwner shopOwner, String location, String note, List<ExperienceGiftImage> imgList) {
this.title = title;
this.subtitle = subtitle;
this.thumbnail = thumbnail;
this.price = price;
this.experienceCategory = experienceCategory;
this.situationCategory = situationCategory;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ public class ShopOwnerExperienceReq {
@Schema(type = "String", description = "경험 카테고리")
private String expCategory;

@Schema(type = "String", description = "상황 카테고리")
private String sttCategory;

@Schema(type = "String", description = "상품명", maxLength = 100)
@NotBlank(message = "상품명은 필수 입력 값입니다.")
private String title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
public class ExperienceRes {

private Long ExperienceGiftId;
private String thumbnail;
private String subtitle;
private String title;
private Long price;
Expand All @@ -24,7 +23,6 @@ public class ExperienceRes {
public static ExperienceRes toDto(ExperienceGift experienceGift, List<String> experienceGiftImgs){
return ExperienceRes.builder()
.ExperienceGiftId(experienceGift.getId())
.thumbnail(experienceGift.getThumbnail())
.subtitle(experienceGift.getSubtitle().getTitle())
.title(experienceGift.getTitle())
.price(experienceGift.getPrice())
Expand Down

0 comments on commit 8030426

Please sign in to comment.