Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public enum ErrorCode {
CHANNEL_SEQUENCE_NOT_UNIQUE(HttpStatus.BAD_REQUEST.value(), "채널의 순서가 중복되었습니다."),
CHANNEL_REGISTRATION_LIMIT_EXCEEDED(HttpStatus.BAD_REQUEST.value(), "등록 가능한 채널 수를 초과하였습니다."),
ALREADY_MENTOR(HttpStatus.BAD_REQUEST.value(), "이미 멘토로 등록된 사용자입니다."),
ALREADY_EXIST_MENTORING(HttpStatus.BAD_REQUEST.value(), "이미 신청된 멘티, 멘토입니다."),
MENTORING_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당 멘토링 신청을 찾을 수 없습니다."),
UNAUTHORIZED_MENTORING(HttpStatus.FORBIDDEN.value(), "멘토링 권한이 없습니다."),
MENTORING_ALREADY_CONFIRMED(HttpStatus.BAD_REQUEST.value(), "이미 승인 또는 거절된 멘토링입니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import jakarta.persistence.UniqueConstraint;
import java.time.ZonedDateTime;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
Expand All @@ -27,29 +29,35 @@
@DynamicInsert
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "mentoring", uniqueConstraints = {
@UniqueConstraint(
name = "uk_mentoring_mentor_id_mentee_id",
columnNames = {"mentor_id", "mentee_id"}
)
})
public class Mentoring extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column
@Column(name="confirmed_at")
private ZonedDateTime confirmedAt;

@Column
@Column(name = "checked_at_by_mentor")
private ZonedDateTime checkedAtByMentor;

@Column
@Column(name = "checked_at_by_mentee")
private ZonedDateTime checkedAtByMentee;

@Column(nullable = false)
@Column(nullable = false, name="verify_status")
@Enumerated(EnumType.STRING)
private VerifyStatus verifyStatus = VerifyStatus.PENDING;

@Column
@Column(name = "mentor_id")
private long mentorId;

@Column
@Column(name = "mentee_id")
private long menteeId;

public Mentoring(long mentorId, long menteeId, VerifyStatus verifyStatus) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.solidconnection.mentor.service;

import static com.example.solidconnection.common.exception.ErrorCode.ALREADY_EXIST_MENTORING;
import static com.example.solidconnection.common.exception.ErrorCode.MENTORING_ALREADY_CONFIRMED;
import static com.example.solidconnection.common.exception.ErrorCode.MENTORING_NOT_FOUND;
import static com.example.solidconnection.common.exception.ErrorCode.MENTOR_NOT_FOUND;
Expand Down Expand Up @@ -30,8 +31,13 @@ public class MentoringCommandService {

@Transactional
public MentoringApplyResponse applyMentoring(long siteUserId, MentoringApplyRequest mentoringApplyRequest) {
Mentoring mentoring = new Mentoring(mentoringApplyRequest.mentorId(), siteUserId, VerifyStatus.PENDING);
long mentorId = mentoringApplyRequest.mentorId();

if (mentoringRepository.existsByMentorIdAndMenteeId(mentorId, siteUserId)) {
throw new CustomException(ALREADY_EXIST_MENTORING);
}

Mentoring mentoring = new Mentoring(mentoringApplyRequest.mentorId(), siteUserId, VerifyStatus.PENDING);
return MentoringApplyResponse.from(mentoringRepository.save(mentoring));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE mentoring
ADD CONSTRAINT uk_mentoring_mentor_id_mentee_id
UNIQUE (mentor_id, mentee_id);
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.solidconnection.mentor.service;

import static com.example.solidconnection.common.exception.ErrorCode.ALREADY_EXIST_MENTORING;
import static com.example.solidconnection.common.exception.ErrorCode.MENTORING_ALREADY_CONFIRMED;
import static com.example.solidconnection.common.exception.ErrorCode.MENTORING_NOT_FOUND;
import static com.example.solidconnection.common.exception.ErrorCode.UNAUTHORIZED_MENTORING;
Expand Down Expand Up @@ -96,6 +97,18 @@ class 멘토링_신청_테스트 {
() -> assertThat(mentoring.getVerifyStatus()).isEqualTo(VerifyStatus.PENDING)
);
}

@Test
void 동일_멘티_멘토끼리는_재신청되지않는다() {
// given
mentoringFixture.대기중_멘토링(mentor1.getId(), menteeUser.getId());
MentoringApplyRequest request = new MentoringApplyRequest(mentor1.getId());

// when & then
assertThatThrownBy(() -> mentoringCommandService.applyMentoring(menteeUser.getId(), request))
.isInstanceOf(CustomException.class)
.hasMessage(ALREADY_EXIST_MENTORING.getMessage());
}
}

@Nested
Expand Down
Loading