1
1
package com .jangburich .domain .store .controller ;
2
2
3
- import com .jangburich .domain .store .dto .response .StoreSearchDetailsResponse ;
3
+ import java .net .URLEncoder ;
4
+ import java .nio .charset .StandardCharsets ;
5
+ import java .time .LocalDate ;
6
+ import java .time .format .DateTimeFormatter ;
4
7
import java .util .List ;
5
8
6
9
import org .springframework .data .domain .Page ;
7
10
import org .springframework .data .domain .Pageable ;
11
+ import org .springframework .http .HttpHeaders ;
8
12
import org .springframework .http .MediaType ;
13
+ import org .springframework .http .ResponseEntity ;
9
14
import org .springframework .security .core .Authentication ;
10
15
import org .springframework .web .bind .annotation .GetMapping ;
11
16
import org .springframework .web .bind .annotation .PatchMapping ;
27
32
import com .jangburich .domain .store .dto .response .OrdersTodayResponse ;
28
33
import com .jangburich .domain .store .dto .response .PaymentGroupDetailResponse ;
29
34
import com .jangburich .domain .store .dto .response .SearchStoresResponse ;
35
+ import com .jangburich .domain .store .dto .response .StoreSearchDetailsResponse ;
30
36
import com .jangburich .domain .store .dto .response .StoreTeamResponse ;
31
37
import com .jangburich .domain .store .service .StoreService ;
32
38
import com .jangburich .global .payload .Message ;
44
50
@ RequestMapping ("/store" )
45
51
public class StoreController {
46
52
47
- private final StoreService storeService ;
48
-
49
- @ Operation (summary = "카테고리 별 가게 목록 조회" , description = "카테고리 별로 가게 목록을 조회합니다." )
50
- @ PostMapping ("/category" )
51
- public ResponseCustom <Page <SearchStoresResponse >> searchByCategory (
52
- Authentication authentication ,
53
- @ RequestParam (required = false , defaultValue = "3" ) Integer searchRadius ,
54
- @ RequestParam (required = false , defaultValue = "ALL" ) Category category ,
55
- Double lat ,
56
- Double lon , Pageable pageable ) {
57
- return ResponseCustom .OK (
58
- storeService .searchByCategory (AuthenticationParser .parseUserId (authentication ), searchRadius , category , lat , lon ,
59
- pageable ));
60
- }
61
-
62
- @ Operation (summary = "매장 찾기(검색)" , description = "검색어와 매장 유형에 맞는 매장을 검색합니다." )
63
- @ GetMapping ("/search" )
64
- public ResponseCustom <Page <SearchStoresResponse >> searchStores (
65
- Authentication authentication ,
66
- @ RequestParam (required = false , defaultValue = "" ) String keyword , Pageable pageable ) {
67
- return ResponseCustom .OK (
68
- storeService .searchStores (AuthenticationParser .parseUserId (authentication ), keyword , pageable ));
69
- }
70
-
71
- @ Operation (summary = "매장 상세 페이지 조회" , description = "매장을 상세 조회합니다." )
72
- @ GetMapping ("/{storeId}" )
73
- public ResponseCustom <StoreSearchDetailsResponse > storeSearchDetails (
74
- Authentication authentication ,
75
- @ PathVariable Long storeId
76
- ) {
77
- return ResponseCustom .OK (storeService .storeSearchDetails (AuthenticationParser .parseUserId (authentication ), storeId ));
78
- }
79
-
80
- @ Operation (summary = "가게 등록" , description = "신규 파트너 가게를 등록합니다." )
81
- @ PostMapping (value = "/create" , produces = MediaType .APPLICATION_JSON_VALUE , consumes = MediaType .MULTIPART_FORM_DATA_VALUE )
82
- public ResponseCustom <Message > createStore (
83
- Authentication authentication ,
84
- @ Parameter (name = "image" , description = "업로드 사진 데이터" ) @ RequestPart (value = "image" ) MultipartFile image ,
85
- @ RequestPart (value = "store" ) StoreCreateRequestDTO storeCreateRequestDTO ,
86
- @ RequestPart (value = "menuImages" , required = false ) List <MultipartFile > menuImages ) {
87
-
88
- storeService .createStore (AuthenticationParser .parseUserId (authentication ), storeCreateRequestDTO , image ,
89
- menuImages );
90
- return ResponseCustom .OK (Message .builder ().message ("success" ).build ());
91
- }
92
-
93
-
94
- @ Operation (summary = "가게 정보 수정" , description = "가게 정보를 수정합니다." )
95
- @ PatchMapping ("/update" )
96
- public ResponseCustom <Message > updateStore (Authentication authentication ,
97
- @ RequestBody StoreUpdateRequestDTO storeUpdateRequestDTO ) {
98
- storeService .updateStore (AuthenticationParser .parseUserId (authentication ), storeUpdateRequestDTO );
99
- return ResponseCustom .OK (Message .builder ().message ("success" ).build ());
100
- }
101
-
102
- @ Operation (summary = "가게 정보 조회" , description = "가게 상세 정보를 조회합니다." )
103
- @ GetMapping ("" )
104
- public ResponseCustom <StoreGetResponseDTO > getStoreInfo (Authentication authentication ) {
105
- return ResponseCustom .OK (storeService .getStoreInfo (AuthenticationParser .parseUserId (authentication )));
106
- }
107
-
108
- @ Operation (summary = "결제 그룹 조회" , description = "장부 결제 그룹을 조회합니다." )
109
- @ GetMapping ("/payment_group" )
110
- public ResponseCustom <List <StoreTeamResponse >> getPaymentGroup (Authentication authentication ) {
111
- return ResponseCustom .OK (
112
- storeService .getPaymentGroup (AuthenticationParser .parseUserId (authentication )));
113
- }
114
-
115
- @ Operation (summary = "결제 그룹 상세 조회" , description = "장부 결제 그룹을 상세 조회합니다." )
116
- @ GetMapping ("/payment_group/{teamId}" )
117
- public ResponseCustom <PaymentGroupDetailResponse > getPaymentGroupDetail (Authentication authentication ,
118
- @ PathVariable Long teamId ) {
119
- return ResponseCustom .OK (
120
- storeService .getPaymentGroupDetail (AuthenticationParser .parseUserId (authentication ), teamId ));
121
- }
122
-
123
- @ Operation (summary = "결제 내역 조회" , description = "가게에서 일어난 결제 내역을 조회합니다." )
124
- @ GetMapping ("/payment_history" )
125
- public ResponseCustom <?> getPaymentHistory (Authentication authentication ) {
126
- return ResponseCustom .OK (
127
- storeService .getPaymentHistory (AuthenticationParser .parseUserId (authentication )));
128
- }
129
-
130
- @ Operation (summary = "지난 주문 조회" , description = "가게에 있는 지난 주문을 조회합니다" )
131
- @ GetMapping ("/orders/last" )
132
- public ResponseCustom <List <OrdersGetResponse >> getLastOrders (Authentication authentication ) {
133
- List <OrdersGetResponse > ordersLast = storeService .getOrdersLast (
134
- AuthenticationParser .parseUserId (authentication ));
135
- return ResponseCustom .OK (ordersLast );
136
- }
137
-
138
- @ Operation (summary = "오늘 주문 조회" , description = "가게에 있는 오늘 주문을 조회합니다" )
139
- @ GetMapping ("/orders/today" )
140
- public ResponseCustom <OrdersTodayResponse > getTodayOrders (Authentication authentication ) {
141
- return ResponseCustom .OK (storeService .getTodayOrders (
142
- AuthenticationParser .parseUserId (authentication )));
143
- }
144
-
145
- @ Operation (summary = "주문 상세 조회" , description = "가게에 있는 주문을 상세 조회합니다" )
146
- @ GetMapping ("/orders/{ordersId}" )
147
- public ResponseCustom <OrdersDetailResponse > getOrders (Authentication authentication , @ RequestParam Long orderId ) {
148
- return ResponseCustom .OK (
149
- storeService .getOrderDetails (AuthenticationParser .parseUserId (authentication ), orderId ));
150
- }
53
+ private final StoreService storeService ;
54
+
55
+ @ Operation (summary = "카테고리 별 가게 목록 조회" , description = "카테고리 별로 가게 목록을 조회합니다." )
56
+ @ PostMapping ("/category" )
57
+ public ResponseCustom <Page <SearchStoresResponse >> searchByCategory (
58
+ Authentication authentication ,
59
+ @ RequestParam (required = false , defaultValue = "3" ) Integer searchRadius ,
60
+ @ RequestParam (required = false , defaultValue = "ALL" ) Category category ,
61
+ Double lat ,
62
+ Double lon , Pageable pageable ) {
63
+ return ResponseCustom .OK (
64
+ storeService .searchByCategory (AuthenticationParser .parseUserId (authentication ), searchRadius , category , lat ,
65
+ lon ,
66
+ pageable ));
67
+ }
68
+
69
+ @ Operation (summary = "매장 찾기(검색)" , description = "검색어와 매장 유형에 맞는 매장을 검색합니다." )
70
+ @ GetMapping ("/search" )
71
+ public ResponseCustom <Page <SearchStoresResponse >> searchStores (
72
+ Authentication authentication ,
73
+ @ RequestParam (required = false , defaultValue = "" ) String keyword , Pageable pageable ) {
74
+ return ResponseCustom .OK (
75
+ storeService .searchStores (AuthenticationParser .parseUserId (authentication ), keyword , pageable ));
76
+ }
77
+
78
+ @ Operation (summary = "매장 상세 페이지 조회" , description = "매장을 상세 조회합니다." )
79
+ @ GetMapping ("/{storeId}" )
80
+ public ResponseCustom <StoreSearchDetailsResponse > storeSearchDetails (
81
+ Authentication authentication ,
82
+ @ PathVariable Long storeId
83
+ ) {
84
+ return ResponseCustom .OK (
85
+ storeService .storeSearchDetails (AuthenticationParser .parseUserId (authentication ), storeId ));
86
+ }
87
+
88
+ @ Operation (summary = "가게 등록" , description = "신규 파트너 가게를 등록합니다." )
89
+ @ PostMapping (value = "/create" , produces = MediaType .APPLICATION_JSON_VALUE , consumes = MediaType .MULTIPART_FORM_DATA_VALUE )
90
+ public ResponseCustom <Message > createStore (
91
+ Authentication authentication ,
92
+ @ Parameter (name = "image" , description = "업로드 사진 데이터" ) @ RequestPart (value = "image" ) MultipartFile image ,
93
+ @ RequestPart (value = "store" ) StoreCreateRequestDTO storeCreateRequestDTO ,
94
+ @ RequestPart (value = "menuImages" , required = false ) List <MultipartFile > menuImages ) {
95
+
96
+ storeService .createStore (AuthenticationParser .parseUserId (authentication ), storeCreateRequestDTO , image ,
97
+ menuImages );
98
+ return ResponseCustom .OK (Message .builder ().message ("success" ).build ());
99
+ }
100
+
101
+ @ Operation (summary = "가게 정보 수정" , description = "가게 정보를 수정합니다." )
102
+ @ PatchMapping ("/update" )
103
+ public ResponseCustom <Message > updateStore (Authentication authentication ,
104
+ @ RequestBody StoreUpdateRequestDTO storeUpdateRequestDTO ) {
105
+ storeService .updateStore (AuthenticationParser .parseUserId (authentication ), storeUpdateRequestDTO );
106
+ return ResponseCustom .OK (Message .builder ().message ("success" ).build ());
107
+ }
108
+
109
+ @ Operation (summary = "가게 정보 조회" , description = "가게 상세 정보를 조회합니다." )
110
+ @ GetMapping ("" )
111
+ public ResponseCustom <StoreGetResponseDTO > getStoreInfo (Authentication authentication ) {
112
+ return ResponseCustom .OK (storeService .getStoreInfo (AuthenticationParser .parseUserId (authentication )));
113
+ }
114
+
115
+ @ Operation (summary = "결제 그룹 조회" , description = "장부 결제 그룹을 조회합니다." )
116
+ @ GetMapping ("/payment_group" )
117
+ public ResponseCustom <List <StoreTeamResponse >> getPaymentGroup (Authentication authentication ) {
118
+ return ResponseCustom .OK (
119
+ storeService .getPaymentGroup (AuthenticationParser .parseUserId (authentication )));
120
+ }
121
+
122
+ @ Operation (summary = "결제 그룹 상세 조회" , description = "장부 결제 그룹을 상세 조회합니다." )
123
+ @ GetMapping ("/payment_group/{teamId}" )
124
+ public ResponseCustom <PaymentGroupDetailResponse > getPaymentGroupDetail (Authentication authentication ,
125
+ @ PathVariable Long teamId ) {
126
+ return ResponseCustom .OK (
127
+ storeService .getPaymentGroupDetail (AuthenticationParser .parseUserId (authentication ), teamId ));
128
+ }
129
+
130
+ @ Operation (summary = "결제 내역 조회" , description = "가게에서 일어난 결제 내역을 조회합니다." )
131
+ @ GetMapping ("/payment_history" )
132
+ public ResponseCustom <?> getPaymentHistory (Authentication authentication ) {
133
+ return ResponseCustom .OK (
134
+ storeService .getPaymentHistory (AuthenticationParser .parseUserId (authentication )));
135
+ }
136
+
137
+ @ Operation (summary = "지난 주문 조회" , description = "가게에 있는 지난 주문을 조회합니다" )
138
+ @ GetMapping ("/orders/last" )
139
+ public ResponseCustom <List <OrdersGetResponse >> getLastOrders (Authentication authentication ) {
140
+ List <OrdersGetResponse > ordersLast = storeService .getOrdersLast (
141
+ AuthenticationParser .parseUserId (authentication ));
142
+ return ResponseCustom .OK (ordersLast );
143
+ }
144
+
145
+ @ Operation (summary = "오늘 주문 조회" , description = "가게에 있는 오늘 주문을 조회합니다" )
146
+ @ GetMapping ("/orders/today" )
147
+ public ResponseCustom <OrdersTodayResponse > getTodayOrders (Authentication authentication ) {
148
+ return ResponseCustom .OK (storeService .getTodayOrders (
149
+ AuthenticationParser .parseUserId (authentication )));
150
+ }
151
+
152
+ @ Operation (summary = "주문 상세 조회" , description = "가게에 있는 주문을 상세 조회합니다" )
153
+ @ GetMapping ("/orders/{ordersId}" )
154
+ public ResponseCustom <OrdersDetailResponse > getOrders (Authentication authentication , @ RequestParam Long orderId ) {
155
+ return ResponseCustom .OK (
156
+ storeService .getOrderDetails (AuthenticationParser .parseUserId (authentication ), orderId ));
157
+ }
158
+
159
+ @ Operation (summary = "가게 엑셀 다운로드" , description = "가게 장부 세부 내역을 엑셀로 제공합니다." )
160
+ @ GetMapping ("/excel" )
161
+ public ResponseEntity <?> getExcel (
162
+ // Authentication authentication,
163
+ @ RequestParam (defaultValue = "1" ) Integer period
164
+ ) {
165
+ byte [] excel = storeService .createExcel ("test-owner" , period );
166
+
167
+ String today = LocalDate .now ().format (DateTimeFormatter .ofPattern ("yyyyMMdd" ));
168
+ String fileName = "장부_세부내역_" + period + "개월_" + today + ".xlsx" ;
169
+ String encodedFileName = URLEncoder .encode (fileName , StandardCharsets .UTF_8 )
170
+ .replace ("+" , "%20" );
171
+
172
+ HttpHeaders headers = new HttpHeaders ();
173
+ headers .setContentType (MediaType .APPLICATION_OCTET_STREAM );
174
+ headers .set ("Content-Disposition" ,
175
+ "attachment; filename=\" " + encodedFileName + "\" ; filename*=UTF-8''" + encodedFileName );
176
+
177
+ return ResponseEntity .ok ().headers (headers ).body (excel );
178
+ }
151
179
}
0 commit comments