Skip to content

Commit

Permalink
[DDING-82] OSIV 비활성화로 인한 지연로딩 에러 수정 (#226)
Browse files Browse the repository at this point in the history
(cherry picked from commit b5c3729)
  • Loading branch information
KoSeonJe committed Jan 25, 2025
1 parent f74144b commit 0b3fc36
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ddingdong.ddingdongBE.domain.club.entity.Club;
import java.util.Optional;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

Expand All @@ -10,4 +11,6 @@ public interface ClubRepository extends JpaRepository<Club, Long> {

Optional<Club> findByUserId(Long userId);

@EntityGraph(attributePaths = {"clubMembers"})
Optional<Club> findEntityGraphByUserId(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@ public interface ClubService {

void delete(Long clubId);



Club getByUserIdWithFetch(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import ddingdong.ddingdongBE.domain.club.repository.ClubRepository;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
@Slf4j
public class GeneralClubService implements ClubService {

private final ClubRepository clubRepository;
Expand All @@ -34,6 +36,11 @@ public Club getByUserId(Long userId) {
.orElseThrow(() -> new ResourceNotFound("Club(userId=" + userId + ")를 찾을 수 없습니다."));
}

@Override
public Club getByUserIdWithFetch(Long userId) {
return clubRepository.findEntityGraphByUserId(userId)
.orElseThrow(() -> new ResourceNotFound("Club(userId=" + userId + ")를 찾을 수 없습니다.")); }

@Override
public List<Club> findAll() {
return clubRepository.findAll();
Expand All @@ -51,5 +58,4 @@ public void delete(Long clubId) {
Club club = getById(clubId);
clubRepository.delete(club);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
import java.util.Set;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = true)
@RequiredArgsConstructor
@Slf4j
public class FacadeCentralClubMemberServiceImpl implements FacadeCentralClubMemberService {

private final ClubService clubService;
Expand All @@ -32,7 +34,7 @@ public byte[] getClubMemberListFile(Long userId) {

@Override
public AllClubMemberInfoQuery getAllMyClubMember(Long userId) {
Club club = clubService.getByUserId(userId);
Club club = clubService.getByUserIdWithFetch(userId);
return AllClubMemberInfoQuery.of(club.getName(), club.getClubMembers());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public record AdminScoreHistoryListResponse(

public static AdminScoreHistoryListResponse from(AdminClubScoreHistoryListQuery query) {
return new AdminScoreHistoryListResponse(
query.club().getScore().getValue(),
query.clubTotalScore(),
query.scoreHistories().stream()
.map(ScoreHistoryResponse::from)
.toList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public record ClubScoreHistoryListResponse(

public static ClubScoreHistoryListResponse from(ClubScoreHistoryListQuery query) {
return new ClubScoreHistoryListResponse(
query.club().getScore().getValue(),
query.clubTotalScore(),
query.scoreHistories().stream()
.map(ScoreHistoryResponse::from)
.toList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public Long create(CreateScoreHistoryCommand command) {
public AdminClubScoreHistoryListQuery findAllByClubId(Long clubId) {
Club club = clubService.getById(clubId);
List<ScoreHistory> scoreHistories = scoreHistoryService.findAllByClubId(clubId);
return AdminClubScoreHistoryListQuery.of(club, scoreHistories);
return AdminClubScoreHistoryListQuery.of(club.getScore().getValue(), scoreHistories);
}

private BigDecimal roundToThirdPoint(BigDecimal value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
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;
Expand All @@ -22,6 +21,6 @@ public class FacadeClubScoreHistoryServiceImpl implements FacadeClubScoreHistory
public ClubScoreHistoryListQuery findMyScoreHistories(Long userId) {
Club club = clubService.getByUserId(userId);
List<ScoreHistory> scoreHistories = scoreHistoryService.findAllByClubId(club.getId());
return ClubScoreHistoryListQuery.of(club, scoreHistories);
return ClubScoreHistoryListQuery.of(club.getScore().getValue(), scoreHistories);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package ddingdong.ddingdongBE.domain.scorehistory.service.dto.query;

import ddingdong.ddingdongBE.domain.club.entity.Club;
import ddingdong.ddingdongBE.domain.scorehistory.entity.ScoreHistory;
import java.math.BigDecimal;
import java.util.List;

public record AdminClubScoreHistoryListQuery(
Club club,
BigDecimal clubTotalScore,
List<ScoreHistory> scoreHistories
) {

public static AdminClubScoreHistoryListQuery of(Club club, List<ScoreHistory> scoreHistories) {
return new AdminClubScoreHistoryListQuery(club, scoreHistories);
public static AdminClubScoreHistoryListQuery of(BigDecimal clubTotalScore, List<ScoreHistory> scoreHistories) {
return new AdminClubScoreHistoryListQuery(clubTotalScore, scoreHistories);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package ddingdong.ddingdongBE.domain.scorehistory.service.dto.query;

import ddingdong.ddingdongBE.domain.club.entity.Club;
import ddingdong.ddingdongBE.domain.scorehistory.entity.ScoreHistory;
import java.math.BigDecimal;
import java.util.List;

public record ClubScoreHistoryListQuery(
Club club,
BigDecimal clubTotalScore,
List<ScoreHistory> scoreHistories
) {

public static ClubScoreHistoryListQuery of(Club club, List<ScoreHistory> scoreHistories) {
return new ClubScoreHistoryListQuery(club, scoreHistories);
public static ClubScoreHistoryListQuery of(BigDecimal clubTotalScore, List<ScoreHistory> scoreHistories) {
return new ClubScoreHistoryListQuery(clubTotalScore, scoreHistories);
}
}

0 comments on commit 0b3fc36

Please sign in to comment.