Skip to content

Commit

Permalink
Merge pull request #67 from GApple-T/database
Browse files Browse the repository at this point in the history
🔀::데이터베이스 개선
  • Loading branch information
enbraining authored Dec 31, 2023
2 parents 53117c3 + 6bbfbb1 commit 6e4a578
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ public class Boardgame {
@Column(nullable = false)
private Long maxOf;

@Column(nullable = false)
private Long joined;

@OneToMany(fetch = FetchType.EAGER)
private List<Member> members;

Expand All @@ -46,7 +43,6 @@ public ToBoardgameDto toDto(Boardgame boardgame){
return new ToBoardgameDto(
boardgame.getId().toString(),
boardgame.getMaxOf(),
boardgame.getJoined(),
new NumberNameWithId(
creator.getNumber() + " " + creator.getName(),
creator.getId().toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
public class ToBoardgameDto {
private String id;
private Long maxOf;
private Long joined;
private NumberNameWithId creator;
private List<NumberNameWithId> players;
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public void submitBoardgame(Long maxOf) {
.joined(0L)
.build();

member.addBoardgame(boardgame);
boardgameRepository.save(boardgame);
}

Expand All @@ -52,26 +51,22 @@ public BoardgameShowResponse showAllBoardgame() {
}

@Override
public void joinBoardgame(UUID id) {
@Transactional
public void joinBoardgame(UUID boardgameId) {
String memberId = SecurityContextHolder.getContext().getAuthentication().getName();
Member member = memberRepository.findMemberById(UUID.fromString(memberId)).orElseThrow(MemberNotFoundException::new);

Boardgame boardgame = boardgameRepository.findBoardgameById(id).orElseThrow(BoardgameNotFoundException::new);
Boardgame boardgame = boardgameRepository.findBoardgameById(boardgameId).orElseThrow(BoardgameNotFoundException::new);

boardgame.addMember(member);

memberRepository.save(member);
boardgameRepository.save(boardgame);
}

@Override
@Transactional
public void doneBoardgame(UUID boardgameId) {
UUID memberId = UUID.fromString(SecurityContextHolder.getContext().getAuthentication().getName());
Member member = memberRepository.findMemberById(memberId).orElseThrow(MemberNotFoundException::new);

member.removeBoardgame(boardgameRepository.findBoardgameById(boardgameId).get());
memberRepository.save(member);

boardgameRepository.deleteById(boardgameId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,11 @@ public class Member implements GrantedAuthority {
@Column(columnDefinition = "VARCHAR(80)", nullable = false)
private String role;

@OneToMany(fetch = FetchType.EAGER)
@OneToMany
@JoinColumn(name = "consulting_id")
private List<Consulting> consulting;

@ManyToMany(fetch = FetchType.EAGER)
@JoinColumn(name = "boardgame_id")
private List<Boardgame> boardgames;

@OneToMany(fetch = FetchType.EAGER)
@OneToMany
@JoinColumn(name = "diary_id")
private List<Diary> diaries;

Expand All @@ -59,13 +55,6 @@ public void addDiary(Diary diary){
this.diaries.add(diary);
}

public void addBoardgame(Boardgame boardgame){
this.boardgames.add(boardgame);
}

public void removeBoardgame(Boardgame boardgame){
this.boardgames.remove(boardgame);
}

@Override
public String getAuthority() {
Expand Down

0 comments on commit 6e4a578

Please sign in to comment.