Skip to content

Commit

Permalink
[DDING-000] ClubMember 도메인 패키지 분리 (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
5uhwann authored Oct 10, 2024
1 parent 9d9f8f5 commit 10af9cd
Show file tree
Hide file tree
Showing 20 changed files with 122 additions and 193 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class QClub extends EntityPathBase<Club> {

public final StringPath category = createString("category");

public final ListPath<ClubMember, QClubMember> clubMembers = this.<ClubMember, QClubMember>createList("clubMembers", ClubMember.class, QClubMember.class, PathInits.DIRECT2);
public final ListPath<ddingdong.ddingdongBE.domain.clubmember.entity.ClubMember, ddingdong.ddingdongBE.domain.clubmember.entity.QClubMember> clubMembers = this.<ddingdong.ddingdongBE.domain.clubmember.entity.ClubMember, ddingdong.ddingdongBE.domain.clubmember.entity.QClubMember>createList("clubMembers", ddingdong.ddingdongBE.domain.clubmember.entity.ClubMember.class, ddingdong.ddingdongBE.domain.clubmember.entity.QClubMember.class, PathInits.DIRECT2);

public final StringPath content = createString("content");

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import ddingdong.ddingdongBE.domain.club.controller.dto.request.UpdateClubRequest;
import ddingdong.ddingdongBE.domain.club.controller.dto.response.DetailClubResponse;
import ddingdong.ddingdongBE.domain.club.service.ClubService;
import ddingdong.ddingdongBE.domain.club.service.FacadeClubMemberService;
import ddingdong.ddingdongBE.domain.clubmember.service.FacadeClubMemberService;
import ddingdong.ddingdongBE.domain.clubmember.service.dto.command.UpdateClubMemberListCommand;
import ddingdong.ddingdongBE.domain.user.entity.User;
import ddingdong.ddingdongBE.file.service.FileService;
import java.net.URLEncoder;
Expand Down Expand Up @@ -78,12 +79,15 @@ public void updateClub(@AuthenticationPrincipal PrincipalDetails principalDetail
@Override
public void updateClubMemberList(PrincipalDetails principalDetails, MultipartFile clubMemberListFile) {
User user = principalDetails.getUser();
facadeClubMemberService.updateMemberList(user.getId(), clubMemberListFile);
UpdateClubMemberListCommand command = UpdateClubMemberListCommand.builder()
.userId(user.getId())
.clubMemberListFile(clubMemberListFile)
.build();
facadeClubMemberService.updateMemberList(command);
}

@Override
public void updateClubMembers(Long clubMemberId,
UpdateClubMemberRequest request) {
facadeClubMemberService.update(clubMemberId, request.toCommand());
public void updateClubMembers(Long clubMemberId, UpdateClubMemberRequest request) {
facadeClubMemberService.update(request.toCommand(clubMemberId));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ddingdong.ddingdongBE.domain.club.controller.dto.request;

import ddingdong.ddingdongBE.domain.club.entity.Position;
import ddingdong.ddingdongBE.domain.club.service.dto.UpdateClubMemberCommand;
import ddingdong.ddingdongBE.domain.clubmember.service.dto.command.UpdateClubMemberCommand;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;
Expand Down Expand Up @@ -37,8 +37,9 @@ public record UpdateClubMemberRequest(
String department
) {

public UpdateClubMemberCommand toCommand() {
public UpdateClubMemberCommand toCommand(Long clubMemberId) {
return UpdateClubMemberCommand.builder()
.clubMemberId(clubMemberId)
.name(name)
.studentNumber(studentNumber)
.phoneNumber(phoneNumber)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ddingdong.ddingdongBE.domain.club.controller.dto.response;

import ddingdong.ddingdongBE.domain.club.entity.ClubMember;
import ddingdong.ddingdongBE.domain.clubmember.entity.ClubMember;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ddingdong.ddingdongBE.common.BaseEntity;
import ddingdong.ddingdongBE.domain.club.controller.dto.request.UpdateClubRequest;
import ddingdong.ddingdongBE.domain.clubmember.entity.ClubMember;
import ddingdong.ddingdongBE.domain.scorehistory.entity.Score;
import ddingdong.ddingdongBE.domain.user.entity.User;
import jakarta.persistence.Column;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ddingdong.ddingdongBE.domain.club.entity;
package ddingdong.ddingdongBE.domain.clubmember.entity;

import ddingdong.ddingdongBE.common.BaseEntity;
import ddingdong.ddingdongBE.domain.club.entity.Club;
import ddingdong.ddingdongBE.domain.club.entity.Position;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package ddingdong.ddingdongBE.domain.clubmember.repository;

import ddingdong.ddingdongBE.domain.clubmember.entity.ClubMember;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ClubMemberRepository extends JpaRepository<ClubMember, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ddingdong.ddingdongBE.domain.clubmember.service;

import ddingdong.ddingdongBE.domain.clubmember.entity.ClubMember;
import java.util.List;

public interface ClubMemberService {

ClubMember getById(Long clubMemberId);

void saveAll(List<ClubMember> clubMembers);

void deleteAll(List<ClubMember> clubMembers);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ddingdong.ddingdongBE.domain.clubmember.service;

import ddingdong.ddingdongBE.domain.clubmember.service.dto.command.UpdateClubMemberCommand;
import ddingdong.ddingdongBE.domain.clubmember.service.dto.command.UpdateClubMemberListCommand;

public interface FacadeClubMemberService {

byte[] getClubMemberListFile(Long userId);

void updateMemberList(UpdateClubMemberListCommand command);

void update(UpdateClubMemberCommand updateClubMemberCommand);

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package ddingdong.ddingdongBE.domain.club.service;
package ddingdong.ddingdongBE.domain.clubmember.service;

import ddingdong.ddingdongBE.domain.club.entity.Club;
import ddingdong.ddingdongBE.domain.club.entity.ClubMember;
import ddingdong.ddingdongBE.domain.club.service.dto.UpdateClubMemberCommand;
import ddingdong.ddingdongBE.domain.clubmember.entity.ClubMember;
import ddingdong.ddingdongBE.domain.club.service.ClubService;
import ddingdong.ddingdongBE.domain.clubmember.service.dto.command.UpdateClubMemberCommand;
import ddingdong.ddingdongBE.domain.clubmember.service.dto.command.UpdateClubMemberListCommand;
import ddingdong.ddingdongBE.file.service.ExcelFileService;
import java.util.HashSet;
import java.util.List;
Expand All @@ -11,26 +13,28 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

@Service
@Transactional
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class FacadeClubMemberService {
public class FacadeClubMemberServiceImpl implements FacadeClubMemberService {

private final ClubService clubService;
private final ClubMemberService clubMemberService;
private final GeneralClubMemberService generalClubMemberService;
private final ExcelFileService excelFileService;

@Transactional(readOnly = true)
@Override
public byte[] getClubMemberListFile(Long userId) {
Club club = clubService.getByUserId(userId);
return excelFileService.generateClubMemberListFile(club.getClubMembers());
}

public void updateMemberList(Long userId, MultipartFile clubMemberListFile) {
Club club = clubService.getByUserId(userId);
List<ClubMember> updatedClubMembers = excelFileService.extractClubMembersInformation(club, clubMemberListFile);
@Override
@Transactional
public void updateMemberList(UpdateClubMemberListCommand command) {
Club club = clubService.getByUserId(command.userId());
List<ClubMember> updatedClubMembers =
excelFileService.extractClubMembersInformation(club, command.clubMemberListFile());
List<ClubMember> clubMembers = club.getClubMembers();
Set<Long> updatedMemberIds = updatedClubMembers.stream()
.map(ClubMember::getId)
Expand All @@ -39,13 +43,15 @@ public void updateMemberList(Long userId, MultipartFile clubMemberListFile) {
.map(ClubMember::getId)
.collect(Collectors.toSet());

clubMemberService.saveAll(filterCreatedMembers(updatedClubMembers, updatedMemberIds, currentMemberIds));
clubMemberService.deleteAll(filterDeletedMembers(clubMembers, updatedMemberIds, currentMemberIds));
generalClubMemberService.saveAll(filterCreatedMembers(updatedClubMembers, updatedMemberIds, currentMemberIds));
generalClubMemberService.deleteAll(filterDeletedMembers(clubMembers, updatedMemberIds, currentMemberIds));
}

public void update(Long clubMemberId, UpdateClubMemberCommand updateClubMemberCommand) {
ClubMember clubMember = clubMemberService.getById(clubMemberId);
clubMember.updateInformation(updateClubMemberCommand.toEntity());
@Override
@Transactional
public void update(UpdateClubMemberCommand command) {
ClubMember clubMember = generalClubMemberService.getById(command.clubMemberId());
clubMember.updateInformation(command.toEntity());
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
package ddingdong.ddingdongBE.domain.club.service;
package ddingdong.ddingdongBE.domain.clubmember.service;

import ddingdong.ddingdongBE.common.exception.PersistenceException.ResourceNotFound;
import ddingdong.ddingdongBE.domain.club.entity.ClubMember;
import ddingdong.ddingdongBE.domain.club.repository.ClubMemberRepository;
import ddingdong.ddingdongBE.domain.clubmember.entity.ClubMember;
import ddingdong.ddingdongBE.domain.clubmember.repository.ClubMemberRepository;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class ClubMemberService {
public class GeneralClubMemberService implements ClubMemberService {

private final ClubMemberRepository clubMemberRepository;

@Override
public ClubMember getById(Long clubMemberId) {
return clubMemberRepository.findById(clubMemberId)
.orElseThrow(() -> new ResourceNotFound("존재하지 않는 동아리원입니다."));
}

@Override
@Transactional
public void saveAll(List<ClubMember> clubMembers) {
clubMemberRepository.saveAll(clubMembers);
}

@Override
@Transactional
public void deleteAll(List<ClubMember> clubMembers) {
clubMemberRepository.deleteAllInBatch(clubMembers);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package ddingdong.ddingdongBE.domain.club.service.dto;
package ddingdong.ddingdongBE.domain.clubmember.service.dto.command;

import ddingdong.ddingdongBE.domain.club.entity.ClubMember;
import ddingdong.ddingdongBE.domain.clubmember.entity.ClubMember;
import ddingdong.ddingdongBE.domain.club.entity.Position;
import lombok.Builder;

@Builder
public record UpdateClubMemberCommand(
Long clubMemberId,
String name,
String studentNumber,
String phoneNumber,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ddingdong.ddingdongBE.domain.clubmember.service.dto.command;

import lombok.Builder;
import org.springframework.web.multipart.MultipartFile;

@Builder
public record UpdateClubMemberListCommand(
Long userId,
MultipartFile clubMemberListFile
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import ddingdong.ddingdongBE.common.exception.ParsingExcelFileException.ExcelIO;
import ddingdong.ddingdongBE.common.exception.ParsingExcelFileException.NonExcelFile;
import ddingdong.ddingdongBE.domain.club.entity.Club;
import ddingdong.ddingdongBE.domain.club.entity.ClubMember;
import ddingdong.ddingdongBE.domain.clubmember.entity.ClubMember;
import ddingdong.ddingdongBE.file.service.dto.ExcelClubMemberDto;
import java.awt.Color;
import java.io.ByteArrayOutputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import ddingdong.ddingdongBE.common.exception.InvalidatedMappingException.InvalidatedEnumValue;
import ddingdong.ddingdongBE.domain.club.entity.Club;
import ddingdong.ddingdongBE.domain.club.entity.ClubMember;
import ddingdong.ddingdongBE.domain.clubmember.entity.ClubMember;
import ddingdong.ddingdongBE.domain.club.entity.Position;
import java.util.Arrays;
import java.util.Iterator;
Expand Down
Loading

0 comments on commit 10af9cd

Please sign in to comment.