Skip to content

Commit c17dd41

Browse files
committed
#8 fix: 판매글 목록 조회 시 판매중 글 뒤에 판매완료 글 배치
1 parent 77dc301 commit c17dd41

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

src/main/java/com/kkobugi/puremarket/produce/application/ProduceService.java

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
import org.springframework.stereotype.Service;
1616
import org.springframework.transaction.annotation.Transactional;
1717

18+
import java.util.ArrayList;
1819
import java.util.List;
19-
import java.util.stream.Collectors;
2020

2121
import static com.kkobugi.puremarket.common.constants.Constant.INACTIVE;
2222
import static com.kkobugi.puremarket.common.constants.Constant.Produce.FOR_SALE;
23+
import static com.kkobugi.puremarket.common.constants.Constant.Produce.SOLD_OUT;
2324
import static com.kkobugi.puremarket.common.enums.BaseResponseStatus.*;
2425

2526
@Service
@@ -34,21 +35,37 @@ public class ProduceService {
3435
private String bucketName;
3536

3637
// 판매글 목록 조회
37-
public ProduceListResponse getProduceList() throws BaseException { // TODO: status=SOLD_OUT인 것도 조회
38+
public ProduceListResponse getProduceList() throws BaseException {
3839
try {
3940
// 판매 상태인 글 최신순으로 조회
40-
List<ProduceListResponse.ProduceDto> produceList = produceRepository.findByStatusEqualsOrderByCreatedDateDesc(FOR_SALE).stream()
41+
List<ProduceListResponse.ProduceDto> forSaleList = produceRepository.findByStatusEqualsOrderByCreatedDateDesc(FOR_SALE).stream()
4142
.map(produce -> new ProduceListResponse.ProduceDto(
4243
produce.getProduceIdx(),
4344
produce.getTitle(),
4445
produce.getPrice(),
4546
produce.getProduceImage(),
46-
produce.getStatus()))
47-
.collect(Collectors.toList());
48-
if (produceList.isEmpty()) throw new BaseException(NULL_PRODUCE_LIST);
47+
produce.getStatus())).toList();
48+
49+
// 판매완료 상태인 글 최신순으로 조회
50+
List<ProduceListResponse.ProduceDto> soldOutList = produceRepository.findByStatusEqualsOrderByCreatedDateDesc(SOLD_OUT).stream()
51+
.map(produce -> new ProduceListResponse.ProduceDto(
52+
produce.getProduceIdx(),
53+
produce.getTitle(),
54+
produce.getPrice(),
55+
produce.getProduceImage(),
56+
produce.getStatus())).toList();
57+
58+
// validation
59+
//if (forSaleList.isEmpty() && soldOutList.isEmpty()) throw new BaseException(NULL_PRODUCE_LIST);
60+
61+
//forSaleList.addAll(soldOutList);
62+
List<ProduceListResponse.ProduceDto> produceList = new ArrayList<>();
63+
produceList.addAll(forSaleList);
64+
produceList.addAll(soldOutList);
65+
4966
return new ProduceListResponse(produceList);
50-
} catch (BaseException e) {
51-
throw e;
67+
// } catch (BaseException e) {
68+
// throw e;
5269
} catch (Exception e) {
5370
throw new BaseException(DATABASE_ERROR);
5471
}
@@ -80,9 +97,6 @@ public void postProduce(ProducePostRequest producePostRequest) throws BaseExcept
8097
try {
8198
User writer = userRepository.findByUserIdx(authService.getUserIdxFromToken()).orElseThrow(() -> new BaseException(INVALID_USER_IDX));
8299

83-
// validation
84-
if (producePostRequest.title().length() > 32) throw new BaseException(TITLE_EXCEEDED_MAX_LIMIT);
85-
86100
// upload image
87101
String fullPath = gcsService.uploadImage("produce", producePostRequest.produceImage());
88102
String produceImageUrl = "https://storage.googleapis.com/"+bucketName+"/"+fullPath;

0 commit comments

Comments
 (0)