Skip to content

Commit

Permalink
Merge pull request #192 from kssumin/main
Browse files Browse the repository at this point in the history
[BE/FIX] 로그인 관련 에러 해결
  • Loading branch information
kssumin authored Jan 9, 2024
2 parents 3005ad9 + 33b1826 commit 5ac585b
Show file tree
Hide file tree
Showing 43 changed files with 485 additions and 247 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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 AttendInfoActiveStatusResponse implements AbstractResponseDto {
private Long memberId;
private String name;
private String activeStatus;
private String attendStatus;
}
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 QueryAttendActiveStatusResponse implements AbstractResponseDto {
private List<AttendInfoActiveStatusResponse> members;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.blackcompany.eeos.attend.application.dto.converter;

import com.blackcompany.eeos.attend.application.dto.AttendInfoActiveStatusResponse;
import com.blackcompany.eeos.member.application.model.MemberModel;
import org.springframework.stereotype.Component;

@Component
public class AttendInfoActiveStatusConverter {
public AttendInfoActiveStatusResponse from(
MemberModel source, String attendStatus, String activeStatus) {
return AttendInfoActiveStatusResponse.builder()
.memberId(source.getId())
.name(source.getName())
.activeStatus(activeStatus)
.attendStatus(attendStatus)
.build();
}
}
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.AttendInfoActiveStatusResponse;
import com.blackcompany.eeos.attend.application.dto.QueryAttendActiveStatusResponse;
import java.util.List;
import org.springframework.stereotype.Component;

@Component
public class QueryAttendActiveStatusConverter {
public QueryAttendActiveStatusResponse of(List<AttendInfoActiveStatusResponse> response) {
return QueryAttendActiveStatusResponse.builder().members(response).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ public class AttendModel implements AbstractModel {
private Long programId;
private AttendStatus status;

public void changeStatus(String beforeStatus, String afterStatus) {
public AttendModel changeStatus(String beforeStatus, String afterStatus) {
validateChange(beforeStatus);
this.status = AttendStatus.find(afterStatus);

return this;
}

public String getStatus() {
Expand All @@ -34,17 +36,17 @@ public static AttendModel of() {
}

private void validateChange(String beforeStatus) {
validateCanChange(beforeStatus);
validateSame(beforeStatus);
canChange(beforeStatus);
isSameBeforeStatus(beforeStatus);
}

private void validateCanChange(String beforeStatus) {
private void canChange(String beforeStatus) {
if (AttendStatus.isSame(beforeStatus, AttendStatus.NONRELATED)) {
throw new DeniedSaveAttendException();
}
}

private void validateSame(String status) {
private void isSameBeforeStatus(String status) {
if (AttendStatus.isSame(status, this.status)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.blackcompany.eeos.attend.application.service;

import com.blackcompany.eeos.attend.application.dto.AttendInfoActiveStatusResponse;
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.QueryAttendActiveStatusResponse;
import com.blackcompany.eeos.attend.application.dto.QueryAttendStatusResponse;
import com.blackcompany.eeos.attend.application.dto.converter.AttendInfoActiveStatusConverter;
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.QueryAttendActiveStatusConverter;
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;
Expand Down Expand Up @@ -48,6 +52,8 @@ public class AttendService
private final MemberEntityConverter memberEntityConverter;
private final AttendInfoConverter attendInfoConverter;
private final QueryAttendStatusResponseConverter attendStatusResponseConverter;
private final AttendInfoActiveStatusConverter attendInfoActiveStatusConverter;
private final QueryAttendActiveStatusConverter queryAttendActiveStatusConverter;

@Override
public List<AttendInfoResponse> findAttendInfo(final Long programId) {
Expand Down Expand Up @@ -79,36 +85,37 @@ public ChangeAttendStatusResponse changeStatus(
final Long memberId, final ChangeAttendStatusRequest request, final Long programId) {
AttendModel model = getAttend(memberId, programId);

model.changeStatus(request.getBeforeAttendStatus(), request.getAfterAttendStatus());
AttendEntity updated = attendRepository.save(attendEntityConverter.toEntity(model));
AttendModel changedModel =
model.changeStatus(request.getBeforeAttendStatus(), request.getAfterAttendStatus());
AttendEntity updated = attendRepository.save(attendEntityConverter.toEntity(changedModel));

String name = queryMemberService.getName(memberId);
return changeAttendStatusConverter.from(name, updated.getStatus().getStatus());
}

@Override
public ChangeAttendStatusResponse getStatus(Long memberId, Long programId) {
boolean isAttend = getAttendDefault(memberId, programId);
boolean isAttend = isExistAttend(memberId, programId);
String name = queryMemberService.getName(memberId);

if (isAttend) {
AttendModel model = getAttend(memberId, programId);
return changeAttendStatusConverter.from(name, model.getStatus());
AttendModel existModel = getAttend(memberId, programId);
return changeAttendStatusConverter.from(name, existModel.getStatus());
}

return changeAttendStatusConverter.from(name, AttendStatus.NONRELATED.getStatus());
}

@Override
public QueryAttendStatusResponse execute(Long programId, String activeStatus) {
List<MemberModel> members = findMembers(activeStatus);
public QueryAttendActiveStatusResponse getAttendInfo(Long programId, String activeStatus) {
List<MemberModel> members = findMembersByActiveStatus(activeStatus);

List<AttendInfoResponse> response =
List<AttendInfoActiveStatusResponse> response =
members.stream()
.map(member -> combine(member, findAttend(programId)))
.map(member -> combine(member, findAttend(programId), member.getActiveStatus()))
.collect(Collectors.toList());

return attendStatusResponseConverter.of(response);
return queryAttendActiveStatusConverter.of(response);
}

private AttendModel getAttend(final Long memberId, final Long programId) {
Expand All @@ -118,7 +125,7 @@ private AttendModel getAttend(final Long memberId, final Long programId) {
.orElseThrow(() -> new NotFoundAttendException(programId));
}

private boolean getAttendDefault(final Long memberId, final Long programId) {
private boolean isExistAttend(final Long memberId, final Long programId) {
return attendRepository.findByProgramIdAndMemberId(programId, memberId).isPresent();
}

Expand All @@ -138,15 +145,16 @@ private AttendInfoResponse combine(
return attendInfoConverter.from(member, model.getStatus());
}

private AttendInfoResponse combine(MemberModel member, List<AttendModel> attends) {
private AttendInfoActiveStatusResponse combine(
MemberModel member, List<AttendModel> attends, String activeStatus) {

AttendModel model =
attends.stream()
.filter(attend -> member.validateSame(attend.getMemberId()))
.findAny()
.orElse(AttendModel.of());

return attendInfoConverter.from(member, model.getStatus());
return attendInfoActiveStatusConverter.from(member, model.getStatus(), activeStatus);
}

private List<MemberModel> findMembers(List<AttendModel> attends) {
Expand All @@ -171,7 +179,7 @@ private List<AttendModel> findAttend(final Long programId) {
.collect(Collectors.toList());
}

private List<MemberModel> findMembers(final String activeStatus) {
private List<MemberModel> findMembersByActiveStatus(final String activeStatus) {
if (ActiveStatus.isSame(activeStatus, ActiveStatus.ALL)) {
return memberRepository.findMembers().stream()
.map(memberEntityConverter::from)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.blackcompany.eeos.attend.application.usecase;

import com.blackcompany.eeos.attend.application.dto.QueryAttendStatusResponse;
import com.blackcompany.eeos.attend.application.dto.QueryAttendActiveStatusResponse;

/** 프로그램에 관련 없음 대상자도 활동 상태를 기준으로 조회한다. */
public interface GetAttendAllInfoSortActiveStatusUsecase {
QueryAttendStatusResponse execute(final Long programId, final String activeStatus);
QueryAttendActiveStatusResponse getAttendInfo(final Long programId, final String activeStatus);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,12 @@
public interface GetAttendantInfoUsecase {
List<AttendInfoResponse> findAttendInfo(final Long programId);

/**
* 프로그램의 관련 있음 대상자만 참석 상태를 기준으로 조회한다.
*
* @param programId
* @param attendStatus
* @return
*/
QueryAttendStatusResponse findAttendInfo(final Long programId, final String attendStatus);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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.QueryAttendActiveStatusResponse;
import com.blackcompany.eeos.attend.application.dto.QueryAttendStatusResponse;
import com.blackcompany.eeos.attend.application.usecase.ChangeAttendStatusUsecase;
import com.blackcompany.eeos.attend.application.usecase.GetAttendAllInfoSortActiveStatusUsecase;
Expand All @@ -26,22 +27,22 @@

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/attend")
@RequestMapping("/api")
public class AttendController {

private final GetAttendantInfoUsecase getAttendantInfoUsecase;
private final ChangeAttendStatusUsecase changeAttendStatusUsecase;
private final GetAttendStatusUsecase getAttendStatusUsecase;
private final GetAttendAllInfoSortActiveStatusUsecase getAttendAllInfoSortActiveStatusUsecase;

@GetMapping("/candidate/programs/{programId}")
@GetMapping("/attend/candidate/programs/{programId}")
public ApiResponse<SuccessBody<List<AttendInfoResponse>>> findAttendMemberInfo(
@PathVariable("programId") Long programId) {
List<AttendInfoResponse> response = getAttendantInfoUsecase.findAttendInfo(programId);
return ApiResponseGenerator.success(response, HttpStatus.OK, MessageCode.GET);
}

@PutMapping("/programs/{programId}")
@PutMapping("/attend/programs/{programId}")
public ApiResponse<SuccessBody<ChangeAttendStatusResponse>> changeAttendStatus(
@Member Long memberId,
@PathVariable("programId") Long programId,
Expand All @@ -51,29 +52,30 @@ public ApiResponse<SuccessBody<ChangeAttendStatusResponse>> changeAttendStatus(
return ApiResponseGenerator.success(response, HttpStatus.OK, MessageCode.UPDATE);
}

@GetMapping("/programs/{programId}")
@GetMapping("/attend/programs/{programId}")
public ApiResponse<SuccessBody<ChangeAttendStatusResponse>> getAttendStatus(
@Member Long memberId, @PathVariable("programId") Long programId) {
ChangeAttendStatusResponse response = getAttendStatusUsecase.getStatus(memberId, programId);
return ApiResponseGenerator.success(response, HttpStatus.OK, MessageCode.UPDATE);
}

@GetMapping("/programs/{programId}/members")
@GetMapping("/attend/programs/{programId}/members")
public ApiResponse<SuccessBody<QueryAttendStatusResponse>> getAttendInfoByProgram(
@PathVariable("programId") Long programId,
@RequestParam("attendStatus") String attendStatus) {

QueryAttendStatusResponse response =
getAttendantInfoUsecase.findAttendInfo(programId, attendStatus);
return ApiResponseGenerator.success(response, HttpStatus.OK, MessageCode.GET);
}

@GetMapping("candidate/programs/{programId}/members")
public ApiResponse<SuccessBody<QueryAttendStatusResponse>>
@GetMapping("/programs/{programId}/members")
public ApiResponse<SuccessBody<QueryAttendActiveStatusResponse>>
getAttendAllInfoByProgramSortActiveStatus(
@PathVariable("programId") Long programId,
@RequestParam("activeStatus") String activeStatus) {
QueryAttendStatusResponse response =
getAttendAllInfoSortActiveStatusUsecase.execute(programId, activeStatus);
QueryAttendActiveStatusResponse response =
getAttendAllInfoSortActiveStatusUsecase.getAttendInfo(programId, activeStatus);
return ApiResponseGenerator.success(response, HttpStatus.OK, MessageCode.GET);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@
public class TokenProvider {

private static final String MEMBER_ID_CLAIM_KEY = "memberId";
private final SecretKey secretKey;
private final SecretKey accessSecretKey;
private final SecretKey refreshSecretKey;
private final long accessValidTime;
private final long refreshValidTime;

public TokenProvider(
@Value("${security.jwt.token.secretKey}") String secretKey,
@Value("${security.jwt.token.access.validTime}") long accessValidTime,
@Value("${security.jwt.token.refresh.validTime}") long refreshValidTime) {
this.secretKey = Keys.hmacShaKeyFor(secretKey.getBytes(StandardCharsets.UTF_8));
@Value("${security.jwt.access.secretKey}") String accessSecretKey,
@Value("${security.jwt.refresh.secretKey}") String refreshSecretKey,
@Value("${security.jwt.access.validTime}") long accessValidTime,
@Value("${security.jwt.refresh.validTime}") long refreshValidTime) {
this.accessSecretKey = Keys.hmacShaKeyFor(accessSecretKey.getBytes(StandardCharsets.UTF_8));
this.refreshSecretKey = Keys.hmacShaKeyFor(refreshSecretKey.getBytes(StandardCharsets.UTF_8));
this.accessValidTime = accessValidTime;
this.refreshValidTime = refreshValidTime;
}
Expand All @@ -36,7 +39,7 @@ public String createAccessToken(final Long memberId) {
.claim(MEMBER_ID_CLAIM_KEY, memberId)
.setIssuedAt(now)
.setExpiration(new Date(now.getTime() + accessValidTime))
.signWith(secretKey)
.signWith(accessSecretKey)
.compact();
}

Expand All @@ -48,7 +51,7 @@ public String createRefreshToken(final Long memberId) {
.claim(MEMBER_ID_CLAIM_KEY, memberId)
.setIssuedAt(now)
.setExpiration(new Date(now.getTime() + refreshValidTime))
.signWith(secretKey)
.signWith(refreshSecretKey)
.compact();
}
}
Loading

0 comments on commit 5ac585b

Please sign in to comment.