Skip to content

Commit

Permalink
Merge pull request #8 from PLADI-ALM/feat/PDS-119-update-material
Browse files Browse the repository at this point in the history
[PDS-119] 아카이빙 자료 이름 변경 API
  • Loading branch information
leeseunghakhello authored Oct 21, 2023
2 parents 1c17177 + 4c8a476 commit 195f496
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.example.PLADIALMArchiving.archiving.dto.request.RegisterProjectReq;
import com.example.PLADIALMArchiving.archiving.dto.request.SearchMaterialReq;
import com.example.PLADIALMArchiving.archiving.dto.request.UpdateMaterialReq;
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.service.ArchivingService;
import com.example.PLADIALMArchiving.global.exception.BaseException;
Expand Down Expand Up @@ -42,7 +44,7 @@ public class ArchivingController {
@ApiResponse(responseCode = "409", description = "(P0001)이미 등록된 프로젝트입니다.", content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
@ApiResponse(responseCode = "400", description = "(P0006)올바르지 않은 프로젝트 이름입니다. 다시 입력해주세요. (공백, 특수문자 제외 20자 이내)", content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
})
@PostMapping("/projects/register")
@PostMapping("/projects")
public ResponseCustom<?> registerProject(@RequestBody @Valid RegisterProjectReq registerProjectReq)
{
archivingService.registerProject(registerProjectReq);
Expand All @@ -59,7 +61,7 @@ public ResponseCustom<?> registerProject(@RequestBody @Valid RegisterProjectReq
@ApiResponse(responseCode = "403", description = "(G0002)접근권한이 없습니다.", content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
@ApiResponse(responseCode = "404", description = "(P0002)존재하지 않는 프로젝트입니다.", content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
})
@PostMapping("/projects/{projectId}/upload")
@PostMapping("/projects/{projectId}")
public ResponseCustom<?> uploadMaterial
(
@RequestBody @Valid UploadMaterialReq uploadMaterialReq,
Expand All @@ -84,7 +86,7 @@ public ResponseCustom<?> registerProject(@RequestBody @Valid RegisterProjectReq
@ApiResponse(responseCode = "404", description = "(P0002)존재하지 않는 프로젝트입니다.", content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
@ApiResponse(responseCode = "404", description = "(P0003)존재하지 않는 카테고리입니다.", content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
})
@PostMapping("/projects/{projectId}")
@GetMapping("/projects/{projectId}")
public ResponseCustom<Page<SearchMaterialRes>> searchMaterial
(
@Parameter(description = "(Long) 프로젝트 Id", example = "1") @PathVariable(name = "projectId") Long projectId,
Expand Down Expand Up @@ -125,9 +127,28 @@ public ResponseCustom<?> deleteMaterial(
@ApiResponse(responseCode = "404", description = "(P0004)존재하지 않는 자료입니다.", content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
})
@GetMapping("/materials/{materialId}")
public ResponseCustom<?> downloadMaterial(
public ResponseCustom<DownloadMaterialRes> downloadMaterial(
@Parameter(description = "(Long) 자원 Id", example = "15") @PathVariable(name = "materialId") Long materialId
) {
return ResponseCustom.OK(archivingService.downloadMaterial(materialId));
}

/**
* 자료 파일명을 변경한다.
*/
@Operation(summary = "자료 파일명 변경 (김민기)", description = "아카이빙 자료 파일명을 변경한다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "(S0001)요청에 성공했습니다."),
@ApiResponse(responseCode = "400", description = "(G0001)잘못된 요청입니다.", content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
@ApiResponse(responseCode = "404", description = "(P0004)존재하지 않는 자료입니다.", content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
})
@PatchMapping("/materials/{materialId}")
public ResponseCustom<?> updateMaterial(
@Parameter(description = "(Long) 자원 Id", example = "15") @PathVariable(name = "materialId") Long materialId,
@RequestBody @Valid UpdateMaterialReq updateMaterialReq
)
{
archivingService.updateMaterial(materialId, updateMaterialReq);
return ResponseCustom.OK();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.PLADIALMArchiving.archiving.dto.request;

import lombok.Getter;

@Getter
public class UpdateMaterialReq {
private String name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,8 @@ public static Material toEntity(UploadMaterialReq uploadMaterialReq, Project pro
.user(user)
.build();
}

public void update(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.example.PLADIALMArchiving.archiving.dto.request.RegisterProjectReq;
import com.example.PLADIALMArchiving.archiving.dto.request.SearchMaterialReq;
import com.example.PLADIALMArchiving.archiving.dto.request.UpdateMaterialReq;
import com.example.PLADIALMArchiving.archiving.dto.request.UploadMaterialReq;
import com.example.PLADIALMArchiving.archiving.dto.response.DownloadMaterialRes;
import com.example.PLADIALMArchiving.archiving.dto.response.SearchMaterialRes;
Expand Down Expand Up @@ -30,7 +31,6 @@
@RequiredArgsConstructor
public class ArchivingService {

private final UserRepository userRepository;
private final ProjectRepository projectRepository;
private final MaterialRepository materialRepository;

Expand Down Expand Up @@ -91,4 +91,10 @@ public DownloadMaterialRes downloadMaterial(Long materialsId) {
Material material = materialRepository.findById(materialsId).orElseThrow(() -> new BaseException(BaseResponseCode.MATERIAL_NOT_FOUND));
return DownloadMaterialRes.toDto(material.getFileKey());
}

@Transactional
public void updateMaterial(Long materialId, UpdateMaterialReq updateMaterialReq) {
Material material = materialRepository.findById(materialId).orElseThrow(() -> new BaseException(BaseResponseCode.MATERIAL_NOT_FOUND));
material.update(updateMaterialReq.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public enum BaseResponseCode {
MATERIAL_NOT_FOUND("P0004", HttpStatus.NOT_FOUND, "존재하지 않는 자료입니다."),
UNAUTHORIZED_USER("P0005", HttpStatus.UNAUTHORIZED, "관리자 계정 또는 자료를 업로드한 유저가 아니므로 자료를 삭제할 수 없습니다."),
INVALID_NAME("P0006", HttpStatus.BAD_REQUEST, "올바르지 않은 이름 형식입니다. 다시 입력해주세요. (공백, 특수문자 제외 20자 이내)"),
INVALID_UPLOAD_MATERIAL_REQUEST("P0007", HttpStatus.BAD_REQUEST, "부적절한 자료 업로드 요청입니다. 공백을 제외하고 다시 입력해주세요."),
INVALID_UPLOAD_MATERIAL_REQUEST("P0007", HttpStatus.BAD_REQUEST, "부적절한 자료 업로드 요청입니다. 공백및 특수문자를 제외하고 다시 입력해주세요."),
;

public final String code;
Expand Down

0 comments on commit 195f496

Please sign in to comment.