15
15
import org .springframework .stereotype .Service ;
16
16
import org .springframework .transaction .annotation .Transactional ;
17
17
18
+ import java .util .ArrayList ;
18
19
import java .util .List ;
19
- import java .util .stream .Collectors ;
20
20
21
21
import static com .kkobugi .puremarket .common .constants .Constant .INACTIVE ;
22
22
import static com .kkobugi .puremarket .common .constants .Constant .Produce .FOR_SALE ;
23
+ import static com .kkobugi .puremarket .common .constants .Constant .Produce .SOLD_OUT ;
23
24
import static com .kkobugi .puremarket .common .enums .BaseResponseStatus .*;
24
25
25
26
@ Service
@@ -34,21 +35,37 @@ public class ProduceService {
34
35
private String bucketName ;
35
36
36
37
// 판매글 목록 조회
37
- public ProduceListResponse getProduceList () throws BaseException { // TODO: status=SOLD_OUT인 것도 조회
38
+ public ProduceListResponse getProduceList () throws BaseException {
38
39
try {
39
40
// 판매 상태인 글 최신순으로 조회
40
- List <ProduceListResponse .ProduceDto > produceList = produceRepository .findByStatusEqualsOrderByCreatedDateDesc (FOR_SALE ).stream ()
41
+ List <ProduceListResponse .ProduceDto > forSaleList = produceRepository .findByStatusEqualsOrderByCreatedDateDesc (FOR_SALE ).stream ()
41
42
.map (produce -> new ProduceListResponse .ProduceDto (
42
43
produce .getProduceIdx (),
43
44
produce .getTitle (),
44
45
produce .getPrice (),
45
46
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
+
49
66
return new ProduceListResponse (produceList );
50
- } catch (BaseException e ) {
51
- throw e ;
67
+ // } catch (BaseException e) {
68
+ // throw e;
52
69
} catch (Exception e ) {
53
70
throw new BaseException (DATABASE_ERROR );
54
71
}
@@ -80,9 +97,6 @@ public void postProduce(ProducePostRequest producePostRequest) throws BaseExcept
80
97
try {
81
98
User writer = userRepository .findByUserIdx (authService .getUserIdxFromToken ()).orElseThrow (() -> new BaseException (INVALID_USER_IDX ));
82
99
83
- // validation
84
- if (producePostRequest .title ().length () > 32 ) throw new BaseException (TITLE_EXCEEDED_MAX_LIMIT );
85
-
86
100
// upload image
87
101
String fullPath = gcsService .uploadImage ("produce" , producePostRequest .produceImage ());
88
102
String produceImageUrl = "https://storage.googleapis.com/" +bucketName +"/" +fullPath ;
0 commit comments