Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,12 @@ class ProfessorController(
): ResponseEntity<List<ProfessorDto>> {
return ResponseEntity.ok(professorService.migrateProfessors(requestList))
}

@PatchMapping("/migragteImage/{professorId}")
fun migrateProfessorImage(
@PathVariable professorId: Long,
@RequestPart("mainImage") mainImage: MultipartFile
): ResponseEntity<ProfessorDto> {
return ResponseEntity.ok(professorService.migrateProfessorImage(professorId, mainImage))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface ProfessorService {
): ProfessorDto
fun deleteProfessor(professorId: Long)
fun migrateProfessors(requestList: List<ProfessorDto>): List<ProfessorDto>
fun migrateProfessorImage(professorId: Long, mainImage: MultipartFile): ProfessorDto
}

@Service
Expand Down Expand Up @@ -225,4 +226,16 @@ class ProfessorServiceImpl(
}
return list
}

@Transactional
override fun migrateProfessorImage(professorId: Long, mainImage: MultipartFile): ProfessorDto {
val professor = professorRepository.findByIdOrNull(professorId)
?: throw CserealException.Csereal404("해당 교수님을 찾을 수 없습니다. professorId: $professorId")

mainImageService.uploadMainImage(professor, mainImage)

val imageURL = mainImageService.createImageURL(professor.mainImage)

return ProfessorDto.of(professor, imageURL)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,31 @@ class ResearchController(
return ResponseEntity.ok(researchService.migrateLabs(requestList))
}

@PatchMapping("/migrateImageAndAttachments/{researchId}")
fun migrateResearchDetailImageAndAttachments(
@PathVariable researchId: Long,
@RequestPart("mainImage") mainImage: MultipartFile?,
@RequestPart("attachments") attachments: List<MultipartFile>?
): ResponseEntity<ResearchDto> {
return ResponseEntity.ok(
researchService.migrateResearchDetailImageAndAttachments(
researchId,
mainImage,
attachments
)
)
}

@PatchMapping("/lab/migratePdf/{labId}")
fun migrateLabPdf(
@PathVariable labId: Long,
@RequestPart("pdf") pdf: MultipartFile?
): ResponseEntity<LabDto> {
return ResponseEntity.ok(
researchService.migrateLabPdf(labId, pdf)
)
}

@GetMapping("/search/top")
fun searchTop(
@RequestParam(required = true) keyword: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ interface ResearchService {
fun updateLab(labId: Long, request: LabUpdateRequest, pdf: MultipartFile?): LabDto
fun migrateResearchDetail(requestList: List<ResearchDto>): List<ResearchDto>
fun migrateLabs(requestList: List<LabDto>): List<LabDto>
fun migrateResearchDetailImageAndAttachments(
researchId: Long,
mainImage: MultipartFile?,
attachments: List<MultipartFile>?
): ResearchDto
fun migrateLabPdf(labId: Long, pdf: MultipartFile?): LabDto
}

@Service
Expand Down Expand Up @@ -319,4 +325,41 @@ class ResearchServiceImpl(
}
return list
}

@Transactional
override fun migrateResearchDetailImageAndAttachments(
researchId: Long,
mainImage: MultipartFile?,
attachments: List<MultipartFile>?
): ResearchDto {
val researchDetail = researchRepository.findByIdOrNull(researchId)
?: throw CserealException.Csereal404("해당 연구내용을 찾을 수 없습니다.")

if (mainImage != null) {
mainImageService.uploadMainImage(researchDetail, mainImage)
}

if (attachments != null) {
attachmentService.uploadAllAttachments(researchDetail, attachments)
}

val imageURL = mainImageService.createImageURL(researchDetail.mainImage)
val attachmentResponses = attachmentService.createAttachmentResponses(researchDetail.attachments)

return ResearchDto.of(researchDetail, imageURL, attachmentResponses)
}

@Transactional
override fun migrateLabPdf(labId: Long, pdf: MultipartFile?): LabDto {
val lab = labRepository.findByIdOrNull(labId)
?: throw CserealException.Csereal404("해당 연구실을 찾을 수 없습니다.")

var pdfURL = ""
if (pdf != null) {
val attachmentDto = attachmentService.uploadAttachmentInLabEntity(lab, pdf)
pdfURL = "${endpointProperties.backend}/v1/file/${attachmentDto.filename}"
}

return LabDto.of(lab, pdfURL)
}
}