-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DDING-3] ScoreHistory 도메인 리팩토링 적용 (#138)
- Loading branch information
Showing
21 changed files
with
377 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...ava/ddingdong/ddingdongBE/domain/scorehistory/service/FacadeAdminScoreHistoryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package ddingdong.ddingdongBE.domain.scorehistory.service; | ||
|
||
import ddingdong.ddingdongBE.domain.scorehistory.service.dto.command.CreateScoreHistoryCommand; | ||
import ddingdong.ddingdongBE.domain.scorehistory.service.dto.query.AdminClubScoreHistoryListQuery; | ||
|
||
public interface FacadeAdminScoreHistoryService { | ||
|
||
Long create(CreateScoreHistoryCommand command); | ||
|
||
AdminClubScoreHistoryListQuery findAllByClubId(Long clubId); | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
...ddingdong/ddingdongBE/domain/scorehistory/service/FacadeAdminScoreHistoryServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package ddingdong.ddingdongBE.domain.scorehistory.service; | ||
|
||
import ddingdong.ddingdongBE.domain.club.entity.Club; | ||
import ddingdong.ddingdongBE.domain.club.service.ClubService; | ||
import ddingdong.ddingdongBE.domain.scorehistory.entity.ScoreHistory; | ||
import ddingdong.ddingdongBE.domain.scorehistory.service.dto.command.CreateScoreHistoryCommand; | ||
import ddingdong.ddingdongBE.domain.scorehistory.service.dto.query.AdminClubScoreHistoryListQuery; | ||
import java.math.BigDecimal; | ||
import java.math.RoundingMode; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class FacadeAdminScoreHistoryServiceImpl implements FacadeAdminScoreHistoryService { | ||
|
||
private final ScoreHistoryService scoreHistoryService; | ||
private final ClubService clubService; | ||
|
||
@Override | ||
@Transactional | ||
public Long create(CreateScoreHistoryCommand command) { | ||
BigDecimal score = roundToThirdPoint(command.amount()); | ||
Club club = clubService.getByClubId(command.clubId()); | ||
clubService.updateClubScore(club.getId(), score); | ||
return scoreHistoryService.create(command.toEntity(club)); | ||
} | ||
|
||
@Override | ||
public AdminClubScoreHistoryListQuery findAllByClubId(Long clubId) { | ||
Club club = clubService.getByClubId(clubId); | ||
List<ScoreHistory> scoreHistories = scoreHistoryService.findAllByClubId(clubId); | ||
return AdminClubScoreHistoryListQuery.of(club, scoreHistories); | ||
} | ||
|
||
private BigDecimal roundToThirdPoint(BigDecimal value) { | ||
return value.setScale(3, RoundingMode.DOWN); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
...java/ddingdong/ddingdongBE/domain/scorehistory/service/FacadeClubScoreHistoryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package ddingdong.ddingdongBE.domain.scorehistory.service; | ||
|
||
import ddingdong.ddingdongBE.domain.scorehistory.service.dto.query.ClubScoreHistoryListQuery; | ||
|
||
public interface FacadeClubScoreHistoryService { | ||
|
||
ClubScoreHistoryListQuery findMyScoreHistories(Long userId); | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
.../ddingdong/ddingdongBE/domain/scorehistory/service/FacadeClubScoreHistoryServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package ddingdong.ddingdongBE.domain.scorehistory.service; | ||
|
||
import ddingdong.ddingdongBE.domain.club.entity.Club; | ||
import ddingdong.ddingdongBE.domain.club.service.ClubService; | ||
import ddingdong.ddingdongBE.domain.scorehistory.entity.ScoreHistory; | ||
import ddingdong.ddingdongBE.domain.scorehistory.service.dto.query.AdminClubScoreHistoryListQuery; | ||
import ddingdong.ddingdongBE.domain.scorehistory.service.dto.query.ClubScoreHistoryListQuery; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class FacadeClubScoreHistoryServiceImpl implements FacadeClubScoreHistoryService { | ||
|
||
private final ScoreHistoryService scoreHistoryService; | ||
private final ClubService clubService; | ||
|
||
@Override | ||
public ClubScoreHistoryListQuery findMyScoreHistories(Long userId) { | ||
Club club = clubService.getByUserId(userId); | ||
List<ScoreHistory> scoreHistories = scoreHistoryService.findAllByClubId(club.getId()); | ||
return ClubScoreHistoryListQuery.of(club, scoreHistories); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...in/java/ddingdong/ddingdongBE/domain/scorehistory/service/GeneralScoreHistoryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package ddingdong.ddingdongBE.domain.scorehistory.service; | ||
|
||
import ddingdong.ddingdongBE.domain.scorehistory.entity.ScoreHistory; | ||
import ddingdong.ddingdongBE.domain.scorehistory.repository.ScoreHistoryRepository; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class GeneralScoreHistoryService implements ScoreHistoryService { | ||
|
||
private final ScoreHistoryRepository scoreHistoryRepository; | ||
|
||
@Override | ||
@Transactional | ||
public Long create(ScoreHistory scoreHistory) { | ||
ScoreHistory savedScoreHistory = scoreHistoryRepository.save(scoreHistory); | ||
return savedScoreHistory.getId(); | ||
} | ||
|
||
@Override | ||
public List<ScoreHistory> findAllByClubId(Long clubId) { | ||
return scoreHistoryRepository.findByClubId(clubId); | ||
} | ||
} |
39 changes: 3 additions & 36 deletions
39
src/main/java/ddingdong/ddingdongBE/domain/scorehistory/service/ScoreHistoryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,12 @@ | ||
package ddingdong.ddingdongBE.domain.scorehistory.service; | ||
|
||
import ddingdong.ddingdongBE.domain.club.entity.Club; | ||
import ddingdong.ddingdongBE.domain.club.service.ClubService; | ||
import ddingdong.ddingdongBE.domain.scorehistory.controller.dto.request.CreateScoreHistoryRequest; | ||
import ddingdong.ddingdongBE.domain.scorehistory.entity.ScoreHistory; | ||
import ddingdong.ddingdongBE.domain.scorehistory.repository.ScoreHistoryRepository; | ||
import java.math.BigDecimal; | ||
import java.math.RoundingMode; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class ScoreHistoryService { | ||
public interface ScoreHistoryService { | ||
|
||
private final ScoreHistoryRepository scoreHistoryRepository; | ||
private final ClubService clubService; | ||
Long create(ScoreHistory scoreHistory); | ||
|
||
public void create(final Long clubId, CreateScoreHistoryRequest createScoreHistoryRequest) { | ||
Club club = clubService.getByClubId(clubId); | ||
List<ScoreHistory> findAllByClubId(Long clubId); | ||
|
||
BigDecimal score = roundToThirdPoint(createScoreHistoryRequest.amount()); | ||
clubService.updateClubScore(clubId, score); | ||
scoreHistoryRepository.save(createScoreHistoryRequest.toEntity(club)); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public List<ScoreHistory> findAllByClubId(final Long clubId) { | ||
return scoreHistoryRepository.findByClubId(clubId); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public List<ScoreHistory> findAllByUserId(final Long userId) { | ||
Club club = clubService.getByUserId(userId); | ||
return scoreHistoryRepository.findByClubId(club.getId()); | ||
} | ||
|
||
private BigDecimal roundToThirdPoint(BigDecimal value) { | ||
return value.setScale(3, RoundingMode.DOWN); | ||
} | ||
} |
Oops, something went wrong.