-
Notifications
You must be signed in to change notification settings - Fork 0
[Feat] Matching 도메인 관련 스켈레톤 코드 구현 및 엔티티 설계 #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package com.nect.api.matching.controller; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| public class MatchingController { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.nect.api.matching.dto; | ||
|
|
||
| import com.nect.core.entity.matching.enums.MatchingRequestType; | ||
| import jakarta.validation.constraints.NotNull; | ||
|
|
||
| public class MatchingReqDto { | ||
|
|
||
| public record matchingReqDto( | ||
| Long targetUserId, | ||
| @NotNull | ||
| Long projectId, | ||
| @NotNull | ||
| MatchingRequestType requestType | ||
| ){} | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package com.nect.api.matching.dto; | ||
|
|
||
| import com.nect.core.entity.matching.enums.MatchingRequestType; | ||
| import com.nect.core.entity.matching.enums.MatchingStatus; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| public class MatchingResDto { | ||
|
|
||
| public record matchingResDto( | ||
| Long id, | ||
| Long requestUserId, | ||
| Long targetUserId, | ||
| Long projectId, | ||
| MatchingStatus matchingStatus, | ||
| MatchingRequestType requestType, | ||
| LocalDateTime expiresAt | ||
| ){} | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.nect.api.matching.enums.code; | ||
|
|
||
| import com.nect.api.global.code.ResponseCode; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| public enum MatchingErrorCode implements ResponseCode { | ||
|
|
||
| MATCHING_APPLY_COUNT_EXCEEDED("M400_1", "이미 매칭 대기 중인 프로젝트가 있습니다."), | ||
| MATCHING_INVITE_COUNT_EXCEEDED("M400_2", "해당 프로젝트의 매칭 신청 가능 수를 초과하였습니다."), | ||
| ; | ||
|
|
||
| private final String statusCode; | ||
| private final String message; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package com.nect.api.matching.exception; | ||
|
|
||
| import com.nect.api.global.code.ResponseCode; | ||
| import com.nect.api.global.exception.CustomException; | ||
|
|
||
| public class MatchingException extends CustomException { | ||
|
|
||
| public MatchingException(ResponseCode code) { | ||
| super(code); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package com.nect.api.matching.service; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class MatchingService { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package com.nect.core.entity.matching; | ||
|
|
||
| import com.nect.core.entity.BaseEntity; | ||
| import com.nect.core.entity.matching.enums.MatchingRequestType; | ||
| import com.nect.core.entity.matching.enums.MatchingStatus; | ||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @Entity | ||
| @Table(name = "matching") | ||
| @Getter | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| public class Matching extends BaseEntity { | ||
|
|
||
| @Builder | ||
| public Matching( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 외부에서 다루지 않을거라면 protected 혹은 private도 고려해보면 좋을 듯 합니다.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expiresAt이나 의도하지 않은 칼럼이 빌더에 의해 수정될 경우를 대비해서 따로 생성자를 정의했습니다. 이럴 경우 외부에서 빌더 패턴을 사용하려면 public으로 설정해야하는데, 혹시 더 좋은 패턴이나 선호하시는 방식이 있으시면 말씀해주세요!!
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋습니다 굿굿 |
||
| Long requestUserId, | ||
| Long targetUserId, | ||
| Long projectId, | ||
| MatchingRequestType requestType | ||
| ){ | ||
| this.requestUserId = requestUserId; | ||
| this.targetUserId = targetUserId; | ||
| this.projectId = projectId; | ||
| this.requestType = requestType; | ||
| this.matchingStatus = MatchingStatus.PENDING; | ||
| } | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(name = "request_user_id", nullable = false) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 컬럼 name을 명시 안 해줘도 requestUserId -> request_user_id로 jpa가 바꿔서 db에 저장해주는데 의도적으로 명시해준걸까요?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵! 의도대로 저장되지 않을 경우를 대비해서 명확하게 지정했습니다! |
||
| private Long requestUserId; | ||
|
|
||
| @Column(name = "target_user_id", nullable = false) | ||
| private Long targetUserId; | ||
|
|
||
| @Column(name = "project_id", nullable = false) | ||
| private Long projectId; | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| @Column(name = "request_type", nullable = false) | ||
| private MatchingRequestType requestType; | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| @Column(name = "matching_status", nullable = false) | ||
| private MatchingStatus matchingStatus; | ||
|
|
||
| @Column(name = "expires_at") | ||
| private LocalDateTime expiresAt; | ||
|
|
||
| @PrePersist | ||
| public void calculateExpiration() { | ||
| this.expiresAt = LocalDateTime.now().plusHours(24); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.nect.core.entity.matching.enums; | ||
|
|
||
| public enum MatchingRequestType { | ||
| USER_TO_PROJECT, // 회원 -> 프로젝트 요청 | ||
| PROJECT_TO_USER // 프로젝트(리더) -> 요청 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package com.nect.core.entity.matching.enums; | ||
|
|
||
| public enum MatchingStatus { | ||
| PENDING, // 진행 | ||
| ACCEPTED, // 수락 | ||
| REJECTED, // 거절 | ||
| EXPIRED, // 만료 | ||
| CANCELED // 취소 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.nect.core.repository.matching; | ||
|
|
||
| import com.nect.core.entity.matching.Matching; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
|
|
||
| public interface MatchingRepository extends JpaRepository<Matching, Long> { | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
targetUserId는 null이어도 되나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네! targetUserId는 리더 -> 팀원 매칭 요청일 때만 받고, 팀원 -> 프로젝트 요청엔 projectId만 받아 서비스단에서 처리할 계획입니다.