Skip to content

Commit

Permalink
Merge pull request #9 from PLADI-ALM/feat/PDS-135-search-projects
Browse files Browse the repository at this point in the history
[PDS-135] 아카이빙 프로젝트 목록 조회 API
  • Loading branch information
leeseunghakhello authored Oct 21, 2023
2 parents 195f496 + f13c1db commit dba3630
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.example.PLADIALMArchiving.archiving.dto.request.UploadMaterialReq;
import com.example.PLADIALMArchiving.archiving.dto.response.DownloadMaterialRes;
import com.example.PLADIALMArchiving.archiving.dto.response.SearchMaterialRes;
import com.example.PLADIALMArchiving.archiving.dto.response.SearchProjectRes;
import com.example.PLADIALMArchiving.archiving.service.ArchivingService;
import com.example.PLADIALMArchiving.global.exception.BaseException;
import com.example.PLADIALMArchiving.global.exception.BaseResponseCode;
Expand Down Expand Up @@ -80,6 +81,7 @@ public ResponseCustom<?> registerProject(@RequestBody @Valid RegisterProjectReq
/**
* 자료목록을 조회 및 검색한다.
*/
// todo 이름, 게시일 오름차순 내림차순 정렬 구현 필요
@Operation(summary = "자료목록 조회 및 검색 (김민기)", description = "아카이빙 자료목록을 조회 및 검색한다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "(S0001)요청에 성공했습니다."),
Expand Down Expand Up @@ -151,4 +153,19 @@ public ResponseCustom<?> updateMaterial(
archivingService.updateMaterial(materialId, updateMaterialReq);
return ResponseCustom.OK();
}

/**
* 프로젝트 목록을 조회한다.
*/
@Operation(summary = "프로젝트 목록 조회 (김민기)", description = "아카이빙 프로젝트 목록을 조회한다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "(S0001)요청에 성공했습니다."),
})
@GetMapping("/projects")
public ResponseCustom<Page<SearchProjectRes>> searchProject(
Pageable pageable
)
{
return ResponseCustom.OK(archivingService.searchProject(pageable));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.PLADIALMArchiving.archiving.dto.response;

import com.example.PLADIALMArchiving.archiving.entity.Project;
import com.example.PLADIALMArchiving.global.Constants;
import lombok.Builder;
import lombok.Data;

import java.time.format.DateTimeFormatter;

@Data
public class SearchProjectRes {
private Long projectId;
private String projectName;
private String createdAt;

@Builder
public SearchProjectRes(Long projectId, String projectName, String createdAt) {
this.projectId = projectId;
this.projectName = projectName;
this.createdAt = createdAt;
}

public static SearchProjectRes toDto(Project project) {
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(Constants.DATE_PATTERN);
return SearchProjectRes.builder()
.projectId(project.getProjectId())
.projectName(project.getName())
.createdAt(project.getCreatedAt().format(dateTimeFormatter))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.example.PLADIALMArchiving.archiving.dto.request.UploadMaterialReq;
import com.example.PLADIALMArchiving.archiving.dto.response.DownloadMaterialRes;
import com.example.PLADIALMArchiving.archiving.dto.response.SearchMaterialRes;
import com.example.PLADIALMArchiving.archiving.dto.response.SearchProjectRes;
import com.example.PLADIALMArchiving.archiving.entity.Category;
import com.example.PLADIALMArchiving.archiving.entity.Material;
import com.example.PLADIALMArchiving.archiving.entity.Project;
Expand Down Expand Up @@ -97,4 +98,9 @@ public void updateMaterial(Long materialId, UpdateMaterialReq updateMaterialReq)
Material material = materialRepository.findById(materialId).orElseThrow(() -> new BaseException(BaseResponseCode.MATERIAL_NOT_FOUND));
material.update(updateMaterialReq.getName());
}

public Page<SearchProjectRes> searchProject(Pageable pageable) {
Page<Project> all = projectRepository.findAll(pageable);
return all.map(SearchProjectRes::toDto);
}
}

0 comments on commit dba3630

Please sign in to comment.