Skip to content
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

[REFACT] 프로젝트 생성일 유효성 검사, 프로젝트 상태 유효성 검사, 프로젝트 상태 필드 추가 #132

Merged
merged 5 commits into from
Feb 21, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.oeid.mogakgo.domain.user.domain.UserDevelopLanguageTag;
import io.oeid.mogakgo.domain.user.domain.UserWantedJobTag;
import io.oeid.mogakgo.domain.user.presentation.dto.res.UserPublicApiResponse;
import java.time.LocalDate;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
Expand All @@ -30,6 +31,8 @@ public class ProjectRepositoryCustomImpl implements ProjectRepositoryCustom {
public CursorPaginationResult<ProjectDetailAPIRes> findByConditionWithPagination(
Long userId, Region region, ProjectStatus projectStatus, CursorPaginationInfoReq pageable
) {
LocalDate today = LocalDate.now();

List<Project> entities = jpaQueryFactory.selectFrom(project)
.innerJoin(project.creator, user)
.on(project.creator.id.eq(user.id))
Expand All @@ -38,7 +41,8 @@ public CursorPaginationResult<ProjectDetailAPIRes> findByConditionWithPagination
cursorIdCondition(pageable.getCursorId()),
userIdEq(userId),
regionEq(region),
projectStatusEq(projectStatus)
projectStatusEq(projectStatus),
createdAtEq(today)
)
.limit(pageable.getPageSize() + 1)
.fetch();
Expand Down Expand Up @@ -100,4 +104,10 @@ private BooleanExpression regionEq(Region region) {
private BooleanExpression projectStatusEq(ProjectStatus projectStatus) {
return projectStatus != null ? project.projectStatus.eq(projectStatus) : null;
}

private BooleanExpression createdAtEq(LocalDate today) {
return project.createdAt.year().eq(today.getYear())
.and(project.createdAt.month().eq(today.getMonthValue()))
.and(project.createdAt.dayOfMonth().eq(today.getDayOfMonth()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.oeid.mogakgo.domain.matching.application.MatchingService;
import io.oeid.mogakgo.domain.matching.application.UserMatchingService;
import io.oeid.mogakgo.domain.project.domain.entity.Project;
import io.oeid.mogakgo.domain.project.domain.entity.enums.ProjectStatus;
import io.oeid.mogakgo.domain.project.exception.ProjectException;
import io.oeid.mogakgo.domain.project.infrastructure.ProjectJpaRepository;
import io.oeid.mogakgo.domain.project_join_req.application.dto.req.ProjectJoinCreateReq;
Expand All @@ -27,6 +28,7 @@
import io.oeid.mogakgo.domain.user.domain.User;
import io.oeid.mogakgo.domain.user.exception.UserException;
import io.oeid.mogakgo.domain.user.infrastructure.UserJpaRepository;
import io.oeid.mogakgo.exception.code.ErrorCode400;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -49,6 +51,7 @@ public Long create(Long userId, ProjectJoinCreateReq request) {
User tokenUser = validateToken(userId);
validateSender(tokenUser, request.getSenderId());
Project project = validateProjectExist(request.getProjectId());
validateProjectStatus(project.getProjectStatus()); // 요청을 보내려는 프로젝트가 대기중이 맞는지 검사
validateProjectCreator(project, userId);
validateUserCertRegion(project, tokenUser);
validateAlreadyExistRequest(userId, project.getId());
Expand Down Expand Up @@ -141,6 +144,12 @@ private Project validateProjectExist(Long projectId) {
.orElseThrow(() -> new ProjectException(PROJECT_NOT_FOUND));
}

private void validateProjectStatus(ProjectStatus projectStatus) {
if (!projectStatus.equals(ProjectStatus.PENDING)) {
throw new ProjectJoinRequestException(ErrorCode400.INVALID_PROJECT_STATUS_TO_ACCEPT);
}
}

private void validateProjectCreator(Project project, Long userId) {
if (project.getCreator().getId().equals(userId)) {
throw new ProjectJoinRequestException(INVALID_CREATOR_PROJECT_JOIN_REQUEST);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package io.oeid.mogakgo.domain.project_join_req.infrastructure;

import static io.oeid.mogakgo.domain.project.domain.entity.QProject.project;
import static io.oeid.mogakgo.domain.project_join_req.domain.entity.QProjectJoinRequest.projectJoinRequest;

import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import io.oeid.mogakgo.common.base.CursorPaginationInfoReq;
Expand Down Expand Up @@ -82,20 +80,7 @@ public boolean existsByProjectId(Long projectId) {
public CursorPaginationResult<ProjectJoinRequestDetailAPIRes> getBySenderIdWithPagination(
Long senderId, Long projectId, RequestStatus requestStatus, CursorPaginationInfoReq pageable
) {
List<ProjectJoinRequestDetailAPIRes> result = jpaQueryFactory.select(
Projections.constructor(
ProjectJoinRequestDetailAPIRes.class,
projectJoinRequest.project.id,
projectJoinRequest.project.creator.avatarUrl,
Projections.constructor(
MeetingInfoResponse.class,
projectJoinRequest.project.meetingInfo.meetStartTime,
projectJoinRequest.project.meetingInfo.meetEndTime,
projectJoinRequest.project.meetingInfo.meetDetail
))
)
.from(projectJoinRequest)
.innerJoin(project).on(projectJoinRequest.project.id.eq(projectId))
List<ProjectJoinRequest> entities = jpaQueryFactory.selectFrom(projectJoinRequest)
.where(
cursorIdCondition(pageable.getCursorId()),
senderIdEq(senderId),
Expand All @@ -105,6 +90,19 @@ public CursorPaginationResult<ProjectJoinRequestDetailAPIRes> getBySenderIdWithP
.limit(pageable.getPageSize() + 1)
.fetch();

List<ProjectJoinRequestDetailAPIRes> result = entities.stream().map(
projectJoinRequest -> new ProjectJoinRequestDetailAPIRes(
projectJoinRequest.getProject().getId(),
projectJoinRequest.getProject().getProjectStatus(),
projectJoinRequest.getProject().getCreator().getAvatarUrl(),
new MeetingInfoResponse(
projectJoinRequest.getProject().getMeetingInfo().getMeetStartTime(),
projectJoinRequest.getProject().getMeetingInfo().getMeetEndTime(),
projectJoinRequest.getProject().getMeetingInfo().getMeetDetail()
)
)
).toList();

return CursorPaginationResult.fromDataWithExtraItemForNextCheck(
result, pageable.getPageSize()
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.oeid.mogakgo.domain.project_join_req.presentation.dto.res;

import io.oeid.mogakgo.domain.project.domain.entity.enums.ProjectStatus;
import io.oeid.mogakgo.domain.project.presentation.dto.res.MeetingInfoResponse;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
Expand All @@ -13,24 +14,29 @@ public class ProjectJoinRequestDetailAPIRes {
@NotNull
private final Long projectId;

@Schema(description = "프로젝트 상태", example = "PENDING", implementation = ProjectStatus.class)
@NotNull
private final ProjectStatus projectStatus;

@Schema(description = "프로젝트 생성자 아바타 URL", example = "https://avatars.githubusercontent.com/u/85854384?v=4")
private final String creatorAvatorUrl;

@Schema(description = "프로젝트 만남 장ㅔ")
private final MeetingInfoResponse meetingInfo;

public ProjectJoinRequestDetailAPIRes(
Long projectId, String creatorAvatorUrl, MeetingInfoResponse meetingInfo
public ProjectJoinRequestDetailAPIRes(Long projectId, ProjectStatus projectStatus,
String creatorAvatorUrl, MeetingInfoResponse meetingInfo
) {
this.projectId = projectId;
this.projectStatus = projectStatus;
this.creatorAvatorUrl = creatorAvatorUrl;
this.meetingInfo = meetingInfo;
}

public static ProjectJoinRequestDetailAPIRes from(
Long projectId, String creatorAvatorUrl, MeetingInfoResponse meetingInfo
public static ProjectJoinRequestDetailAPIRes from(Long projectId, ProjectStatus projectStatus,
String creatorAvatorUrl, MeetingInfoResponse meetingInfo
) {
return new ProjectJoinRequestDetailAPIRes(projectId, creatorAvatorUrl, meetingInfo);
return new ProjectJoinRequestDetailAPIRes(projectId, projectStatus, creatorAvatorUrl, meetingInfo);
}

}
Loading