Skip to content

Commit

Permalink
학사 및 교과 연도별 api에 첨부파일 추가 (#329)
Browse files Browse the repository at this point in the history
* 학사 및 교과 연도별 api에 첨부파일 추가

* 오타 수정
  • Loading branch information
leeeryboy authored Nov 27, 2024
1 parent 731abc9 commit 3a7460b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.wafflestudio.csereal.core.academics.api.req

data class UpdateYearReq(
val description: String
val description: String,
val deleteIds: List<Long>? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ class AcademicsController(
@RequestParam(required = false, defaultValue = "ko") language: String,
@PathVariable studentType: String,
@PathVariable postType: String,
@RequestBody request: CreateYearReq
) = academicsService.createAcademicsYearResponse(language, studentType, postType, request)
@RequestPart request: CreateYearReq,
@RequestPart attachments: List<MultipartFile>?
) = academicsService.createAcademicsYearResponse(language, studentType, postType, request, attachments)

@AuthenticatedStaff
@PutMapping("/{studentType}/{postType}/{year}")
Expand All @@ -73,8 +74,9 @@ class AcademicsController(
@PathVariable studentType: String,
@PathVariable postType: String,
@PathVariable year: Int,
@RequestBody request: UpdateYearReq
) = academicsService.updateAcademicsYearResponse(language, studentType, postType, year, request)
@RequestPart request: UpdateYearReq,
@RequestPart newAttachments: List<MultipartFile>?
) = academicsService.updateAcademicsYearResponse(language, studentType, postType, year, request, newAttachments)

@AuthenticatedStaff
@DeleteMapping("/{studentType}/{postType}/{year}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,18 @@ interface AcademicsService {
studentType: String,
postType: String,
year: Int,
request: UpdateYearReq
request: UpdateYearReq,
newAttachments: List<MultipartFile>?
)

fun deleteAcademicsYearResponse(language: String, studentType: String, postType: String, year: Int)
fun createAcademicsYearResponse(language: String, studentType: String, postType: String, request: CreateYearReq)
fun createAcademicsYearResponse(
language: String,
studentType: String,
postType: String,
request: CreateYearReq,
attachments: List<MultipartFile>?
)
}

// TODO: add Update, Delete method
Expand Down Expand Up @@ -124,7 +131,8 @@ class AcademicsServiceImpl(
studentType: String,
postType: String,
year: Int,
request: UpdateYearReq
request: UpdateYearReq,
newAttachments: List<MultipartFile>?
) {
val languageType = LanguageType.makeStringToLanguageType(language)
val enumStudentType = makeStringToAcademicsStudentType(studentType)
Expand All @@ -141,6 +149,12 @@ class AcademicsServiceImpl(
academicsEntity.academicsSearch?.update(academicsEntity) ?: let {
academicsEntity.academicsSearch = AcademicsSearchEntity.create(academicsEntity)
}

attachmentService.deleteAttachments(request.deleteIds)

if (newAttachments != null) {
attachmentService.uploadAllAttachments(academicsEntity, newAttachments)
}
}

@Transactional
Expand All @@ -156,6 +170,7 @@ class AcademicsServiceImpl(
year
) ?: throw CserealException.Csereal404("AcademicsEntity Not Found")

attachmentService.deleteAttachments(academicsEntity.attachments.map { it.id })
academicsRepository.delete(academicsEntity)
}

Expand All @@ -164,7 +179,8 @@ class AcademicsServiceImpl(
language: String,
studentType: String,
postType: String,
request: CreateYearReq
request: CreateYearReq,
attachments: List<MultipartFile>?
) {
val languageType = LanguageType.makeStringToLanguageType(language)
val enumStudentType = makeStringToAcademicsStudentType(studentType)
Expand All @@ -186,6 +202,10 @@ class AcademicsServiceImpl(
academicsSearch = AcademicsSearchEntity.create(this)
}

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

academicsRepository.save(newAcademics)
}

Expand Down

0 comments on commit 3a7460b

Please sign in to comment.