Skip to content

Commit

Permalink
Merge pull request #33 from team-acode/feat/fragrance
Browse files Browse the repository at this point in the history
chore: 구매 링크 api 수정
  • Loading branch information
yoonsseo authored Jan 31, 2024
2 parents 2e3bb36 + c23c1ff commit bd8c068
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
package server.acode.domain.fragrance.dto.response;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;
import server.acode.domain.fragrance.entity.Fragrance;

import java.util.List;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Builder
public class GetFragrancePurchase {
private String link1; // 구매 링크 url
private String link2;
private String link3;

public GetFragrancePurchase(String link1, String link2, String link3) {
this.link1 = link1;
this.link2 = link2;
this.link3 = link3;
}

public static GetFragrancePurchase from(Fragrance fragrance) {
return new GetFragrancePurchase(
fragrance.getLink1(), fragrance.getLink2(), fragrance.getLink3()
);
}
private boolean isSoldOut;
private String fragranceName;
private String brandName;
private List<PurchaseInfo> purchaseList;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package server.acode.domain.fragrance.dto.response;

import lombok.*;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class PurchaseInfo {
private String title;
private String link;
private String image;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package server.acode.domain.fragrance.service;

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
Expand All @@ -10,8 +11,10 @@
import server.acode.domain.family.entity.Family;
import server.acode.domain.family.repository.FragranceFamilyRepository;
import server.acode.domain.fragrance.dto.response.*;
import server.acode.domain.fragrance.entity.Brand;
import server.acode.domain.fragrance.entity.Capacity;
import server.acode.domain.fragrance.entity.Fragrance;
import server.acode.domain.fragrance.repository.BrandRepository;
import server.acode.domain.fragrance.repository.CapacityRepository;
import server.acode.domain.fragrance.repository.FragranceRepository;
import server.acode.domain.ingredient.entity.Ingredient;
Expand All @@ -36,6 +39,8 @@
import java.util.*;
import java.util.stream.Collectors;

import static org.springframework.util.StringUtils.*;

@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
Expand All @@ -59,6 +64,20 @@ public class FragranceService {

private final UserRepository userRepository;

private final BrandRepository brandRepository;

@Value("${store.image.siVillage}")
String siVillage;

@Value("${store.image.lotteOn}")
String lotteOn;

@Value("${store.image.kurly}")
String kurly;

@Value("${store.image.lg}")
String lg;


@Transactional
public GetFragranceResponse getFragranceDetail(Long fragranceId, CustomUserDetails userDetails) {
Expand Down Expand Up @@ -369,7 +388,81 @@ private SimilarFragranceOrCond getSimilarFragranceOrCond(Long fragranceId, List<
public GetFragrancePurchase getFragrancePurchase(Long fragranceId) {
Fragrance fragrance = fragranceRepository.findById(fragranceId)
.orElseThrow(() -> new CustomException(ErrorCode.FRAGRANCE_NOT_FOUND));
return GetFragrancePurchase.from(fragrance);

boolean isSoldOut = false;
if (!hasText(fragrance.getLink1())) {
isSoldOut = true;
return GetFragrancePurchase.builder()
.isSoldOut(isSoldOut)
.fragranceName(fragrance.getName())
.brandName(fragrance.getBrand().getKorName())
.build();
}

List<PurchaseInfo> purchaseList = new ArrayList<>();
PurchaseInfo purchaseInfo1 = setPurchaseInfo(fragrance, fragrance.getLink1());
purchaseList.add(purchaseInfo1);

if (hasText(fragrance.getLink2())) {
PurchaseInfo purchaseInfo2 = setPurchaseInfo(fragrance, fragrance.getLink2());
purchaseList.add(purchaseInfo2);
} else {
return GetFragrancePurchase.builder()
.isSoldOut(isSoldOut)
.fragranceName(fragrance.getName())
.brandName(fragrance.getBrand().getKorName())
.purchaseList(purchaseList)
.build();
}

if (hasText(fragrance.getLink3())) {
PurchaseInfo purchaseInfo3 = setPurchaseInfo(fragrance, fragrance.getLink3());
purchaseList.add(purchaseInfo3);
} else {
return GetFragrancePurchase.builder()
.isSoldOut(isSoldOut)
.fragranceName(fragrance.getName())
.brandName(fragrance.getBrand().getKorName())
.purchaseList(purchaseList)
.build();
}

return GetFragrancePurchase.builder()
.isSoldOut(isSoldOut)
.fragranceName(fragrance.getName())
.brandName(fragrance.getBrand().getKorName())
.purchaseList(purchaseList)
.build();
}

private PurchaseInfo setPurchaseInfo(Fragrance fragrance, String link) {
PurchaseInfo purchaseInfo = PurchaseInfo.builder().link(link).build();

if (purchaseInfo.getLink().startsWith("https://www.sivillage")) {
purchaseInfo.setImage(siVillage);
purchaseInfo.setTitle("S.I.VILLAGE 신세계인터내셔날 공식몰");
} else if (purchaseInfo.getLink().contains(fragrance.getBrand().getEngName().replace(" ", "").toLowerCase())) { // 공홈
purchaseInfo.setImage(fragrance.getBrand().getRoundImg());
// StringBuilder sb = new StringBuilder(fragrance.getBrand().getEngName()).append(" ").append(fragrance.getBrand().getKorName());
purchaseInfo.setTitle(fragrance.getBrand().getEngName() + " " + fragrance.getBrand().getKorName());
} else if (fragrance.getBrand().getId() == 5L) { // 조말론
Brand brand = brandRepository.findById(5L).orElseThrow(() -> new CustomException(ErrorCode.BRAND_NOT_FOUND));
purchaseInfo.setImage(brand.getRoundImg());
purchaseInfo.setTitle("JO MALONE LONDON 조말론 런던");
} else if (purchaseInfo.getLink().startsWith("https://www.lotteon")) {
purchaseInfo.setImage(lotteOn);
purchaseInfo.setTitle("LOTTE ON 롯데온");
} else if (purchaseInfo.getLink().startsWith("https://brand.naver.com/lg_perfumery")) {
purchaseInfo.setImage(lg);
purchaseInfo.setTitle("LG생활건강");
} else if (purchaseInfo.getLink().startsWith("https://www.kurly")) {
purchaseInfo.setImage(kurly);
purchaseInfo.setTitle("KURLY 컬리");
} else {
throw new CustomException(ErrorCode.IMAGE_NOT_FOUND);
}

return purchaseInfo;
}


Expand Down
1 change: 1 addition & 0 deletions src/main/java/server/acode/global/common/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public enum ErrorCode {
REVIEW_LONGEVITY_NOT_FOUND(HttpStatus.NOT_FOUND, "관리자에게 문의 바랍니다."),
REVIEW_INTENSITY_NOT_FOUND(HttpStatus.NOT_FOUND, "관리자에게 문의 바랍니다."),
REVIEW_STYLE_NOT_FOUND(HttpStatus.NOT_FOUND, "관리자에게 문의 바랍니다."),
IMAGE_NOT_FOUND(HttpStatus.NOT_FOUND, "관리자에게 문의 바랍니다"),


/* 409 CONFLICT */
Expand Down
9 changes: 8 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,11 @@ cloud:
auto: false

presignedUrlDuration: ${PRESIGNED_URL_DURATION}
kakaoAdminKey: ${KAKAO_ADMIN_KEY}
kakaoAdminKey: ${KAKAO_ADMIN_KEY}

store:
image:
siVillage: ${STORE_IMAGE_SIVILLAGE}
lotteOn: ${STORE_IMAGE_LOTTEON}
kurly: ${STORE_IMAGE_KURLY}
lg: ${STORE_IMAGE_LG}

0 comments on commit bd8c068

Please sign in to comment.