Skip to content

Commit

Permalink
๐Ÿ”จ Refactor/#59 - 3.2 ๊ฐ€๊ฒŒ ์ƒ์„ธ ์ •๋ณด ์กฐํšŒ store history info ๋ฐฐ์—ด๋กœ ๋ณ€๊ฒฝ (#64)
Browse files Browse the repository at this point in the history
* โœจ feature/#59 : store history ์ถ”๊ฐ€ API ๊ตฌํ˜„

Signed-off-by: EunJiJung <[email protected]>

* โœจ feature/#59 : store history ์ถ”๊ฐ€ http ๋ฉ”์„œ๋“œ ์ •์˜

Signed-off-by: EunJiJung <[email protected]>

* โ™ป๏ธ refactor/#59 : store history yyyy๋…„ mm์›” ๊ธฐ์ค€ info list๋กœ ๋ณ€๊ฒฝ

Signed-off-by: EunJiJung <[email protected]>

* โ™ป๏ธ refactor/#59 : amount util ํŒŒ์ผ ์ œ๊ฑฐ, amount ๊ณ„์‚ฐ ์‹ response dto์—์„œ ์ฒ˜๋ฆฌ

Signed-off-by: EunJiJung <[email protected]>

* โ™ป๏ธ refactor/#59 : ticket response dto store_ingo -> info๋กœ ์˜คํƒ€ ๋ณ€๊ฒฝ

Signed-off-by: EunJiJung <[email protected]>

---------

Signed-off-by: EunJiJung <[email protected]>
  • Loading branch information
bianbbc87 authored Nov 22, 2024
1 parent 7dd2ffe commit 143e07b
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 12 deletions.
15 changes: 14 additions & 1 deletion http/account/AccountControllerHttpRequest.http
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,17 @@ Authorization: Bearer {{access_token}}
### 3.2 ๊ฐ€๊ฒŒ ์ƒ์„ธ ์ •๋ณด ์กฐํšŒ
// @no-log
GET {{host_url}}/api/v1/stores/{{account.API_3_2.id}}/details
Authorization: Bearer {{access_token}}
Authorization: Bearer {{access_token}}

### 3.3 ๊ฐ€๊ฒŒ ํžˆ์Šคํ† ๋ฆฌ ๋“ฑ๋กํ•˜๊ธฐ
// @no-log
POST {{host_url}}/api/v1/store-histories
Content-Type: application/json
Authorization: Bearer {{access_token}}

