Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #190

Merged
merged 4 commits into from
Dec 3, 2024
Merged
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
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
Loading