-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[BE/FEAT] 프로그램 참여 관련 구현
- Loading branch information
Showing
28 changed files
with
358 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...rc/main/java/com/blackcompany/eeos/attend/application/dto/ChangeAttendStatusResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.blackcompany.eeos.attend.application.dto; | ||
|
||
import com.blackcompany.eeos.common.support.dto.AbstractResponseDto; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder(toBuilder = true) | ||
public class ChangeAttendStatusResponse implements AbstractResponseDto { | ||
private String name; | ||
private String attendStatus; | ||
} |
16 changes: 16 additions & 0 deletions
16
...src/main/java/com/blackcompany/eeos/attend/application/dto/QueryAttendStatusResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.blackcompany.eeos.attend.application.dto; | ||
|
||
import com.blackcompany.eeos.common.support.dto.AbstractResponseDto; | ||
import java.util.List; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder(toBuilder = true) | ||
public class QueryAttendStatusResponse implements AbstractResponseDto { | ||
private List<AttendInfoResponse> members; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...a/com/blackcompany/eeos/attend/application/dto/converter/ChangeAttendStatusConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.blackcompany.eeos.attend.application.dto.converter; | ||
|
||
import com.blackcompany.eeos.attend.application.dto.ChangeAttendStatusResponse; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ChangeAttendStatusConverter { | ||
public ChangeAttendStatusResponse from(String name, String attendStatus) { | ||
return ChangeAttendStatusResponse.builder().name(name).attendStatus(attendStatus).build(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...lackcompany/eeos/attend/application/dto/converter/QueryAttendStatusResponseConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.blackcompany.eeos.attend.application.dto.converter; | ||
|
||
import com.blackcompany.eeos.attend.application.dto.AttendInfoResponse; | ||
import com.blackcompany.eeos.attend.application.dto.QueryAttendStatusResponse; | ||
import java.util.List; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class QueryAttendStatusResponseConverter { | ||
public QueryAttendStatusResponse of(List<AttendInfoResponse> response) { | ||
return QueryAttendStatusResponse.builder().members(response).build(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...in/java/com/blackcompany/eeos/attend/application/exception/DeniedSaveAttendException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.blackcompany.eeos.attend.application.exception; | ||
|
||
import com.blackcompany.eeos.common.exception.BusinessException; | ||
import org.springframework.http.HttpStatus; | ||
|
||
/** 해당 프로그램의 참석 대상자가 아닌데 참석 정보를 입력하려고 할 때 발생하는 예외 */ | ||
public class DeniedSaveAttendException extends BusinessException { | ||
private static final String FAIL_CODE = "2005"; | ||
|
||
public DeniedSaveAttendException() { | ||
super(FAIL_CODE, HttpStatus.NOT_FOUND); | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return String.format(" 프로그램의 참석 대상자가 아닙니다."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 0 additions & 80 deletions
80
BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/model/AttendService.java
This file was deleted.
Oops, something went wrong.
132 changes: 132 additions & 0 deletions
132
BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/service/AttendService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package com.blackcompany.eeos.attend.application.service; | ||
|
||
import com.blackcompany.eeos.attend.application.dto.AttendInfoResponse; | ||
import com.blackcompany.eeos.attend.application.dto.ChangeAttendStatusRequest; | ||
import com.blackcompany.eeos.attend.application.dto.ChangeAttendStatusResponse; | ||
import com.blackcompany.eeos.attend.application.dto.QueryAttendStatusResponse; | ||
import com.blackcompany.eeos.attend.application.dto.converter.AttendInfoConverter; | ||
import com.blackcompany.eeos.attend.application.dto.converter.ChangeAttendStatusConverter; | ||
import com.blackcompany.eeos.attend.application.dto.converter.QueryAttendStatusResponseConverter; | ||
import com.blackcompany.eeos.attend.application.exception.NotFoundAttendException; | ||
import com.blackcompany.eeos.attend.application.model.AttendModel; | ||
import com.blackcompany.eeos.attend.application.model.AttendStatus; | ||
import com.blackcompany.eeos.attend.application.model.converter.AttendEntityConverter; | ||
import com.blackcompany.eeos.attend.application.usecase.ChangeAttendStatusUsecase; | ||
import com.blackcompany.eeos.attend.application.usecase.GetAttendStatusUsecase; | ||
import com.blackcompany.eeos.attend.application.usecase.GetAttendantInfoUsecase; | ||
import com.blackcompany.eeos.attend.persistence.AttendEntity; | ||
import com.blackcompany.eeos.attend.persistence.AttendRepository; | ||
import com.blackcompany.eeos.member.application.model.MemberModel; | ||
import com.blackcompany.eeos.member.application.model.converter.MemberEntityConverter; | ||
import com.blackcompany.eeos.member.application.service.QueryMemberService; | ||
import com.blackcompany.eeos.member.persistence.MemberEntity; | ||
import com.blackcompany.eeos.member.persistence.MemberRepository; | ||
import com.blackcompany.eeos.program.application.service.ProgramValidService; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class AttendService | ||
implements GetAttendantInfoUsecase, ChangeAttendStatusUsecase, GetAttendStatusUsecase { | ||
|
||
private final AttendRepository attendRepository; | ||
|
||
private final MemberRepository memberRepository; | ||
private final ProgramValidService programValidService; | ||
private final AttendInfoConverter infoConverter; | ||
private final AttendEntityConverter attendEntityConverter; | ||
private final QueryMemberService queryMemberService; | ||
private final ChangeAttendStatusConverter changeAttendStatusConverter; | ||
private final MemberEntityConverter memberEntityConverter; | ||
private final AttendInfoConverter attendInfoConverter; | ||
private final QueryAttendStatusResponseConverter attendStatusResponseConverter; | ||
|
||
@Override | ||
public List<AttendInfoResponse> findAttendInfo(final Long programId) { | ||
programValidService.validate(programId); | ||
|
||
return memberRepository.findMembersByProgramId(programId).stream() | ||
.map(member -> infoConverter.from(member, getAttendStatus(member.getId(), programId))) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public QueryAttendStatusResponse findAttendInfo(final Long programId, final String status) { | ||
programValidService.validate(programId); | ||
|
||
List<AttendEntity> attendsByProgram = findAttend(programId, status); | ||
List<MemberModel> members = | ||
findAMembers(programId, status).stream() | ||
.map(memberEntityConverter::from) | ||
.collect(Collectors.toList()); | ||
|
||
List<AttendInfoResponse> response = | ||
members.stream() | ||
.map(member -> combine(member, attendsByProgram, programId)) | ||
.collect(Collectors.toList()); | ||
|
||
return attendStatusResponseConverter.of(response); | ||
} | ||
|
||
@Transactional | ||
@Override | ||
public ChangeAttendStatusResponse changeStatus( | ||
final Long memberId, final ChangeAttendStatusRequest request, final Long programId) { | ||
AttendModel model = attendEntityConverter.from(getAttend(memberId, programId)); | ||
|
||
model.changeStatus(request.getBeforeAttendStatus(), request.getAfterAttendStatus()); | ||
AttendEntity updated = attendRepository.save(attendEntityConverter.toEntity(model)); | ||
|
||
String name = queryMemberService.getName(memberId); | ||
return changeAttendStatusConverter.from(name, updated.getStatus().getStatus()); | ||
} | ||
|
||
@Override | ||
public ChangeAttendStatusResponse getStatus(Long memberId, Long programId) { | ||
AttendModel model = attendEntityConverter.from(getAttend(memberId, programId)); | ||
String name = queryMemberService.getName(memberId); | ||
|
||
return changeAttendStatusConverter.from(name, model.getStatus().getStatus()); | ||
} | ||
|
||
private AttendEntity getAttend(final Long memberId, final Long programId) { | ||
return attendRepository | ||
.findByProgramIdAndMemberId(programId, memberId) | ||
.orElseThrow(() -> new NotFoundAttendException(programId)); | ||
} | ||
|
||
private AttendStatus getAttendStatus(final Long memberId, final Long programId) { | ||
return getAttend(memberId, programId).getStatus(); | ||
} | ||
|
||
private AttendInfoResponse combine( | ||
MemberModel member, List<AttendEntity> attends, Long programId) { | ||
AttendEntity attendEntity = | ||
attends.stream() | ||
.filter(attend -> member.validateSame(attend.getMemberId())) | ||
.findAny() | ||
.orElseThrow(() -> new NotFoundAttendException(programId)); | ||
|
||
return attendInfoConverter.from(member, attendEntity.getStatus()); | ||
} | ||
|
||
private List<MemberEntity> findAMembers(final Long programId, final String status) { | ||
List<Long> memberIds = | ||
findAttend(programId, status).stream() | ||
.map(AttendEntity::getMemberId) | ||
.collect(Collectors.toList()); | ||
|
||
return memberRepository.findUsersByIds(memberIds); | ||
} | ||
|
||
private List<AttendEntity> findAttend(final Long programId, final String status) { | ||
AttendStatus attendStatus = AttendStatus.findByAttendStatus(status); | ||
|
||
return attendRepository.findAllByProgramIdAndStatus(programId, attendStatus); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
BE/eeos/src/main/java/com/blackcompany/eeos/attend/application/service/CandidateService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
package com.blackcompany.eeos.attend.application.service; | ||
|
||
import com.blackcompany.eeos.program.application.dto.ChangeAttendStatusRequest; | ||
import com.blackcompany.eeos.program.application.dto.ChangeAllAttendStatusRequest; | ||
import com.blackcompany.eeos.program.application.dto.ProgramMembers; | ||
import java.util.List; | ||
|
||
/** 관련 있는 대상자를 선택한다. */ | ||
public interface CandidateService { | ||
void saveCandidate(final Long programId, final List<ProgramMembers> members); | ||
|
||
void updateCandidate(final Long programId, final List<ChangeAttendStatusRequest> requests); | ||
void updateCandidate(final Long programId, final List<ChangeAllAttendStatusRequest> requests); | ||
} |
Oops, something went wrong.