{
"store_id": {{account.API_3_3.store_id}},
"action_date": "{{account.API_3_3.action_date}}",
"content": "{{account.API_3_3.content}}",
"amount": {{account.API_3_3.amount}}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.daon.onjung.account.application.controller.command;

import com.daon.onjung.account.application.dto.request.CreateStoreHistoryRequestDto;
import com.daon.onjung.account.application.usecase.CreateStoreHistoryUseCase;
import com.daon.onjung.core.dto.ResponseDto;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
public class StoreCommandV1Controller {

private final CreateStoreHistoryUseCase createStoreHistoryUseCase;

/**
* 3.3 ๊ฐ€๊ฒŒ ํžˆ์Šคํ† ๋ฆฌ ๋“ฑ๋กํ•˜๊ธฐ
*/
@PostMapping(value = "/api/v1/store-histories")
public ResponseDto<Void> createStoreHistory(
@RequestBody @Valid CreateStoreHistoryRequestDto requestDto
) {
createStoreHistoryUseCase.execute(requestDto);
return ResponseDto.ok(null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.daon.onjung.account.application.dto.request;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.time.LocalDate;

public record CreateStoreHistoryRequestDto(
@JsonProperty("store_id")
Long storeId,

@JsonProperty("action_date")
LocalDate actionDate,

@JsonProperty("content")
String content,

@JsonProperty("amount")
Integer amount
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,21 +215,25 @@ public static class StoreHistoryDto {

@NotNull(message = "info๋Š” null์ผ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")
@JsonProperty("info")
private final StoreHistoryInfo storeHistoryInfo;
private final List<StoreHistoryInfo> storeHistoryInfo;

@Builder
public StoreHistoryDto(String date, StoreHistoryInfo storeHistoryInfo) {
public StoreHistoryDto(String date, List<StoreHistoryInfo> storeHistoryInfo) {
this.date = date;
this.storeHistoryInfo = storeHistoryInfo;
}

public static StoreHistoryDto fromEntity(StoreHistory storeHistory) {
return StoreHistoryDto.builder()
.date(DateTimeUtil.convertLocalDateToKORYearMonthString(storeHistory.getActionDate()))
.storeHistoryInfo(StoreHistoryInfo.fromEntity(
storeHistory.getContent(),
storeHistory.getAmount() + "๋งŒ์›"
))
.date(DateTimeUtil.convertLocalDateToString(storeHistory.getActionDate()))
.storeHistoryInfo(
List.of(
StoreHistoryInfo.fromEntity(
storeHistory.getContent(),
storeHistory.getAmount() / 10000 + "๋งŒ์›"
)
)
)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.daon.onjung.account.application.service;

import com.daon.onjung.account.application.dto.request.CreateStoreHistoryRequestDto;
import com.daon.onjung.account.application.usecase.CreateStoreHistoryUseCase;
import com.daon.onjung.account.domain.Store;
import com.daon.onjung.account.domain.StoreHistory;
import com.daon.onjung.account.domain.service.StoreHistoryService;
import com.daon.onjung.account.repository.mysql.StoreHistoryRepository;
import com.daon.onjung.account.repository.mysql.StoreRepository;
import com.daon.onjung.core.exception.error.ErrorCode;
import com.daon.onjung.core.exception.type.CommonException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
public class CreateStoreHistoryService implements CreateStoreHistoryUseCase {

private final StoreRepository storeRepository;
private final StoreHistoryRepository storeHistoryRepository;

private final StoreHistoryService storeHistoryService;

@Override
@Transactional
public void execute(CreateStoreHistoryRequestDto requestDto) {
Store store = storeRepository.findById(requestDto.storeId())
.orElseThrow(() -> new CommonException(ErrorCode.NOT_FOUND_RESOURCE));

StoreHistory storeHistory = storeHistoryService.createStoreHistory(
requestDto.actionDate(),
requestDto.content(),
requestDto.amount(),
store
);

storeHistoryRepository.save(storeHistory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.daon.onjung.core.exception.error.ErrorCode;
import com.daon.onjung.core.exception.type.CommonException;
import com.daon.onjung.core.utility.BankUtil;
import com.daon.onjung.core.utility.DateTimeUtil;
import com.daon.onjung.core.utility.RestClientUtil;
import com.daon.onjung.event.domain.Event;
import com.daon.onjung.event.domain.service.EventService;
Expand All @@ -21,7 +22,9 @@
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
Expand Down Expand Up @@ -67,8 +70,26 @@ public ReadStoreDetailResponseDto execute(Long id) {

List<StoreHistory> storeHistories = storeHistoryRepository.findByStoreOrderByActionDateAsc(store);

List<ReadStoreDetailResponseDto.StoreHistoryDto> storeHistoryDtos = storeHistories.stream()
.map(ReadStoreDetailResponseDto.StoreHistoryDto::fromEntity)
// ๊ทธ๋ฃนํ™”: actionDate๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๊ทธ๋ฃนํ™”
Map<String, List<StoreHistory>> groupedByYearMonth = storeHistories.stream()
.collect(Collectors.groupingBy(
sh -> DateTimeUtil.convertLocalDateToKORYearMonthString(sh.getActionDate()) // "yyyy๋…„ MM์›”" ๊ธฐ์ค€ ๊ทธ๋ฃนํ™”
));


List<ReadStoreDetailResponseDto.StoreHistoryDto> storeHistoryDtos = groupedByYearMonth.entrySet().stream()
.map(entry -> {
String yearMonth = entry.getKey();
List<ReadStoreDetailResponseDto.StoreHistoryDto.StoreHistoryInfo> infos = entry.getValue().stream()
.map(ReadStoreDetailResponseDto.StoreHistoryDto::fromEntity) // StoreHistory -> StoreHistoryDto ๋ณ€ํ™˜
.flatMap(dto -> dto.getStoreHistoryInfo().stream()) // StoreHistoryInfo๋งŒ ์ถ”์ถœ
.toList();

return ReadStoreDetailResponseDto.StoreHistoryDto.builder()
.date(yearMonth)
.storeHistoryInfo(infos)
.build();
})
.toList();

return ReadStoreDetailResponseDto.fromEntity(storeInfoDto, eventInfoDto, onjungInfoDto, storeHistoryDtos);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.daon.onjung.account.application.usecase;

import com.daon.onjung.account.application.dto.request.CreateStoreHistoryRequestDto;
import com.daon.onjung.core.annotation.bean.UseCase;

import java.time.LocalDate;

@UseCase
public interface CreateStoreHistoryUseCase {
void execute(CreateStoreHistoryRequestDto requestDto);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ public class StoreHistory {
/* Methods ------------------------------------ */
/* -------------------------------------------- */
@Builder
public StoreHistory(LocalDate actionDate, String content, Store store) {
public StoreHistory(LocalDate actionDate, String content, Integer amount, Store store) {
this.actionDate = actionDate;
this.content = content;
this.store = store;
this.amount = amount;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.daon.onjung.account.domain.service;

import com.daon.onjung.account.domain.Store;
import com.daon.onjung.account.domain.StoreHistory;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

@Service
public class StoreHistoryService {
public StoreHistory createStoreHistory(
LocalDate actionDate,
String content,
Integer amount,
Store store
) {
return StoreHistory.builder()
.actionDate(actionDate)
.content(content)
.amount(amount)
.store(store)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static class TicketDto {
@JsonProperty("id")
private final Long id;

@JsonProperty("store_ingo")
@JsonProperty("store_info")
private final StoreInfoDto storeInfo;

@JsonProperty("expiration_date")
Expand Down

0 comments on commit 143e07b

Please sign in to comment.