Skip to content

Commit

Permalink
chore: 구매 링크 api 수정 #7
Browse files Browse the repository at this point in the history
  • Loading branch information
yoonsseo committed Jan 30, 2024
1 parent 2e3bb36 commit c6b0dc5
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
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 List<PurchaseInfo> purchaseList;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package server.acode.domain.fragrance.dto.response;

import lombok.*;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class PurchaseInfo {
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,89 @@ 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).build();
}

List<PurchaseInfo> purchaseList = new ArrayList<>();
PurchaseInfo purchaseInfo1 = PurchaseInfo.builder().link(fragrance.getLink1()).build();
if (purchaseInfo1.getLink().startsWith("https://www.sivillage")) {
purchaseInfo1.setImage(siVillage);
} else if (purchaseInfo1.getLink().contains(fragrance.getBrand().getEngName().replace(" ", "").toLowerCase())) { // 공홈
purchaseInfo1.setImage(fragrance.getBrand().getRoundImg());
} else if (fragrance.getBrand().getId() == 5L) { // 조말론
Brand brand = brandRepository.findById(5L).orElseThrow(() -> new CustomException(ErrorCode.BRAND_NOT_FOUND));
purchaseInfo1.setImage(brand.getRoundImg());
} else if (purchaseInfo1.getLink().startsWith("https://www.lotteon")) {
purchaseInfo1.setImage(lotteOn);
} else if (purchaseInfo1.getLink().startsWith("https://brand.naver.com/lg_perfumery")) {
purchaseInfo1.setImage(lg);
} else if (purchaseInfo1.getLink().startsWith("https://www.kurly")) {
purchaseInfo1.setImage(kurly);
} else {
throw new CustomException(ErrorCode.IMAGE_NOT_FOUND);
}
purchaseList.add(purchaseInfo1);

if (hasText(fragrance.getLink2())) {
PurchaseInfo purchaseInfo2 = PurchaseInfo.builder().link(fragrance.getLink2()).build();
if (purchaseInfo2.getLink().startsWith("https://www.sivillage")) {
purchaseInfo2.setImage(siVillage);
} else if (purchaseInfo2.getLink().contains(fragrance.getBrand().getEngName().replace(" ", "").toLowerCase())) { // 공홈
purchaseInfo2.setImage(fragrance.getBrand().getRoundImg());
} else if (fragrance.getBrand().getId() == 5L) { // 조말론
Brand brand = brandRepository.findById(5L).orElseThrow(() -> new CustomException(ErrorCode.BRAND_NOT_FOUND));
purchaseInfo2.setImage(brand.getRoundImg());
} else if (purchaseInfo2.getLink().startsWith("https://www.lotteon")) {
purchaseInfo2.setImage(lotteOn);
} else if (purchaseInfo2.getLink().startsWith("https://brand.naver.com/lg_perfumery")) {
purchaseInfo2.setImage(lg);
} else if (purchaseInfo2.getLink().startsWith("https://www.kurly")) {
purchaseInfo2.setImage(kurly);
} else {
throw new CustomException(ErrorCode.IMAGE_NOT_FOUND);
}
purchaseList.add(purchaseInfo2);
} else {
return GetFragrancePurchase.builder()
.isSoldOut(isSoldOut)
.purchaseList(purchaseList)
.build();
}

if (hasText(fragrance.getLink3())) {
PurchaseInfo purchaseInfo3 = PurchaseInfo.builder().link(fragrance.getLink3()).build();
if (purchaseInfo3.getLink().startsWith("https://www.sivillage")) {
purchaseInfo3.setImage(siVillage);
} else if (purchaseInfo3.getLink().contains(fragrance.getBrand().getEngName().replace(" ", "").toLowerCase())) { // 공홈
purchaseInfo3.setImage(fragrance.getBrand().getRoundImg());
} else if (fragrance.getBrand().getId() == 5L) { // 조말론
Brand brand = brandRepository.findById(5L).orElseThrow(() -> new CustomException(ErrorCode.BRAND_NOT_FOUND));
purchaseInfo3.setImage(brand.getRoundImg());
} else if (purchaseInfo3.getLink().startsWith("https://www.lotteon")) {
purchaseInfo3.setImage(lotteOn);
} else if (purchaseInfo3.getLink().startsWith("https://brand.naver.com/lg_perfumery")) {
purchaseInfo3.setImage(lg);
} else if (purchaseInfo3.getLink().startsWith("https://www.kurly")) {
purchaseInfo3.setImage(kurly);
} else {
throw new CustomException(ErrorCode.IMAGE_NOT_FOUND);
}
purchaseList.add(purchaseInfo3);
} else {
return GetFragrancePurchase.builder()
.isSoldOut(isSoldOut)
.purchaseList(purchaseList)
.build();
}

return GetFragrancePurchase.builder()
.isSoldOut(isSoldOut)
.purchaseList(purchaseList)
.build();
}


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 c6b0dc5

Please sign in to comment.