Skip to content

Commit

Permalink
Merge pull request #189 from 9oormthon-univ/feat/excel
Browse files Browse the repository at this point in the history
Feat/excel
  • Loading branch information
HyunWoo9930 authored Dec 3, 2024
2 parents ec3a7c5 + 525164b commit cd47d13
Show file tree
Hide file tree
Showing 7 changed files with 388 additions and 113 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ dependencies {
implementation 'com.sun.xml.ws:jaxws-rt:2.3.1'
implementation 'org.glassfish.metro:webservices-rt:2.4.4'
implementation fileTree(dir: 'libs', include: ['*.jar'])

// excel
implementation 'org.apache.poi:poi:5.2.3' // .xls
implementation 'org.apache.poi:poi-ooxml:5.2.3' // .xlsx
}

tasks.named('test') {
Expand Down
238 changes: 133 additions & 105 deletions src/main/java/com/jangburich/domain/store/controller/StoreController.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.jangburich.domain.store.controller;

import com.jangburich.domain.store.dto.response.StoreSearchDetailsResponse;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
Expand All @@ -27,6 +32,7 @@
import com.jangburich.domain.store.dto.response.OrdersTodayResponse;
import com.jangburich.domain.store.dto.response.PaymentGroupDetailResponse;
import com.jangburich.domain.store.dto.response.SearchStoresResponse;
import com.jangburich.domain.store.dto.response.StoreSearchDetailsResponse;
import com.jangburich.domain.store.dto.response.StoreTeamResponse;
import com.jangburich.domain.store.service.StoreService;
import com.jangburich.global.payload.Message;
Expand All @@ -44,108 +50,130 @@
@RequestMapping("/store")
public class StoreController {

private final StoreService storeService;

@Operation(summary = "์นดํ…Œ๊ณ ๋ฆฌ ๋ณ„ ๊ฐ€๊ฒŒ ๋ชฉ๋ก ์กฐํšŒ", description = "์นดํ…Œ๊ณ ๋ฆฌ ๋ณ„๋กœ ๊ฐ€๊ฒŒ ๋ชฉ๋ก์„ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@PostMapping("/category")
public ResponseCustom<Page<SearchStoresResponse>> searchByCategory(
Authentication authentication,
@RequestParam(required = false, defaultValue = "3") Integer searchRadius,
@RequestParam(required = false, defaultValue = "ALL") Category category,
Double lat,
Double lon, Pageable pageable) {
return ResponseCustom.OK(
storeService.searchByCategory(AuthenticationParser.parseUserId(authentication), searchRadius, category, lat, lon,
pageable));
}

@Operation(summary = "๋งค์žฅ ์ฐพ๊ธฐ(๊ฒ€์ƒ‰)", description = "๊ฒ€์ƒ‰์–ด์™€ ๋งค์žฅ ์œ ํ˜•์— ๋งž๋Š” ๋งค์žฅ์„ ๊ฒ€์ƒ‰ํ•ฉ๋‹ˆ๋‹ค.")
@GetMapping("/search")
public ResponseCustom<Page<SearchStoresResponse>> searchStores(
Authentication authentication,
@RequestParam(required = false, defaultValue = "") String keyword, Pageable pageable) {
return ResponseCustom.OK(
storeService.searchStores(AuthenticationParser.parseUserId(authentication), keyword, pageable));
}

@Operation(summary = "๋งค์žฅ ์ƒ์„ธ ํŽ˜์ด์ง€ ์กฐํšŒ", description = "๋งค์žฅ์„ ์ƒ์„ธ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@GetMapping("/{storeId}")
public ResponseCustom<StoreSearchDetailsResponse> storeSearchDetails(
Authentication authentication,
@PathVariable Long storeId
) {
return ResponseCustom.OK(storeService.storeSearchDetails(AuthenticationParser.parseUserId(authentication), storeId));
}

@Operation(summary = "๊ฐ€๊ฒŒ ๋“ฑ๋ก", description = "์‹ ๊ทœ ํŒŒํŠธ๋„ˆ ๊ฐ€๊ฒŒ๋ฅผ ๋“ฑ๋กํ•ฉ๋‹ˆ๋‹ค.")
@PostMapping(value = "/create", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseCustom<Message> createStore(
Authentication authentication,
@Parameter(name = "image", description = "์—…๋กœ๋“œ ์‚ฌ์ง„ ๋ฐ์ดํ„ฐ") @RequestPart(value = "image") MultipartFile image,
@RequestPart(value = "store") StoreCreateRequestDTO storeCreateRequestDTO,
@RequestPart(value = "menuImages", required = false) List<MultipartFile> menuImages) {

storeService.createStore(AuthenticationParser.parseUserId(authentication), storeCreateRequestDTO, image,
menuImages);
return ResponseCustom.OK(Message.builder().message("success").build());
}


@Operation(summary = "๊ฐ€๊ฒŒ ์ •๋ณด ์ˆ˜์ •", description = "๊ฐ€๊ฒŒ ์ •๋ณด๋ฅผ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.")
@PatchMapping("/update")
public ResponseCustom<Message> updateStore(Authentication authentication,
@RequestBody StoreUpdateRequestDTO storeUpdateRequestDTO) {
storeService.updateStore(AuthenticationParser.parseUserId(authentication), storeUpdateRequestDTO);
return ResponseCustom.OK(Message.builder().message("success").build());
}

@Operation(summary = "๊ฐ€๊ฒŒ ์ •๋ณด ์กฐํšŒ", description = "๊ฐ€๊ฒŒ ์ƒ์„ธ ์ •๋ณด๋ฅผ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@GetMapping("")
public ResponseCustom<StoreGetResponseDTO> getStoreInfo(Authentication authentication) {
return ResponseCustom.OK(storeService.getStoreInfo(AuthenticationParser.parseUserId(authentication)));
}

@Operation(summary = "๊ฒฐ์ œ ๊ทธ๋ฃน ์กฐํšŒ", description = "์žฅ๋ถ€ ๊ฒฐ์ œ ๊ทธ๋ฃน์„ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@GetMapping("/payment_group")
public ResponseCustom<List<StoreTeamResponse>> getPaymentGroup(Authentication authentication) {
return ResponseCustom.OK(
storeService.getPaymentGroup(AuthenticationParser.parseUserId(authentication)));
}

@Operation(summary = "๊ฒฐ์ œ ๊ทธ๋ฃน ์ƒ์„ธ ์กฐํšŒ", description = "์žฅ๋ถ€ ๊ฒฐ์ œ ๊ทธ๋ฃน์„ ์ƒ์„ธ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@GetMapping("/payment_group/{teamId}")
public ResponseCustom<PaymentGroupDetailResponse> getPaymentGroupDetail(Authentication authentication,
@PathVariable Long teamId) {
return ResponseCustom.OK(
storeService.getPaymentGroupDetail(AuthenticationParser.parseUserId(authentication), teamId));
}

@Operation(summary = "๊ฒฐ์ œ ๋‚ด์—ญ ์กฐํšŒ", description = "๊ฐ€๊ฒŒ์—์„œ ์ผ์–ด๋‚œ ๊ฒฐ์ œ ๋‚ด์—ญ์„ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@GetMapping("/payment_history")
public ResponseCustom<?> getPaymentHistory(Authentication authentication) {
return ResponseCustom.OK(
storeService.getPaymentHistory(AuthenticationParser.parseUserId(authentication)));
}

@Operation(summary = "์ง€๋‚œ ์ฃผ๋ฌธ ์กฐํšŒ", description = "๊ฐ€๊ฒŒ์— ์žˆ๋Š” ์ง€๋‚œ ์ฃผ๋ฌธ์„ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค")
@GetMapping("/orders/last")
public ResponseCustom<List<OrdersGetResponse>> getLastOrders(Authentication authentication) {
List<OrdersGetResponse> ordersLast = storeService.getOrdersLast(
AuthenticationParser.parseUserId(authentication));
return ResponseCustom.OK(ordersLast);
}

@Operation(summary = "์˜ค๋Š˜ ์ฃผ๋ฌธ ์กฐํšŒ", description = "๊ฐ€๊ฒŒ์— ์žˆ๋Š” ์˜ค๋Š˜ ์ฃผ๋ฌธ์„ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค")
@GetMapping("/orders/today")
public ResponseCustom<OrdersTodayResponse> getTodayOrders(Authentication authentication) {
return ResponseCustom.OK(storeService.getTodayOrders(
AuthenticationParser.parseUserId(authentication)));
}

@Operation(summary = "์ฃผ๋ฌธ ์ƒ์„ธ ์กฐํšŒ", description = "๊ฐ€๊ฒŒ์— ์žˆ๋Š” ์ฃผ๋ฌธ์„ ์ƒ์„ธ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค")
@GetMapping("/orders/{ordersId}")
public ResponseCustom<OrdersDetailResponse> getOrders(Authentication authentication, @RequestParam Long orderId) {
return ResponseCustom.OK(
storeService.getOrderDetails(AuthenticationParser.parseUserId(authentication), orderId));
}
private final StoreService storeService;

@Operation(summary = "์นดํ…Œ๊ณ ๋ฆฌ ๋ณ„ ๊ฐ€๊ฒŒ ๋ชฉ๋ก ์กฐํšŒ", description = "์นดํ…Œ๊ณ ๋ฆฌ ๋ณ„๋กœ ๊ฐ€๊ฒŒ ๋ชฉ๋ก์„ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@PostMapping("/category")
public ResponseCustom<Page<SearchStoresResponse>> searchByCategory(
Authentication authentication,
@RequestParam(required = false, defaultValue = "3") Integer searchRadius,
@RequestParam(required = false, defaultValue = "ALL") Category category,
Double lat,
Double lon, Pageable pageable) {
return ResponseCustom.OK(
storeService.searchByCategory(AuthenticationParser.parseUserId(authentication), searchRadius, category, lat,
lon,
pageable));
}

@Operation(summary = "๋งค์žฅ ์ฐพ๊ธฐ(๊ฒ€์ƒ‰)", description = "๊ฒ€์ƒ‰์–ด์™€ ๋งค์žฅ ์œ ํ˜•์— ๋งž๋Š” ๋งค์žฅ์„ ๊ฒ€์ƒ‰ํ•ฉ๋‹ˆ๋‹ค.")
@GetMapping("/search")
public ResponseCustom<Page<SearchStoresResponse>> searchStores(
Authentication authentication,
@RequestParam(required = false, defaultValue = "") String keyword, Pageable pageable) {
return ResponseCustom.OK(
storeService.searchStores(AuthenticationParser.parseUserId(authentication), keyword, pageable));
}

@Operation(summary = "๋งค์žฅ ์ƒ์„ธ ํŽ˜์ด์ง€ ์กฐํšŒ", description = "๋งค์žฅ์„ ์ƒ์„ธ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@GetMapping("/{storeId}")
public ResponseCustom<StoreSearchDetailsResponse> storeSearchDetails(
Authentication authentication,
@PathVariable Long storeId
) {
return ResponseCustom.OK(
storeService.storeSearchDetails(AuthenticationParser.parseUserId(authentication), storeId));
}

@Operation(summary = "๊ฐ€๊ฒŒ ๋“ฑ๋ก", description = "์‹ ๊ทœ ํŒŒํŠธ๋„ˆ ๊ฐ€๊ฒŒ๋ฅผ ๋“ฑ๋กํ•ฉ๋‹ˆ๋‹ค.")
@PostMapping(value = "/create", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseCustom<Message> createStore(
Authentication authentication,
@Parameter(name = "image", description = "์—…๋กœ๋“œ ์‚ฌ์ง„ ๋ฐ์ดํ„ฐ") @RequestPart(value = "image") MultipartFile image,
@RequestPart(value = "store") StoreCreateRequestDTO storeCreateRequestDTO,
@RequestPart(value = "menuImages", required = false) List<MultipartFile> menuImages) {

storeService.createStore(AuthenticationParser.parseUserId(authentication), storeCreateRequestDTO, image,
menuImages);
return ResponseCustom.OK(Message.builder().message("success").build());
}

@Operation(summary = "๊ฐ€๊ฒŒ ์ •๋ณด ์ˆ˜์ •", description = "๊ฐ€๊ฒŒ ์ •๋ณด๋ฅผ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.")
@PatchMapping("/update")
public ResponseCustom<Message> updateStore(Authentication authentication,
@RequestBody StoreUpdateRequestDTO storeUpdateRequestDTO) {
storeService.updateStore(AuthenticationParser.parseUserId(authentication), storeUpdateRequestDTO);
return ResponseCustom.OK(Message.builder().message("success").build());
}

@Operation(summary = "๊ฐ€๊ฒŒ ์ •๋ณด ์กฐํšŒ", description = "๊ฐ€๊ฒŒ ์ƒ์„ธ ์ •๋ณด๋ฅผ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@GetMapping("")
public ResponseCustom<StoreGetResponseDTO> getStoreInfo(Authentication authentication) {
return ResponseCustom.OK(storeService.getStoreInfo(AuthenticationParser.parseUserId(authentication)));
}

@Operation(summary = "๊ฒฐ์ œ ๊ทธ๋ฃน ์กฐํšŒ", description = "์žฅ๋ถ€ ๊ฒฐ์ œ ๊ทธ๋ฃน์„ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@GetMapping("/payment_group")
public ResponseCustom<List<StoreTeamResponse>> getPaymentGroup(Authentication authentication) {
return ResponseCustom.OK(
storeService.getPaymentGroup(AuthenticationParser.parseUserId(authentication)));
}

@Operation(summary = "๊ฒฐ์ œ ๊ทธ๋ฃน ์ƒ์„ธ ์กฐํšŒ", description = "์žฅ๋ถ€ ๊ฒฐ์ œ ๊ทธ๋ฃน์„ ์ƒ์„ธ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@GetMapping("/payment_group/{teamId}")
public ResponseCustom<PaymentGroupDetailResponse> getPaymentGroupDetail(Authentication authentication,
@PathVariable Long teamId) {
return ResponseCustom.OK(
storeService.getPaymentGroupDetail(AuthenticationParser.parseUserId(authentication), teamId));
}

@Operation(summary = "๊ฒฐ์ œ ๋‚ด์—ญ ์กฐํšŒ", description = "๊ฐ€๊ฒŒ์—์„œ ์ผ์–ด๋‚œ ๊ฒฐ์ œ ๋‚ด์—ญ์„ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.")
@GetMapping("/payment_history")
public ResponseCustom<?> getPaymentHistory(Authentication authentication) {
return ResponseCustom.OK(
storeService.getPaymentHistory(AuthenticationParser.parseUserId(authentication)));
}

@Operation(summary = "์ง€๋‚œ ์ฃผ๋ฌธ ์กฐํšŒ", description = "๊ฐ€๊ฒŒ์— ์žˆ๋Š” ์ง€๋‚œ ์ฃผ๋ฌธ์„ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค")
@GetMapping("/orders/last")
public ResponseCustom<List<OrdersGetResponse>> getLastOrders(Authentication authentication) {
List<OrdersGetResponse> ordersLast = storeService.getOrdersLast(
AuthenticationParser.parseUserId(authentication));
return ResponseCustom.OK(ordersLast);
}

@Operation(summary = "์˜ค๋Š˜ ์ฃผ๋ฌธ ์กฐํšŒ", description = "๊ฐ€๊ฒŒ์— ์žˆ๋Š” ์˜ค๋Š˜ ์ฃผ๋ฌธ์„ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค")
@GetMapping("/orders/today")
public ResponseCustom<OrdersTodayResponse> getTodayOrders(Authentication authentication) {
return ResponseCustom.OK(storeService.getTodayOrders(
AuthenticationParser.parseUserId(authentication)));
}

@Operation(summary = "์ฃผ๋ฌธ ์ƒ์„ธ ์กฐํšŒ", description = "๊ฐ€๊ฒŒ์— ์žˆ๋Š” ์ฃผ๋ฌธ์„ ์ƒ์„ธ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค")
@GetMapping("/orders/{ordersId}")
public ResponseCustom<OrdersDetailResponse> getOrders(Authentication authentication, @RequestParam Long orderId) {
return ResponseCustom.OK(
storeService.getOrderDetails(AuthenticationParser.parseUserId(authentication), orderId));
}

@Operation(summary = "๊ฐ€๊ฒŒ ์—‘์…€ ๋‹ค์šด๋กœ๋“œ", description = "๊ฐ€๊ฒŒ ์žฅ๋ถ€ ์„ธ๋ถ€ ๋‚ด์—ญ์„ ์—‘์…€๋กœ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.")
@GetMapping("/excel")
public ResponseEntity<?> getExcel(
// Authentication authentication,
@RequestParam(defaultValue = "1") Integer period
) {
byte[] excel = storeService.createExcel("test-owner", period);

String today = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
String fileName = "์žฅ๋ถ€_์„ธ๋ถ€๋‚ด์—ญ_" + period + "๊ฐœ์›”_" + today + ".xlsx";
String encodedFileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8)
.replace("+", "%20");

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.set("Content-Disposition",
"attachment; filename=\"" + encodedFileName + "\"; filename*=UTF-8''" + encodedFileName);

return ResponseEntity.ok().headers(headers).body(excel);
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
package com.jangburich.domain.store.domain;

import java.time.LocalDate;
import java.time.LocalDateTime;

import com.jangburich.domain.point.domain.TransactionType;
import com.querydsl.core.annotations.QueryProjection;

public record StoreChargeHistoryResponse(
Long id,
LocalDateTime createdAt,
String teamName,
Integer transactionedPoint
Long teamId,
Integer transactionedPoint,
TransactionType transactionType
) {
@QueryProjection
public StoreChargeHistoryResponse(Long id, LocalDateTime createdAt, String teamName, Integer transactionedPoint) {
public StoreChargeHistoryResponse(Long id, LocalDateTime createdAt, String teamName, Long teamId,
Integer transactionedPoint, TransactionType transactionType) {
this.id = id;
this.createdAt = createdAt;
this.teamName = teamName;
this.teamId = teamId;
this.transactionedPoint = transactionedPoint;
this.transactionType = transactionType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public class StoreTeam extends BaseEntity {
@Column(name = "prepaid_expiration_date")
private LocalDate prepaidExpirationDate;

@Column(name = "prepay_count")
private Integer prepayCount;

public void updatePersonalAllocatedPoint(Integer point) {
this.personalAllocatedPoint = point;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public record StoreTeamResponseDTO(
Long id,
Integer remainPoint,
Integer point,
Long teamId,
String teamName,
String teamDescription,
Expand All @@ -18,10 +19,11 @@ public record StoreTeamResponseDTO(

) {
@QueryProjection
public StoreTeamResponseDTO(Long id, Integer remainPoint, Long teamId, String teamName, String teamDescription,
Long storeId, LocalDateTime updatedAt) {
public StoreTeamResponseDTO(Long id, Integer remainPoint, Integer point, Long teamId, String teamName,
String teamDescription, Long storeId, LocalDateTime updatedAt) {
this.id = id;
this.remainPoint = remainPoint;
this.point = point;
this.teamId = teamId;
this.teamName = teamName;
this.teamDescription = teamDescription;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public Message prepay(String userId, PrepayRequest prepayRequest) {
.transactionedPoint(prepayRequest.prepayAmount())
.user(user)
.store(store)
.team(team)
.build();

pointTransactionRepository.save(pointTransaction);
Expand All @@ -94,6 +95,7 @@ public Message prepay(String userId, PrepayRequest prepayRequest) {
StoreTeam storeTeam = storeAndTeam.get();
storeTeam.setPersonalAllocatedPoint(prepayRequest.personalAllocatedAmount());
storeTeam.recharge(prepayRequest.prepayAmount());
storeTeam.setPrepayCount(storeTeam.getPrepayCount() + 1);

return Message.builder()
.message("๋งค์žฅ ์„ ๊ฒฐ์ œ๊ฐ€ ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")
Expand Down
Loading

0 comments on commit cd47d13

Please sign in to comment.