Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: about에서 이미지랑 첨부파일 추가 #187

Merged
merged 7 commits into from
Feb 22, 2024
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 @@ -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
Loading