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

학사 및 교과 연도별 api에 첨부파일 추가 #329

Merged
merged 2 commits into from
Nov 27, 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
@@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleteAttachmentIds 같이 네이밍만 명확하게 바꾸면 좋을듯!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 다른데서 이렇게 쓰고 있는데 찬솔이가 통일하는게 편하다했어서 일단 그대로 가야할듯..

)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 전체 v2로 옮기는거 나중에 한번 하면 좋을듯

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
Loading