diff --git a/src/main/java/com/gapple/weeingback/domain/boardgame/domain/Boardgame.java b/src/main/java/com/gapple/weeingback/domain/boardgame/domain/Boardgame.java index 825ee96..9643b39 100644 --- a/src/main/java/com/gapple/weeingback/domain/boardgame/domain/Boardgame.java +++ b/src/main/java/com/gapple/weeingback/domain/boardgame/domain/Boardgame.java @@ -1,12 +1,10 @@ package com.gapple.weeingback.domain.boardgame.domain; import com.gapple.weeingback.domain.member.entity.Member; -import com.gapple.weeingback.domain.member.entity.NumberNameWithId; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.GenericGenerator; -import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -22,13 +20,13 @@ public class Boardgame { @GenericGenerator(name="uuid2", strategy = "uuid2") private UUID id; - @ManyToOne + @ManyToOne(fetch = FetchType.EAGER) private Member creator; @Column(nullable = false) private Long maxOf; - @OneToMany + @OneToMany(fetch = FetchType.EAGER) private List members; public void addMember(Member member){ diff --git a/src/main/java/com/gapple/weeingback/domain/member/entity/NumberNameWithId.java b/src/main/java/com/gapple/weeingback/domain/boardgame/domain/BoardgameMemberDto.java similarity index 69% rename from src/main/java/com/gapple/weeingback/domain/member/entity/NumberNameWithId.java rename to src/main/java/com/gapple/weeingback/domain/boardgame/domain/BoardgameMemberDto.java index 94caa56..65dca1a 100644 --- a/src/main/java/com/gapple/weeingback/domain/member/entity/NumberNameWithId.java +++ b/src/main/java/com/gapple/weeingback/domain/boardgame/domain/BoardgameMemberDto.java @@ -1,4 +1,4 @@ -package com.gapple.weeingback.domain.member.entity; +package com.gapple.weeingback.domain.boardgame.domain; import lombok.*; @@ -6,7 +6,7 @@ @Getter @Setter @NoArgsConstructor @AllArgsConstructor -public class NumberNameWithId { +public class BoardgameMemberDto { private Long grade; private Long classroom; diff --git a/src/main/java/com/gapple/weeingback/domain/boardgame/domain/ToBoardgameDto.java b/src/main/java/com/gapple/weeingback/domain/boardgame/domain/ToBoardgameDto.java index e818b5f..057d84c 100644 --- a/src/main/java/com/gapple/weeingback/domain/boardgame/domain/ToBoardgameDto.java +++ b/src/main/java/com/gapple/weeingback/domain/boardgame/domain/ToBoardgameDto.java @@ -1,6 +1,5 @@ package com.gapple.weeingback.domain.boardgame.domain; -import com.gapple.weeingback.domain.member.entity.NumberNameWithId; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; @@ -13,6 +12,6 @@ public class ToBoardgameDto { private String id; private Long maxOf; - private NumberNameWithId creator; - private List players; + private BoardgameMemberDto creator; + private List players; } diff --git a/src/main/java/com/gapple/weeingback/domain/boardgame/service/implmentation/BoardgameServiceImpl.java b/src/main/java/com/gapple/weeingback/domain/boardgame/service/implmentation/BoardgameServiceImpl.java index dcebfc9..ff92eff 100644 --- a/src/main/java/com/gapple/weeingback/domain/boardgame/service/implmentation/BoardgameServiceImpl.java +++ b/src/main/java/com/gapple/weeingback/domain/boardgame/service/implmentation/BoardgameServiceImpl.java @@ -1,12 +1,12 @@ package com.gapple.weeingback.domain.boardgame.service.implmentation; import com.gapple.weeingback.domain.boardgame.domain.Boardgame; +import com.gapple.weeingback.domain.boardgame.domain.BoardgameMemberDto; import com.gapple.weeingback.domain.boardgame.domain.ToBoardgameDto; import com.gapple.weeingback.domain.boardgame.domain.dto.response.BoardgameShowResponse; import com.gapple.weeingback.domain.boardgame.repository.BoardgameRepository; import com.gapple.weeingback.domain.boardgame.service.BoardgameService; import com.gapple.weeingback.domain.member.entity.Member; -import com.gapple.weeingback.domain.member.entity.NumberNameWithId; import com.gapple.weeingback.domain.member.repository.MemberRepository; import com.gapple.weeingback.global.exception.BoardgameNotFoundException; import com.gapple.weeingback.global.exception.MemberNotFoundException; @@ -14,7 +14,6 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; - import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -39,18 +38,6 @@ public void submitBoardgame(Long maxOf) { boardgameRepository.save(boardgame); } - @Override - public BoardgameShowResponse showAllBoardgame() { - List boardgames = boardgameRepository.findAll(); - List boardgameDtos = new ArrayList<>(); - boardgames.forEach(boardgame -> - boardgameDtos.add(toDto(boardgame)) - ); - - - - return new BoardgameShowResponse(boardgameDtos); - } @Override @Transactional @@ -69,44 +56,30 @@ public void joinBoardgame(UUID boardgameId) { public void doneBoardgame(UUID boardgameId) { boardgameRepository.deleteById(boardgameId); } + @Override + public BoardgameShowResponse showAllBoardgame() { + List boardgames = boardgameRepository.findAll(); + List boardgameDtos = new ArrayList<>(); + boardgames.forEach(boardgame -> + boardgameDtos.add(toDto(boardgame)) + ); - public ToBoardgameDto toDto(Boardgame boardgame){ - List players = new ArrayList<>(); - List members = boardgame.getMembers(); - Member creator = boardgame.getCreator(); + return new BoardgameShowResponse(boardgameDtos); + } - members.forEach(m -> { - players.add(new NumberNameWithId( - m.getGrade(), - m.getClassroom(), - m.getNumber(), - m.getName(), - m.getId().toString() - )); - }); + public ToBoardgameDto toDto(Boardgame boardgame){ + List players = new ArrayList<>(); boardgame.getMembers().forEach(member -> - players.add(new NumberNameWithId( - member.getGrade(), - member.getClassroom(), - member.getNumber(), - member.getName(), - member.getId().toString() - )) + players.add( + Member.toBoardgameMemberDto(member) + ) ); return new ToBoardgameDto( boardgame.getId().toString(), boardgame.getMaxOf(), - new NumberNameWithId( - creator.getGrade(), - creator.getClassroom(), - creator.getNumber(), - creator.getName(), - creator.getId().toString() - ), + Member.toBoardgameMemberDto(boardgame.getCreator()), players); } -} - - +} \ No newline at end of file diff --git a/src/main/java/com/gapple/weeingback/domain/member/entity/Member.java b/src/main/java/com/gapple/weeingback/domain/member/entity/Member.java index 49cdc9f..d719fa3 100644 --- a/src/main/java/com/gapple/weeingback/domain/member/entity/Member.java +++ b/src/main/java/com/gapple/weeingback/domain/member/entity/Member.java @@ -1,6 +1,7 @@ package com.gapple.weeingback.domain.member.entity; import com.gapple.weeingback.domain.boardgame.domain.Boardgame; +import com.gapple.weeingback.domain.boardgame.domain.BoardgameMemberDto; import com.gapple.weeingback.domain.consulting.entity.Consulting; import com.gapple.weeingback.domain.diary.entity.Diary; @@ -45,11 +46,11 @@ public class Member implements GrantedAuthority { @Column(columnDefinition = "VARCHAR(80)", nullable = false) private String role; - @OneToMany + @OneToMany(fetch = FetchType.EAGER) @JoinColumn(name = "consulting_id") private List consulting; - @OneToMany + @OneToMany(fetch = FetchType.EAGER) @JoinColumn(name = "diary_id") private List diaries; @@ -66,4 +67,14 @@ public void addDiary(Diary diary){ public String getAuthority() { return role; } + + public static BoardgameMemberDto toBoardgameMemberDto(Member member){ + return new BoardgameMemberDto( + member.getGrade(), + member.getClassroom(), + member.getNumber(), + member.getName(), + member.getId().toString() + ); + } }