Skip to content
Open
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 @@ -91,7 +91,8 @@ public List<LifestyleFeaturedDeviceDto> findFeaturedDevicesByTagKey(String tagKe
COALESCE(d.imageUrl, img.imageUrl) AS imageUrl,
CONCAT(b.brandName, ' ', d.name) AS displayName,
d.releaseDate AS releaseDate,
COALESCE(MIN(o.price), d.price) AS price
COALESCE(MIN(o.price), d.price) AS price,
d.priceCurrency AS priceCurrency
FROM tags t
JOIN lifestyleFeaturedSets s
ON s.tagId = t.tagId AND s.isActive = 1
Expand All @@ -113,7 +114,7 @@ SELECT deviceId, MIN(sortOrder) AS minSort
) m ON m.deviceId = di1.deviceId AND m.minSort = di1.sortOrder
) img ON img.deviceId = d.deviceId
WHERE t.tagKey = :tagKey
GROUP BY sd.slot, d.deviceId, d.imageUrl, img.imageUrl, b.brandName, d.name, d.releaseDate, d.price
GROUP BY sd.slot, d.deviceId, d.imageUrl, img.imageUrl, b.brandName, d.name, d.releaseDate, d.price, d.priceCurrency
ORDER BY sd.slot ASC
""";

Expand All @@ -127,7 +128,7 @@ SELECT deviceId, MIN(sortOrder) AS minSort
rs.getString("displayName"),
releaseDate,
price,
"KRW"
rs.getString("priceCurrency")
);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,44 @@

import com.devicelife.devicelife_api.common.exception.CustomException;
import com.devicelife.devicelife_api.common.exception.ErrorCode;
import com.devicelife.devicelife_api.common.util.CurrencyConverter;
import com.devicelife.devicelife_api.domain.lifestyle.request.LifestyleFeaturedDeviceDto;
import com.devicelife.devicelife_api.domain.lifestyle.response.LifestyleFeaturedResponse;
import com.devicelife.devicelife_api.repository.lifestyle.LifestyleFeaturedRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class LifestyleFeaturedService {

private final LifestyleFeaturedRepository repo;
private final CurrencyConverter currencyConverter;

public LifestyleFeaturedResponse getFeaturedByTagKey(String tagKey) {
var tag = repo.findTagByKey(tagKey);
if (tag == null) throw new CustomException(ErrorCode.REQ_4002, "존재하지 않는 tagKey");

var devices = repo.findFeaturedDevicesByTagKey(tagKey);
return new LifestyleFeaturedResponse(tag.tagKey(), tag.tagLabel(), tag.tagType(), devices);

// 가격을 한화(KRW)로 환전
var devicesWithKrwPrice = devices.stream()
.map(device -> new LifestyleFeaturedDeviceDto(
device.getSlot(),
device.getDeviceId(),
device.getImageUrl(),
device.getDisplayName(),
device.getReleaseDate(),
currencyConverter.convertToKRW(device.getPrice(), device.getCurrency()),
"KRW"
))
.collect(Collectors.toList());

return new LifestyleFeaturedResponse(tag.tagKey(), tag.tagLabel(), tag.tagType(), devicesWithKrwPrice);
}

@Transactional
Expand Down