Skip to content

Commit

Permalink
[REFACT] 사용자의 프로젝트 조회 API 리팩토링 (#253)
Browse files Browse the repository at this point in the history
* [REFACT] 사용자의 프로젝트 조회 API 응답타입 수정

* [REFACT] 프로젝트 조회 시, 매칭된 프로젝트도 조회할 수 있도록 리팩토링, 응답으로 매칭 아이디 추가 전달
  • Loading branch information
JIN-076 authored Mar 11, 2024
1 parent ce4c09d commit a9d18d8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.oeid.mogakgo.domain.project.presentation.dto.req.ProjectCreateReq;
import io.oeid.mogakgo.domain.project.presentation.dto.res.ProjectDensityRankRes;
import io.oeid.mogakgo.domain.project.presentation.dto.res.ProjectDetailAPIRes;
import io.oeid.mogakgo.domain.project.presentation.dto.res.ProjectDetailInfoAPIRes;
import io.oeid.mogakgo.domain.project.presentation.dto.res.ProjectInfoAPIRes;
import io.oeid.mogakgo.domain.project_join_req.exception.ProjectJoinRequestException;
import io.oeid.mogakgo.domain.project_join_req.infrastructure.ProjectJoinRequestJpaRepository;
Expand Down Expand Up @@ -179,7 +180,7 @@ public ProjectDensityRankRes getDensityRankProjects() {
return new ProjectDensityRankRes(regionRankList);
}

public List<ProjectDetailAPIRes> getLastedProjectByUserId(Long userId, Long id) {
public ProjectDetailInfoAPIRes getLastedProjectByUserId(Long userId, Long id) {
User user = getUser(userId);

validateProjectCardCreator(user, id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.oeid.mogakgo.domain.geo.domain.enums.Region;
import io.oeid.mogakgo.domain.project.domain.entity.enums.ProjectStatus;
import io.oeid.mogakgo.domain.project.presentation.dto.res.ProjectDetailAPIRes;
import io.oeid.mogakgo.domain.project.presentation.dto.res.ProjectDetailInfoAPIRes;
import io.oeid.mogakgo.domain.project.presentation.dto.res.ProjectInfoAPIRes;
import java.util.List;

Expand All @@ -20,5 +21,5 @@ CursorPaginationResult<ProjectInfoAPIRes> findByCreatorIdWithPagination(

List<Region> getDensityRankProjectsByRegion(int limit);

List<ProjectDetailAPIRes> findLatestProjectByUserId(Long userId);
ProjectDetailInfoAPIRes findLatestProjectByUserId(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static io.oeid.mogakgo.domain.project.domain.entity.QProject.project;
import static io.oeid.mogakgo.domain.user.domain.QUser.user;
import static io.oeid.mogakgo.domain.matching.domain.entity.QMatching.matching;

import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
Expand All @@ -13,6 +14,7 @@
import io.oeid.mogakgo.domain.project.domain.entity.enums.ProjectStatus;
import io.oeid.mogakgo.domain.project.presentation.dto.res.MeetingInfoResponse;
import io.oeid.mogakgo.domain.project.presentation.dto.res.ProjectDetailAPIRes;
import io.oeid.mogakgo.domain.project.presentation.dto.res.ProjectDetailInfoAPIRes;
import io.oeid.mogakgo.domain.project.presentation.dto.res.ProjectInfoAPIRes;
import io.oeid.mogakgo.domain.user.domain.UserDevelopLanguageTag;
import io.oeid.mogakgo.domain.user.domain.UserWantedJobTag;
Expand Down Expand Up @@ -126,18 +128,25 @@ public List<Region> getDensityRankProjectsByRegion(int limit) {
}

@Override
public List<ProjectDetailAPIRes> findLatestProjectByUserId(Long userId) {
public ProjectDetailInfoAPIRes findLatestProjectByUserId(Long userId) {

List<Project> entity = jpaQueryFactory.selectFrom(project)
.innerJoin(project.creator, user)
.on(project.creator.id.eq(user.id))
.where(
userIdEq(userId),
projectStatusEq(ProjectStatus.PENDING)
.or(projectStatusEq(ProjectStatus.MATCHED)),
createdAtEq(LocalDate.now())
)
.fetch();

return entity.stream().map(
Long matchingId = entity.isEmpty() ? null : jpaQueryFactory.select(matching.id)
.from(matching)
.where(matching.project.id.eq(entity.get(0).getId()))
.fetchOne();

List<ProjectDetailAPIRes> result = entity.stream().map(
project -> new ProjectDetailAPIRes(
project.getId(),
new UserPublicApiResponse(
Expand Down Expand Up @@ -165,6 +174,8 @@ public List<ProjectDetailAPIRes> findLatestProjectByUserId(Long userId) {
)
)
).toList();

return ProjectDetailInfoAPIRes.of(matchingId, result);
}

private BooleanExpression cursorIdCondition(Long cursorId) {
Expand All @@ -180,7 +191,7 @@ private BooleanExpression regionEq(Region region) {
}

private BooleanExpression projectStatusEq(ProjectStatus projectStatus) {
return projectStatus != null ? project.projectStatus.eq(projectStatus) : null;
return project.projectStatus.eq(projectStatus);
}

private BooleanExpression createdAtEq(LocalDate today) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public ResponseEntity<ProjectDetailAPIRes> getById(
@GetMapping("/{id}/info")
public ResponseEntity<ProjectDetailInfoAPIRes> getByUserId(
@UserId Long userId, @PathVariable Long id) {
return ResponseEntity.ok().body(ProjectDetailInfoAPIRes.of(projectService.getLastedProjectByUserId(userId, id)));
return ResponseEntity.ok().body(projectService.getLastedProjectByUserId(userId, id));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class ProjectDetailInfoAPIRes {

private final Long matchingId;
private final List<ProjectDetailAPIRes> response;

public static ProjectDetailInfoAPIRes of(List<ProjectDetailAPIRes> response) {
return new ProjectDetailInfoAPIRes(response);
public static ProjectDetailInfoAPIRes of(Long matchingId, List<ProjectDetailAPIRes> response) {
return new ProjectDetailInfoAPIRes(matchingId, response);
}
}

0 comments on commit a9d18d8

Please sign in to comment.