Skip to content

Commit

Permalink
feat: about에서 이미지랑 첨부파일 추가 (#187)
Browse files Browse the repository at this point in the history
* feat: migrateProfessorImage 추가

* feat: migrateResearchImageAndAttachments 추가

* feat: migrateStaffImage 추가

* feat: migrateLabPdf 추가

* feat: about에서 이미지랑 첨부파일 추가
  • Loading branch information
skfotakf authored Feb 22, 2024
1 parent ccefb4e commit cb93db7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,15 @@ class AboutController(
): ResponseEntity<List<DirectionDto>> {
return ResponseEntity.ok(aboutService.migrateDirections(requestList))
}

@PatchMapping("/migrateImage/{aboutId}")
fun migrateAboutImageAndAttachment(
@PathVariable aboutId: Long,
@RequestPart("mainImage") mainImage: MultipartFile?,
@RequestPart("attachments") attachments: List<MultipartFile>?
): ResponseEntity<AboutDto> {
return ResponseEntity.ok(
aboutService.migrateAboutImageAndAttachments(aboutId, mainImage, attachments)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.wafflestudio.csereal.core.about.database.*
import com.wafflestudio.csereal.core.about.dto.*
import com.wafflestudio.csereal.core.resource.attachment.service.AttachmentService
import com.wafflestudio.csereal.core.resource.mainImage.service.MainImageService
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import org.springframework.web.multipart.MultipartFile
Expand All @@ -28,6 +29,11 @@ interface AboutService {
fun migrateStudentClubs(requestList: List<StudentClubDto>): List<StudentClubDto>
fun migrateFacilities(requestList: List<FacilityDto>): List<FacilityDto>
fun migrateDirections(requestList: List<DirectionDto>): List<DirectionDto>
fun migrateAboutImageAndAttachments(
aboutId: Long,
mainImage: MultipartFile?,
attachments: List<MultipartFile>?
): AboutDto
}

@Service
Expand Down Expand Up @@ -329,6 +335,25 @@ class AboutServiceImpl(
return list
}

@Transactional
override fun migrateAboutImageAndAttachments(
aboutId: Long,
mainImage: MultipartFile?,
attachments: List<MultipartFile>?
): AboutDto {
val about = aboutRepository.findByIdOrNull(aboutId)
?: throw CserealException.Csereal404("해당 소개는 존재하지 않습니다.")

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

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

return AboutDto.of(about, imageURL, attachmentResponses)
}

private fun makeStringToEnum(postType: String): AboutPostType {
try {
val upperPostType = postType.replace("-", "_").uppercase()
Expand Down

0 comments on commit cb93db7

Please sign in to comment.