Skip to content

Commit

Permalink
feat: update guide
Browse files Browse the repository at this point in the history
  • Loading branch information
leeeryboy committed Jul 12, 2024
1 parent f7245a0 commit 30f494a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.wafflestudio.csereal.core.academics.api

import com.wafflestudio.csereal.common.aop.AuthenticatedStaff
import com.wafflestudio.csereal.common.enums.LanguageType
import com.wafflestudio.csereal.core.academics.api.req.UpdateGuideReq
import com.wafflestudio.csereal.core.academics.dto.*
import com.wafflestudio.csereal.core.academics.service.AcademicsService
import com.wafflestudio.csereal.core.academics.dto.ScholarshipDto
Expand Down Expand Up @@ -41,6 +42,15 @@ class AcademicsController(
return ResponseEntity.ok(academicsService.readGuide(language, studentType))
}

@AuthenticatedStaff
@PutMapping("/{studentType}/guide")
fun updateGuide(
@RequestParam(required = false, defaultValue = "ko") language: String,
@PathVariable studentType: String,
@RequestPart request: UpdateGuideReq,
@RequestPart newAttachments: List<MultipartFile>?
) = academicsService.updateGuide(language, studentType, request, newAttachments)

@GetMapping("/undergraduate/general-studies-requirements")
fun readGeneralStudiesRequirements(
@RequestParam(required = false, defaultValue = "ko") language: String
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.wafflestudio.csereal.core.academics.api.req

data class UpdateGuideReq(
val description: String,
val deleteIds: List<Long>
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.wafflestudio.csereal.core.academics.service

import com.wafflestudio.csereal.common.CserealException
import com.wafflestudio.csereal.common.enums.LanguageType
import com.wafflestudio.csereal.core.academics.api.req.UpdateGuideReq
import com.wafflestudio.csereal.core.academics.database.*
import com.wafflestudio.csereal.core.academics.dto.*
import com.wafflestudio.csereal.core.resource.attachment.service.AttachmentService
Expand Down Expand Up @@ -44,6 +45,12 @@ interface AcademicsService {

fun readAllScholarship(language: String, studentType: String): ScholarshipPageResponse
fun readScholarship(scholarshipId: Long): ScholarshipDto
fun updateGuide(
language: String,
studentType: String,
request: UpdateGuideReq,
newAttachments: List<MultipartFile>?
)
}

// TODO: add Update, Delete method
Expand Down Expand Up @@ -103,6 +110,29 @@ class AcademicsServiceImpl(
return GuidePageResponse.of(academicsEntity, attachmentResponses)
}

@Transactional
override fun updateGuide(
language: String,
studentType: String,
request: UpdateGuideReq,
newAttachments: List<MultipartFile>?
) {
val languageType = LanguageType.makeStringToLanguageType(language)
val enumStudentType = makeStringToAcademicsStudentType(studentType)

val academicsEntity =
academicsRepository.findByLanguageAndStudentTypeAndPostType(
languageType,
enumStudentType,
AcademicsPostType.GUIDE
)
academicsEntity.description = request.description
attachmentService.deleteAttachmentsDeprecated(request.deleteIds)
if (newAttachments != null) {
attachmentService.uploadAllAttachments(academicsEntity, newAttachments)
}
}

@Transactional(readOnly = true)
override fun readAcademicsYearResponses(
language: String,
Expand Down

0 comments on commit 30f494a

Please sign in to comment.