Skip to content

Commit

Permalink
Merge pull request #386 from mash-up-kr/feature/add-member-gen
Browse files Browse the repository at this point in the history
add transfer api
  • Loading branch information
kh0712 authored Dec 16, 2023
2 parents 667b2d1 + 98ba4ec commit 68bcee6
Show file tree
Hide file tree
Showing 21 changed files with 286 additions and 116 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ out/

### VS Code ###
.vscode/
/mashup-domain/src/main/generated/
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
package kr.mashup.branding.facade.member;

import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

import kr.mashup.branding.domain.member.MemberGeneration;
import kr.mashup.branding.domain.member.MemberStatus;
import kr.mashup.branding.domain.member.*;
import kr.mashup.branding.service.member.CurrentMemberStatusCalculationService;
import kr.mashup.branding.ui.member.request.MemberDropOutRequest;
import kr.mashup.branding.ui.member.request.MemberStatusUpdateRequest;
import kr.mashup.branding.ui.member.request.MemberTransferRequest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import kr.mashup.branding.domain.generation.Generation;
import kr.mashup.branding.domain.member.Member;
import kr.mashup.branding.domain.member.Platform;
import kr.mashup.branding.repository.member.MemberRepositoryCustomImpl.MemberScoreQueryResult;
import kr.mashup.branding.service.generation.GenerationService;
import kr.mashup.branding.service.member.MemberService;
Expand All @@ -38,27 +35,43 @@ public class MemberFacadeService {
private final MemberService memberService;
private final GenerationService generationService;
private final ScoreHistoryService scoreHistoryService;
private final CurrentMemberStatusCalculationService currentMemberStatusCalculationService;

@Transactional(readOnly = true)
public Page<MemberResponse> getAllNotRun(Integer generationNumber, Platform platform, String searchName, Pageable pageable) {
public Page<MemberResponse> getAll(
final Integer generationNumber,
final Platform platform,
final String searchName,
final Pageable pageable
) {

final Generation generation = generationService.getByNumberOrThrow(generationNumber);

final Page<MemberScoreQueryResult> queryResults
= memberService.getActiveAllByGeneration(generation, platform, searchName, pageable);

final List<MemberResponse> response = new ArrayList<>();
final List<Member> members =
queryResults
.getContent()
.stream()
.map(MemberScoreQueryResult::getMember)
.collect(Collectors.toList());
final Map<Long, CurrentMemberStatus> currentStatus =
currentMemberStatusCalculationService.getCurrentStatus(generation, members);

for (final MemberScoreQueryResult result : queryResults) {

final Member member = result.getMember();
final MemberGeneration memberGeneration = result.getMemberGeneration();

final MemberResponse memberResponse = MemberResponse.of(member.getId(),
final MemberResponse memberResponse = MemberResponse.of(
member.getId(),
member.getName(),
member.getIdentification(),
result.getPlatform().name(),
memberGeneration.getPlatform().name(),
result.getScore(),
member.getStatus());
currentStatus.get(member.getId()));

response.add(memberResponse);
}
Expand Down Expand Up @@ -123,7 +136,25 @@ public void updateMemberStatus(Integer generationNumber, MemberStatusUpdateReque

final List<Long> memberIds = memberStatusUpdateRequest.getMemberIds();

List<Member> members = memberIds.stream().map(memberService::findMemberById).collect(Collectors.toList());
final List<Member> members = memberIds.stream().map(memberService::findMemberById).collect(Collectors.toList());
memberService.updateStatus(memberStatus, generation, memberStatusUpdateRequest.getPlatform(), members);
}

@Transactional
public void transfer(final MemberTransferRequest request) {

final Generation oldGeneration = generationService.getByNumberOrThrow(request.getOldGenerationNumber());
final Generation newGeneration = generationService.getByNumberOrThrow(request.getNewGenerationNumber());
final List<Member> members = memberService.findAllByMemberIds(request.getMemberIds());

memberService.transfer(oldGeneration, newGeneration, members);
}

@Transactional
public void dropOut(final MemberDropOutRequest request) {
final Generation generation = generationService.getByNumberOrThrow(request.getGenerationNumber());
final List<Member> members = memberService.findAllByMemberIds(request.getMemberIds());

memberService.dropOut(generation, members);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
import kr.mashup.branding.domain.adminmember.vo.AdminLoginCommand;
import kr.mashup.branding.domain.adminmember.vo.AdminMemberSignUpCommand;
import kr.mashup.branding.domain.adminmember.vo.AdminMemberVo;
import kr.mashup.branding.ui.adminmember.vo.*;
import kr.mashup.branding.ui.adminmember.vo.AdminDeleteRequest;
import kr.mashup.branding.ui.adminmember.vo.AdminMemberResponse;
import kr.mashup.branding.ui.adminmember.vo.AdminPasswordChangeRequest;
import kr.mashup.branding.ui.adminmember.vo.AdminPasswordResetRequest;
import kr.mashup.branding.ui.adminmember.vo.LoginRequest;
import kr.mashup.branding.ui.adminmember.vo.LoginResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import java.util.List;

import kr.mashup.branding.ui.member.request.MemberDropOutRequest;
import kr.mashup.branding.ui.member.request.MemberStatusUpdateRequest;
import kr.mashup.branding.ui.member.request.MemberTransferRequest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
Expand Down Expand Up @@ -33,7 +35,8 @@ public ApiResponse<List<MemberResponse>> getAllByGeneration(
@RequestParam(value = "platform", required = false) Platform platform,
@RequestParam(value = "searchName", required = false) String searchName
) {
Page<MemberResponse> response = memberFacadeService.getAllNotRun(generationNumber, platform, searchName, pageable);
final Page<MemberResponse> response =
memberFacadeService.getAll(generationNumber, platform, searchName, pageable);

return ApiResponse.success(response);
}
Expand All @@ -43,8 +46,8 @@ public ApiResponse<List<MemberResponse>> getAllByGeneration(
public ApiResponse<MemberDetailResponse> getByID(
@PathVariable Integer generationNumber,
@PathVariable Long memberId
){
MemberDetailResponse response = memberFacadeService.getAttendance(generationNumber, memberId);
) {
final MemberDetailResponse response = memberFacadeService.getAttendance(generationNumber, memberId);

return ApiResponse.success(response);
}
Expand All @@ -60,8 +63,8 @@ public ApiResponse<EmptyResponse> resetPassword(
return ApiResponse.success();
}

@ApiOperation("회원 강제 탈퇴")
@DeleteMapping("/{memberId}")
@ApiOperation("멤버 전체 기수 활동 내역 삭제 및 멤버 삭제")
@DeleteMapping
public ApiResponse<EmptyResponse> withdraw(
@PathVariable Long memberId
) {
Expand All @@ -70,14 +73,34 @@ public ApiResponse<EmptyResponse> withdraw(
return ApiResponse.success();
}

@ApiOperation("특정 기수 중도 하차 처리")
@DeleteMapping("/drop-out")
public ApiResponse<EmptyResponse> dropOut(
@RequestBody MemberDropOutRequest request
) {
memberFacadeService.dropOut(request);

return ApiResponse.success();
}

@ApiOperation("멤버 상태 변경")
@PostMapping("/status/{generationNumber}")
public ApiResponse<EmptyResponse> updateMemberStatus(
@PathVariable Integer generationNumber,
@RequestBody MemberStatusUpdateRequest memberStatusUpdateRequest
@PathVariable Integer generationNumber,
@RequestBody MemberStatusUpdateRequest memberStatusUpdateRequest
) {
memberFacadeService.updateMemberStatus(generationNumber, memberStatusUpdateRequest);

return ApiResponse.success();
}

@ApiOperation("새로운 기수로 멤버 이관")
@PostMapping("/transfer")
public ApiResponse<EmptyResponse> transferMemberToNewGeneration(
@RequestBody MemberTransferRequest memberTransferRequest
){
memberFacadeService.transfer(memberTransferRequest);

return ApiResponse.success();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package kr.mashup.branding.ui.member.request;

import lombok.Getter;

import java.util.List;

@Getter
public class MemberDropOutRequest {

private List<Long> memberIds;
private Integer generationNumber;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package kr.mashup.branding.ui.member.request;

import lombok.Getter;

import java.util.List;

@Getter
public class MemberTransferRequest {
private Integer oldGenerationNumber;
private Integer newGenerationNumber;
private List<Long> memberIds;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kr.mashup.branding.ui.member.response;

import kr.mashup.branding.domain.member.CurrentMemberStatus;
import kr.mashup.branding.domain.member.MemberStatus;
import lombok.Getter;
import lombok.Value;
Expand All @@ -12,5 +13,6 @@ public class MemberResponse {
private String identification;
private String platform;
private Double score;
private MemberStatus memberStatus;
private CurrentMemberStatus memberStatus;

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@Entity
@Getter
@ToString(of = {"adminMemberId", "username", "phoneNumber", "position", "createdAt", "updatedAt"})
@ToString(of = {"adminMemberId", "username", "position", "createdAt", "updatedAt"})
@EqualsAndHashCode(of = "adminMemberId")
@EntityListeners(AuditingEntityListener.class)
public class AdminMember {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public void changeEndedDate(LocalDate newEndedDate){
this.endedAt = newEndedDate;
}

public boolean isInProgress(LocalDate baseTime){
return DateUtil.isInTime(startedAt, baseTime, endedAt);
}

public GenerationStatus getStatus(){

// 현재 일자 기준으로 기수 종료일자가 미래이거나 같은 경우
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package kr.mashup.branding.domain.member;

public enum CurrentMemberStatus {
ACTIVE, END, DROP_OUT, TRANSFER
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class MemberGeneration extends BaseEntity {

private String role;

@Enumerated(EnumType.STRING)
private MemberGenerationStatus status;

public static MemberGeneration of(Member member, Generation generation, Platform platform){
return new MemberGeneration(member, generation, platform);
}
Expand All @@ -40,13 +43,18 @@ private MemberGeneration(Member member, Generation generation, Platform platform
this.member = member;
this.generation = generation;
this.platform = platform;
this.status = MemberGenerationStatus.ACTIVE;
}

public void update(
String projectTeamName,
String role
public void updateProjectInfo(
String projectTeamName,
String role
) {
this.projectTeamName = projectTeamName;
this.role = role;
}

public void dropOut(){
this.status = MemberGenerationStatus.DROP_OUT;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package kr.mashup.branding.domain.member;

import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public enum MemberGenerationStatus {
ACTIVE("정상 활동"),
DROP_OUT("중도 하차");

private final String description;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import kr.mashup.branding.domain.member.MemberGeneration;

import java.util.List;
import java.util.Optional;

public interface MemberGenerationRepositoryCustom {
Optional<MemberGeneration> findByMemberIdAndGenerationNumber(Long memberId, Integer generationNumber);

List<MemberGeneration> findByMemberIdsAndGenerationNumber(List<Long> memberIds, Integer generationNumber);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import kr.mashup.branding.domain.member.MemberGeneration;
import lombok.RequiredArgsConstructor;

import java.util.List;
import java.util.Optional;

import static kr.mashup.branding.domain.generation.QGeneration.generation;
import static kr.mashup.branding.domain.member.QMember.member;
import static kr.mashup.branding.domain.member.QMemberGeneration.memberGeneration;

@RequiredArgsConstructor
Expand All @@ -18,9 +20,20 @@ public Optional<MemberGeneration> findByMemberIdAndGenerationNumber(Long memberI
return Optional.ofNullable(queryFactory
.selectFrom(memberGeneration)
.join(memberGeneration.generation, generation)
.where(memberGeneration.member.id.eq(memberId), generation.number.eq(generationNumber))
.join(memberGeneration.member, member)
.where(member.id.eq(memberId), generation.number.eq(generationNumber))
.fetchOne()
);
}

@Override
public List<MemberGeneration> findByMemberIdsAndGenerationNumber(List<Long> memberIds, Integer generationNumber) {
return queryFactory
.selectFrom(memberGeneration)
.join(memberGeneration.member, member).fetchJoin()
.join(memberGeneration.generation, generation)
.where(member.id.in(memberIds), generation.number.eq(generationNumber))
.fetch();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,4 @@ public interface MemberRepository extends JpaRepository<Member, Long>, MemberRep

Boolean existsByIdentification(String identification);

Page<Member> findAllByStatus(MemberStatus status, Pageable pageable);
}
/**
* Member 연관관계
* one to many : memberGeneration, attendance
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@

public interface MemberRepositoryCustom {

Page<MemberScoreQueryResult> findAllNotRunByGeneration(Generation generation, Platform platform, String searchName, Pageable pageable);

Long countActiveByPlatformAndGeneration(Platform platform, Generation generation);
Page<MemberScoreQueryResult> findAllByGeneration(Generation generation, Platform platform, String searchName, Pageable pageable);

List<Member> findActiveByPlatformAndGeneration(Platform platform, Generation generation);

Expand All @@ -25,7 +23,3 @@ public interface MemberRepositoryCustom {

List<Member> findAllActiveByGeneration(Generation generation);
}
/**
* Member 연관관계
* one to many : memberGeneration, attendance
*/
Loading

0 comments on commit 68bcee6

Please sign in to comment.