Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/fashion recommend #86

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public FasCloResponseDTO.FasCloJoinDTO joinFasClo(FasCloRequestDTO.JoinRequestDT
@Override
@Transactional
public FasCloResponseDTO.CreateDTO createFasClo(FasCloRequestDTO.CrateRequestDTO request, List<MultipartFile> tops, List<MultipartFile> bottoms, List<MultipartFile> outers) throws IOException {

log.info("실행2");
List<FasCloResponseDTO.FasTagItemDTO> topFasItems = toFasCloItems(tops);
List<FasCloResponseDTO.FasTagItemDTO> bottomFasItems = toFasCloItems(bottoms);
List<FasCloResponseDTO.FasTagItemDTO> outerFasItems = toFasCloItems(outers);
Expand All @@ -79,7 +79,7 @@ public FasCloResponseDTO.CreateDTO createFasClo(FasCloRequestDTO.CrateRequestDTO
Collections.shuffle(results);
results = results.subList(0, 18);
}

log.info("끝");
return FasCloConverter.toCreateDTO(results);
}
public List<FasCloResponseDTO.CreateItemDTO> MatchingFashion(List<FasCloResponseDTO.FasCloItems> fasCloItems) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ public class FasCloQueryServiceImpl implements FasCloQueryService {
@Transactional
public FasCloResponseDTO.ViewListResultDTO viewList(Long userId){
Optional<User> userOptional= userRepository.findById(userId);
log.info(String.valueOf(userId));
User user=userOptional.get();
List<FashionCloset> fashionClosets= fasCloRepository.findAllByUser(user, Sort.by(Sort.Direction.DESC, "createdAt"));

List<FasCloResponseDTO.ViewListItemDTO> items= fashionClosets.stream().map(
fashionCloset -> {
log.info("옷장번호 "+String.valueOf(fashionCloset.getId()));
Optional<FashionClosetFashionStyle>fashionClosetFashionStyleOptional= fasCloFasStyRepository.findFirstByFashionCloset(fashionCloset);
FashionClosetFashionStyle fashionClosetFashionStyle= fashionClosetFashionStyleOptional.get();

FashionClosetFashionStyle fashionClosetFashionStyle = fashionClosetFashionStyleOptional.get();

return FasCloConverter.toViewListItem(fashionClosetFashionStyle);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.nio.file.Files;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -223,16 +224,30 @@ public SeaCloResponseDTO.SeaCloListDTO getSimilarProductsFile(

List<ProductSearchResults.Result> similarProducts =
response.getResponses(0).getProductSearchResults().getResultsList();
List<SeaCloResponseDTO.SeaCloItemDTO> items=similarProducts.stream()
.map(product->{
String productIdPath = product.getProduct().getName();
String[] parts = productIdPath.split("/");
String itemId = parts[parts.length - 1];
Optional<ItemList> itemListOptional= itemListReposiotroy.findByTitle(itemId);
ItemList itemList=itemListOptional.get();

return SeaCloConverter.toSeaCloItemDTO(itemList.getPrice(),itemId,itemList.getImage(),itemList.getUrl());
}).collect(Collectors.toList());
List<SeaCloResponseDTO.SeaCloItemDTO> items = similarProducts.stream()
.map(product -> {
try {
log.info("1");
String productIdPath = product.getProduct().getName();
String[] parts = productIdPath.split("/");
String itemId = parts[parts.length - 1];
Optional<ItemList> itemListOptional = itemListReposiotroy.findByTitle(itemId);

// 예외 처리: itemListOptional이 비어있는 경우 처리
if (!itemListOptional.isPresent()) {
return null;
}

ItemList itemList = itemListOptional.get();
return SeaCloConverter.toSeaCloItemDTO(itemList.getPrice(), itemId, itemList.getImage(), itemList.getUrl());
} catch (Exception e) {
// 예외 처리: 로그 출력
log.error("Error processing product: " + product.getProduct().getName(), e);
return null; // null을 반환하여 나중에 필터링
}
})
.filter(Objects::nonNull) // null이 아닌 항목만 필터링
.collect(Collectors.toList());
// log.info("Similar Products: ");
// for (ProductSearchResults.Result product : similarProducts) {
// log.info(String.format("\nProduct name: %s", product.getProduct().getName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class FasCloRestController {
private final TokenProvider tokenProvider;
@PostMapping("")
ApiResponse<FasCloResponseDTO.CreateDTO> create(@RequestPart(value ="request", required = true) @Valid FasCloRequestDTO.CrateRequestDTO request, @RequestPart(value="top",required = true) @Valid List<MultipartFile> tops,@RequestPart(value="bottom",required = true) @Valid List<MultipartFile> bottoms,@RequestPart(value="outer",required = false) @Valid List<MultipartFile> outers) throws IOException {

log.info("실행");
return ApiResponse.onSuccess(fasCloCommandService.createFasClo(request,tops,bottoms,outers));
}
@PostMapping("/closet")
Expand Down
Loading