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

update api for single html page #294

Merged
merged 4 commits into from
Jul 14, 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 @@ -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.UpdateSingleReq
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: UpdateSingleReq,
@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 Expand Up @@ -95,6 +105,14 @@ class AcademicsController(
return ResponseEntity.ok(academicsService.readDegreeRequirements(language))
}

@AuthenticatedStaff
@PutMapping("/undergraduate/degree-requirements")
fun updateDegreeRequirements(
@RequestParam(required = false, defaultValue = "ko") language: String,
@RequestPart request: UpdateSingleReq,
@RequestPart newAttachments: List<MultipartFile>?
) = academicsService.updateDegreeRequirements(language, request, newAttachments)

@AuthenticatedStaff
@PostMapping("/{studentType}/scholarshipDetail")
fun createScholarshipDetail(
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 UpdateSingleReq(
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.UpdateSingleReq
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 @@ -29,6 +30,7 @@ interface AcademicsService {

fun readGeneralStudiesRequirements(language: String): GeneralStudiesRequirementsPageResponse
fun readDegreeRequirements(language: String): DegreeRequirementsPageResponse
fun updateDegreeRequirements(language: String, request: UpdateSingleReq, newAttachments: List<MultipartFile>?)
fun createCourse(
studentType: String,
request: CourseDto,
Expand All @@ -44,6 +46,12 @@ interface AcademicsService {

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

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

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

val academicsEntity =
academicsRepository.findByLanguageAndStudentTypeAndPostType(
languageType,
enumStudentType,
AcademicsPostType.GUIDE
)

academicsEntity.description = request.description
academicsEntity.academicsSearch?.update(academicsEntity) ?: let {
academicsEntity.academicsSearch = AcademicsSearchEntity.create(academicsEntity)
}

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

@Transactional(readOnly = true)
override fun readAcademicsYearResponses(
language: String,
Expand Down Expand Up @@ -162,6 +198,32 @@ class AcademicsServiceImpl(
return DegreeRequirementsPageResponse.of(academicsEntity, attachments)
}

@Transactional
override fun updateDegreeRequirements(
language: String,
request: UpdateSingleReq,
newAttachments: List<MultipartFile>?
) {
val enumLanguageType = LanguageType.makeStringToLanguageType(language)

val academicsEntity =
academicsRepository.findByLanguageAndStudentTypeAndPostType(
enumLanguageType,
AcademicsStudentType.UNDERGRADUATE,
AcademicsPostType.DEGREE_REQUIREMENTS
)

academicsEntity.description = request.description
academicsEntity.academicsSearch?.update(academicsEntity) ?: let {
academicsEntity.academicsSearch = AcademicsSearchEntity.create(academicsEntity)
}

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

@Transactional
override fun createCourse(
studentType: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ interface AttachmentService {
contentEntityType: AttachmentContentEntityType,
requestAttachments: List<MultipartFile>
): List<AttachmentDto>

fun createOneAttachmentResponse(attachment: AttachmentEntity?): AttachmentResponse?
fun createAttachmentResponses(attachments: List<AttachmentEntity>?): List<AttachmentResponse>

fun deleteAttachment(attachment: AttachmentEntity)
fun deleteAttachments(ids: List<Long>?)
fun deleteAttachmentsDeprecated(ids: List<Long>?)
fun deleteAttachmentDeprecated(attachment: AttachmentEntity)
}
Expand Down Expand Up @@ -174,6 +176,17 @@ class AttachmentServiceImpl(
eventPublisher.publishEvent(FileDeleteEvent(fileDirectory))
}

@Transactional
override fun deleteAttachments(ids: List<Long>?) {
if (ids != null) {
for (id in ids) {
val attachment = attachmentRepository.findByIdOrNull(id)
?: throw CserealException.Csereal404("id:${id}인 첨부파일을 찾을 수 없습니다.")
deleteAttachment(attachment)
}
}
}

private fun connectAttachmentToEntity(contentEntity: AttachmentContentEntityType, attachment: AttachmentEntity) {
when (contentEntity) {
is NewsEntity -> {
Expand Down
Loading