Merge branch 'be/feat/project-detail' into 'be/develop'
Feat: 프로젝트에 썸네일 추가 See merge request s11-s-project/S11P21S002!149
This commit is contained in:
commit
4ebe662ea0
@ -23,6 +23,13 @@ public interface ImageRepository extends JpaRepository<Image, Long> {
|
|||||||
|
|
||||||
Optional<Image> findByIdAndFolderIdAndFolderProjectId(Long imageId, Integer folderId, Integer projectId);
|
Optional<Image> findByIdAndFolderIdAndFolderProjectId(Long imageId, Integer folderId, Integer projectId);
|
||||||
|
|
||||||
|
@Query(value = "SELECT i.* FROM project_image i " +
|
||||||
|
"JOIN folder f ON i.folder_id = f.folder_id " +
|
||||||
|
"JOIN project p ON f.project_id = p.project_id " +
|
||||||
|
"WHERE p.project_id = :projectId " +
|
||||||
|
"LIMIT 1", nativeQuery = true)
|
||||||
|
Optional<Image> findFirstImageByProjectId(@Param("projectId") Integer projectId);
|
||||||
|
|
||||||
@Query("SELECT i FROM Image i " +
|
@Query("SELECT i FROM Image i " +
|
||||||
"JOIN FETCH i.folder f " +
|
"JOIN FETCH i.folder f " +
|
||||||
"JOIN FETCH f.project p " +
|
"JOIN FETCH f.project p " +
|
||||||
|
@ -5,6 +5,7 @@ import com.worlabel.domain.project.dto.AutoModelRequest;
|
|||||||
import com.worlabel.domain.project.entity.dto.ProjectMemberResponse;
|
import com.worlabel.domain.project.entity.dto.ProjectMemberResponse;
|
||||||
import com.worlabel.domain.project.entity.dto.ProjectRequest;
|
import com.worlabel.domain.project.entity.dto.ProjectRequest;
|
||||||
import com.worlabel.domain.project.entity.dto.ProjectResponse;
|
import com.worlabel.domain.project.entity.dto.ProjectResponse;
|
||||||
|
import com.worlabel.domain.project.entity.dto.ProjectWithThumbnailResponse;
|
||||||
import com.worlabel.domain.project.service.ProjectService;
|
import com.worlabel.domain.project.service.ProjectService;
|
||||||
import com.worlabel.global.annotation.CurrentUser;
|
import com.worlabel.global.annotation.CurrentUser;
|
||||||
import com.worlabel.global.config.swagger.SwaggerApiError;
|
import com.worlabel.global.config.swagger.SwaggerApiError;
|
||||||
@ -52,7 +53,7 @@ public class ProjectController {
|
|||||||
@SwaggerApiSuccess(description = "전체 프로젝트를 성공적으로 조회합니다.")
|
@SwaggerApiSuccess(description = "전체 프로젝트를 성공적으로 조회합니다.")
|
||||||
@SwaggerApiError({ErrorCode.SERVER_ERROR})
|
@SwaggerApiError({ErrorCode.SERVER_ERROR})
|
||||||
@GetMapping("/workspaces/{workspace_id}/projects")
|
@GetMapping("/workspaces/{workspace_id}/projects")
|
||||||
public List<ProjectResponse> getProjects(
|
public List<ProjectWithThumbnailResponse> getProjects(
|
||||||
@PathVariable("workspace_id") Integer workspaceId,
|
@PathVariable("workspace_id") Integer workspaceId,
|
||||||
@CurrentUser final Integer memberId,
|
@CurrentUser final Integer memberId,
|
||||||
@Parameter(name = "마지막 프로젝트 id", description = "마지막 프로젝트 id를 넣으면 그 아래 부터 가져옴, 넣지않으면 가장 최신", example = "1") @RequestParam(required = false) Integer lastProjectId,
|
@Parameter(name = "마지막 프로젝트 id", description = "마지막 프로젝트 id를 넣으면 그 아래 부터 가져옴, 넣지않으면 가장 최신", example = "1") @RequestParam(required = false) Integer lastProjectId,
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
package com.worlabel.domain.project.entity.dto;
|
||||||
|
|
||||||
|
import com.worlabel.domain.project.entity.Project;
|
||||||
|
import com.worlabel.domain.project.entity.ProjectType;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Schema(name = "프로젝트 디테일 응답 dto", description = "프로젝트 디테일 응답 DTO")
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
|
public class ProjectWithThumbnailResponse {
|
||||||
|
|
||||||
|
@Schema(description = "워크스페이스 ID", example = "1")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@Schema(description = "제목", example = "project")
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@Schema(description = "워크스페이스 id", example = "1")
|
||||||
|
private Integer workspaceId;
|
||||||
|
|
||||||
|
@Schema(description = "프로젝트 타입", example = "classification")
|
||||||
|
private ProjectType projectType;
|
||||||
|
|
||||||
|
@Schema(description = "생성일시", example = "2024-07-25 17:51:02")
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
|
@Schema(description = "수정일시", example = "2024-07-28 17:51:02")
|
||||||
|
private LocalDateTime updatedAt;
|
||||||
|
|
||||||
|
@Schema(description = "썸네일", example = "test.jpg")
|
||||||
|
private String thumbnail;
|
||||||
|
|
||||||
|
public static ProjectWithThumbnailResponse from(final Project project, final String thumbnail) {
|
||||||
|
return new ProjectWithThumbnailResponse(
|
||||||
|
project.getId(),
|
||||||
|
project.getTitle(),
|
||||||
|
project.getWorkspace().getId(),
|
||||||
|
project.getProjectType(),
|
||||||
|
project.getCreatedAt(),
|
||||||
|
project.getUpdatedAt(),
|
||||||
|
thumbnail
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -25,6 +25,7 @@ import com.worlabel.domain.project.entity.Project;
|
|||||||
import com.worlabel.domain.project.entity.dto.ProjectMemberResponse;
|
import com.worlabel.domain.project.entity.dto.ProjectMemberResponse;
|
||||||
import com.worlabel.domain.project.entity.dto.ProjectRequest;
|
import com.worlabel.domain.project.entity.dto.ProjectRequest;
|
||||||
import com.worlabel.domain.project.entity.dto.ProjectResponse;
|
import com.worlabel.domain.project.entity.dto.ProjectResponse;
|
||||||
|
import com.worlabel.domain.project.entity.dto.ProjectWithThumbnailResponse;
|
||||||
import com.worlabel.domain.project.repository.ProjectRepository;
|
import com.worlabel.domain.project.repository.ProjectRepository;
|
||||||
import com.worlabel.domain.workspace.entity.Workspace;
|
import com.worlabel.domain.workspace.entity.Workspace;
|
||||||
import com.worlabel.domain.workspace.repository.WorkspaceRepository;
|
import com.worlabel.domain.workspace.repository.WorkspaceRepository;
|
||||||
@ -42,6 +43,7 @@ import java.lang.reflect.Type;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@ -81,9 +83,9 @@ public class ProjectService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
public List<ProjectResponse> getProjectsByWorkspaceId(final Integer workspaceId, final Integer memberId, final Integer lastProjectId, final Integer pageSize) {
|
public List<ProjectWithThumbnailResponse> getProjectsByWorkspaceId(final Integer workspaceId, final Integer memberId, final Integer lastProjectId, final Integer pageSize) {
|
||||||
return projectRepository.findProjectsByWorkspaceIdAndMemberIdWithPagination(workspaceId, memberId, lastProjectId, pageSize).stream()
|
return projectRepository.findProjectsByWorkspaceIdAndMemberIdWithPagination(workspaceId, memberId, lastProjectId, pageSize).stream()
|
||||||
.map(ProjectResponse::from)
|
.map(project -> ProjectWithThumbnailResponse.from(project, getFirstImageWithProject(project)))
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,4 +251,13 @@ public class ProjectService {
|
|||||||
throw new CustomException(ErrorCode.PARTICIPANT_BAD_REQUEST);
|
throw new CustomException(ErrorCode.PARTICIPANT_BAD_REQUEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getFirstImageWithProject(final Project project) {
|
||||||
|
Optional<Image> image = imageRepository.findFirstImageByProjectId(project.getId());
|
||||||
|
if (image.isPresent()) {
|
||||||
|
return image.get().getImagePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
return "https://www.shoshinsha-design.com/wp-content/uploads/2020/05/noimage-760x460.png";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user