Skip to content

Commit

Permalink
Merge pull request #32 from WE-ARE-RACCOONS/RAC-99
Browse files Browse the repository at this point in the history
Rac 99
  • Loading branch information
ay-eonii authored Nov 9, 2023
2 parents dc375fa + 66d6b37 commit 7640547
Show file tree
Hide file tree
Showing 18 changed files with 264 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package com.postgraduate.domain.mentoring.application.dto.req;

import com.postgraduate.domain.mentoring.domain.entity.constant.Status;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class MentoringStatusRequest {
@AllArgsConstructor
public class MentoringDateRequest {
@NotNull
private Status status;
private String date;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.postgraduate.domain.mentoring.application.dto.req;

import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class MentoringRefuseRequest {
@NotNull
private String refuse;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.postgraduate.domain.mentoring.application.dto.res;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Builder
@AllArgsConstructor
@Getter
public class SeniorMentoringDetailResponse {
private String nickName;
private String topic;
private String question;
private String[] dates;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.postgraduate.domain.mentoring.application.dto.res;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Builder
@AllArgsConstructor
@Getter
public class SeniorMentoringResponse {
private Long mentoringId;
private String nickname;
private String[] dates;
private int term;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.postgraduate.domain.mentoring.application.dto.AppliedMentoringInfo;
import com.postgraduate.domain.mentoring.application.dto.req.MentoringApplyRequest;
import com.postgraduate.domain.mentoring.application.dto.res.AppliedMentoringDetailResponse;
import com.postgraduate.domain.mentoring.application.dto.res.SeniorMentoringDetailResponse;
import com.postgraduate.domain.mentoring.application.dto.res.SeniorMentoringResponse;
import com.postgraduate.domain.mentoring.domain.entity.Mentoring;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.user.domain.entity.User;
Expand Down Expand Up @@ -63,4 +65,24 @@ public static Mentoring mapToMentoring(User user, Senior senior, MentoringApplyR
.date(request.getDate())
.build();
}

public static SeniorMentoringResponse mapToSeniorMentoring(Mentoring mentoring) {
String[] dates = mentoring.getDate().split(",");
return SeniorMentoringResponse.builder()
.mentoringId(mentoring.getMentoringId())
.nickname(mentoring.getUser().getNickName())
.dates(dates)
.term(mentoring.getSenior().getTerm())
.build();
}

public static SeniorMentoringDetailResponse mapToSeniorMentoringDetail(Mentoring mentoring) {
String[] dates = mentoring.getDate().split(",");
return SeniorMentoringDetailResponse.builder()
.nickName(mentoring.getUser().getNickName())
.topic(mentoring.getTopic())
.question(mentoring.getQuestion())
.dates(dates)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import com.postgraduate.domain.mentoring.domain.entity.Mentoring;
import com.postgraduate.domain.mentoring.domain.service.MentoringGetService;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.senior.domain.service.SeniorGetService;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.global.auth.AuthDetails;
import com.postgraduate.global.config.security.util.SecurityUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -13,16 +16,22 @@
@Transactional
@RequiredArgsConstructor
public class CheckIsMyMentoringUseCase {
private final SecurityUtils securityUtils;
private final SeniorGetService seniorGetService;
private final MentoringGetService mentoringGetService;
public Mentoring checkByRole(User user, Long mentoringId) {

public Mentoring byUser(AuthDetails authDetails, Long mentoringId) {
User user = securityUtils.getLoggedInUser(authDetails);
Mentoring mentoring = mentoringGetService.byMentoringId(mentoringId);
if (mentoring.getUser() != user) {
throw new PermissionDeniedException();
}
return mentoring;
}

public Mentoring checkByRole(Senior senior, Long mentoringId) {
public Mentoring bySenior(AuthDetails authDetails, Long mentoringId) {
User user = securityUtils.getLoggedInUser(authDetails);
Senior senior = seniorGetService.byUser(user);
Mentoring mentoring = mentoringGetService.byMentoringId(mentoringId);
if (mentoring.getSenior() != senior) {
throw new PermissionDeniedException();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package com.postgraduate.domain.mentoring.application.usecase;

import com.postgraduate.domain.mentoring.application.dto.AppliedMentoringInfo;
import com.postgraduate.domain.mentoring.application.dto.res.AppliedMentoringDetailResponse;
import com.postgraduate.domain.mentoring.application.dto.res.AppliedMentoringResponse;
import com.postgraduate.domain.mentoring.application.dto.AppliedMentoringInfo;
import com.postgraduate.domain.mentoring.application.dto.res.SeniorMentoringDetailResponse;
import com.postgraduate.domain.mentoring.application.dto.res.SeniorMentoringResponse;
import com.postgraduate.domain.mentoring.application.mapper.MentoringMapper;
import com.postgraduate.domain.mentoring.domain.entity.Mentoring;
import com.postgraduate.domain.mentoring.domain.entity.constant.Status;
import com.postgraduate.domain.mentoring.domain.service.MentoringGetService;
import com.postgraduate.domain.mentoring.exception.MentoringDoneException;
import com.postgraduate.domain.mentoring.exception.MentoringNotWaitingException;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.senior.domain.service.SeniorGetService;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.global.auth.AuthDetails;
import com.postgraduate.global.config.security.util.SecurityUtils;
Expand All @@ -16,13 +22,18 @@

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import static com.postgraduate.domain.mentoring.domain.entity.constant.Status.DONE;
import static com.postgraduate.domain.mentoring.domain.entity.constant.Status.WAITING;

@Service
@Transactional
@RequiredArgsConstructor
public class MentoringInfoUseCase {
private final MentoringGetService mentoringGetService;
private final CheckIsMyMentoringUseCase checkIsMyMentoringUseCase;
private final SeniorGetService seniorGetService;
private final SecurityUtils securityUtils;
/**
* securityUtils 이후 수정
Expand All @@ -35,6 +46,14 @@ public AppliedMentoringResponse getMentorings(Status status, AuthDetails authDet
return getCategories(status, mentorings);
}

public List<SeniorMentoringResponse> getSeniorMentorings(Status status, AuthDetails authDetails) {
User user = securityUtils.getLoggedInUser(authDetails);
Senior senior = seniorGetService.byUser(user);

List<Mentoring> mentorings = mentoringGetService.mentoringBySenior(senior, status);
return mentorings.stream().map(MentoringMapper::mapToSeniorMentoring).collect(Collectors.toList());
}

private AppliedMentoringResponse getCategories(Status status, List<Mentoring> mentorings) {
List<AppliedMentoringInfo> appliedMentoringInfos = new ArrayList<>();

Expand All @@ -56,8 +75,18 @@ private AppliedMentoringResponse getCategories(Status status, List<Mentoring> me
}

public AppliedMentoringDetailResponse getMentoringDetail(AuthDetails authDetails, Long mentoringId) {
User user = securityUtils.getLoggedInUser(authDetails);
Mentoring mentoring = checkIsMyMentoringUseCase.checkByRole(user, mentoringId);
Mentoring mentoring = checkIsMyMentoringUseCase.byUser(authDetails, mentoringId);
if (mentoring.getStatus() != WAITING) {
throw new MentoringNotWaitingException();
}
return MentoringMapper.mapToAppliedDetailInfo(mentoring);
}

public SeniorMentoringDetailResponse getSeniorMentoringDetail(AuthDetails authDetails, Long mentoringId) {
Mentoring mentoring = checkIsMyMentoringUseCase.bySenior(authDetails, mentoringId);
if (mentoring.getStatus() == DONE) {
throw new MentoringDoneException();
}
return MentoringMapper.mapToSeniorMentoringDetail(mentoring);
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,46 @@
package com.postgraduate.domain.mentoring.application.usecase;

import com.postgraduate.domain.mentoring.application.dto.req.MentoringStatusRequest;
import com.postgraduate.domain.mentoring.application.dto.req.MentoringDateRequest;
import com.postgraduate.domain.mentoring.application.dto.req.MentoringRefuseRequest;
import com.postgraduate.domain.mentoring.domain.entity.Mentoring;
import com.postgraduate.domain.mentoring.domain.entity.constant.Status;
import com.postgraduate.domain.mentoring.domain.service.MentoringUpdateService;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.domain.mentoring.exception.MentoringNotWaitingException;
import com.postgraduate.global.auth.AuthDetails;
import com.postgraduate.global.config.security.util.SecurityUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import static com.postgraduate.domain.mentoring.domain.entity.constant.Status.WAITING;

@Service
@Transactional
@RequiredArgsConstructor
public class MentoringManageUseCase {
private final SecurityUtils securityUtils;
private final MentoringUpdateService mentoringUpdateService;
private final CheckIsMyMentoringUseCase checkIsMyMentoringUseCase;
private final MentoringUpdateService mentoringUpdateService;

public void updateStatus(AuthDetails authDetails, Long mentoringId, Status status) {
Mentoring mentoring = checkIsMyMentoringUseCase.byUser(authDetails, mentoringId);
mentoringUpdateService.updateStatus(mentoring, status);
}

public void updateSeniorStatus(AuthDetails authDetails, Long mentoringId, Status status) {
Mentoring mentoring = checkIsMyMentoringUseCase.bySenior(authDetails, mentoringId);
mentoringUpdateService.updateStatus(mentoring, status);
}

public void updateRefuse(AuthDetails authDetails, Long mentoringId, MentoringRefuseRequest request, Status status) {
Mentoring mentoring = checkIsMyMentoringUseCase.bySenior(authDetails, mentoringId);
mentoringUpdateService.updateRefuse(mentoring, request.getRefuse());
mentoringUpdateService.updateStatus(mentoring, status);
}

public void updateStatus(AuthDetails authDetails, Long mentoringId, MentoringStatusRequest request) {
User user = securityUtils.getLoggedInUser(authDetails);
Mentoring mentoring = checkIsMyMentoringUseCase.checkByRole(user, mentoringId);
mentoringUpdateService.updateStatus(mentoring, request.getStatus());
public void updateDate(AuthDetails authDetails, Long mentoringId, MentoringDateRequest request) {
Mentoring mentoring = checkIsMyMentoringUseCase.bySenior(authDetails, mentoringId);
if (mentoring.getStatus() != WAITING) {
throw new MentoringNotWaitingException();
}
mentoringUpdateService.updateDate(mentoring, request.getDate());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.CreationTimestamp;

import java.time.LocalDate;
Expand Down Expand Up @@ -42,6 +41,8 @@ public class Mentoring {
@Builder.Default
private int pay = 20000;

private String refuse;

@Enumerated(EnumType.STRING)
@Builder.Default
private Status status = Status.WAITING;
Expand All @@ -55,7 +56,15 @@ public void updateStatus(Status status) {
this.status = status;
}

public void updateRefuse(String refuse) {
this.refuse = refuse;
}

public void updateDeletedAt() {
this.deletedAt = LocalDate.now();
}

public void updateDate(String date) {
this.date = date;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.postgraduate.domain.mentoring.domain.entity.Mentoring;
import com.postgraduate.domain.mentoring.domain.entity.constant.Status;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.user.domain.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;

Expand All @@ -11,4 +12,5 @@
public interface MentoringRepository extends JpaRepository<Mentoring, Long> {
Optional<Mentoring> findByMentoringIdAndDeletedAtIsNull(Long mentoringId);
Optional<List<Mentoring>> findAllByUserAndStatusAndDeletedAtIsNull(User user, Status status);
Optional<List<Mentoring>> findAllBySeniorAndStatusAndDeletedAtIsNull(Senior senior, Status status);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.postgraduate.domain.mentoring.domain.entity.constant.Status;
import com.postgraduate.domain.mentoring.domain.repository.MentoringRepository;
import com.postgraduate.domain.mentoring.exception.MentoringNotFoundException;
import com.postgraduate.domain.senior.domain.entity.Senior;
import com.postgraduate.domain.user.domain.entity.User;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -20,6 +21,10 @@ public List<Mentoring> mentoringByUser(User user, Status status) {
return mentoringRepository.findAllByUserAndStatusAndDeletedAtIsNull(user, status).orElse(new ArrayList<>());
}

public List<Mentoring> mentoringBySenior(Senior senior, Status status) {
return mentoringRepository.findAllBySeniorAndStatusAndDeletedAtIsNull(senior, status).orElse(new ArrayList<>());
}

public Mentoring byMentoringId(Long mentoringId) {
return mentoringRepository.findByMentoringIdAndDeletedAtIsNull(mentoringId).orElseThrow(MentoringNotFoundException::new);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,12 @@ public void updateStatus(Mentoring mentoring, Status status) {
}
mentoring.updateStatus(status);
}

public void updateRefuse(Mentoring mentoring, String refuse) {
mentoring.updateRefuse(refuse);
}

public void updateDate(Mentoring mentoring, String date) {
mentoring.updateDate(date);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.postgraduate.domain.mentoring.exception;

import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseCode.MENTORING_DONE;
import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseMessage.DONE_MENTORING;


public class MentoringDoneException extends MentoringException {

public MentoringDoneException() {
super(DONE_MENTORING.getMessage(), MENTORING_DONE.getCode());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.postgraduate.domain.mentoring.exception;

import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseCode.MENTORING_NOT_WAITING;
import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseMessage.NOT_WAITING_MENTORING;


public class MentoringNotWaitingException extends MentoringException {

public MentoringNotWaitingException() {
super(NOT_WAITING_MENTORING.getMessage(), MENTORING_NOT_WAITING.getCode());
}
}
Loading

0 comments on commit 7640547

Please sign in to comment.