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

fix: research 패키지 프론트에 맞춰 협의 #52

Merged
merged 10 commits into from
Sep 2, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package com.wafflestudio.csereal.common.controller

import com.wafflestudio.csereal.core.resource.mainImage.database.MainImageEntity

interface ImageContentEntityType {
interface MainImageContentEntityType {
fun bringMainImage(): MainImageEntity?
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.wafflestudio.csereal.core.about.database

import com.wafflestudio.csereal.common.config.BaseTimeEntity
import com.wafflestudio.csereal.common.controller.AttachmentContentEntityType
import com.wafflestudio.csereal.common.controller.ImageContentEntityType
import com.wafflestudio.csereal.common.controller.MainImageContentEntityType
import com.wafflestudio.csereal.core.about.dto.AboutDto
import com.wafflestudio.csereal.core.resource.attachment.database.AttachmentEntity
import com.wafflestudio.csereal.core.resource.mainImage.database.MainImageEntity
Expand All @@ -26,7 +26,7 @@ class AboutEntity(
@OneToOne
var mainImage: MainImageEntity? = null,

) : BaseTimeEntity(), ImageContentEntityType, AttachmentContentEntityType {
) : BaseTimeEntity(), MainImageContentEntityType, AttachmentContentEntityType {
override fun bringMainImage(): MainImageEntity? = mainImage
override fun bringAttachments(): List<AttachmentEntity> = attachments

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ data class AboutDto(
val attachments: List<AttachmentResponse>?,
) {
companion object {
fun of(entity: AboutEntity, imageURL: String?, attachments: List<AttachmentResponse>?) : AboutDto = entity.run {
fun of(entity: AboutEntity, imageURL: String?, attachmentResponses: List<AttachmentResponse>) : AboutDto = entity.run {
AboutDto(
id = this.id,
name = this.name,
Expand All @@ -29,7 +29,7 @@ data class AboutDto(
modifiedAt = this.modifiedAt,
locations = this.locations.map { it.name },
imageURL = imageURL,
attachments = attachments,
attachments = attachmentResponses,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,33 @@ class AboutServiceImpl(
}

if(attachments != null) {
attachmentService.uploadAttachments(newAbout, attachments)
attachmentService.uploadAllAttachments(newAbout, attachments)
}
aboutRepository.save(newAbout)

val imageURL = mainImageService.createImageURL(newAbout.mainImage)
val attachments = attachmentService.createAttachments(newAbout.attachments)
val attachmentResponses = attachmentService.createAttachmentResponses(newAbout.attachments)

return AboutDto.of(newAbout, imageURL, attachments)
return AboutDto.of(newAbout, imageURL, attachmentResponses)
}

@Transactional(readOnly = true)
override fun readAbout(postType: String): AboutDto {
val enumPostType = makeStringToEnum(postType)
val about = aboutRepository.findByPostType(enumPostType)
val imageURL = mainImageService.createImageURL(about.mainImage)
val attachments = attachmentService.createAttachments(about.attachments)
val attachmentResponses = attachmentService.createAttachmentResponses(about.attachments)


return AboutDto.of(about, imageURL, attachments)
return AboutDto.of(about, imageURL, attachmentResponses)
}

@Transactional(readOnly = true)
override fun readAllClubs(): List<AboutDto> {
val clubs = aboutRepository.findAllByPostTypeOrderByName(AboutPostType.STUDENT_CLUBS).map {
val imageURL = mainImageService.createImageURL(it.mainImage)
val attachments = attachmentService.createAttachments(it.attachments)
AboutDto.of(it, imageURL, attachments)
val attachmentResponses = attachmentService.createAttachmentResponses(it.attachments)
AboutDto.of(it, imageURL, attachmentResponses)
}

return clubs
Expand All @@ -78,8 +78,8 @@ class AboutServiceImpl(
override fun readAllFacilities(): List<AboutDto> {
val facilities = aboutRepository.findAllByPostTypeOrderByName(AboutPostType.FACILITIES).map {
val imageURL = mainImageService.createImageURL(it.mainImage)
val attachments = attachmentService.createAttachments(it.attachments)
AboutDto.of(it, imageURL, attachments)
val attachmentResponses = attachmentService.createAttachmentResponses(it.attachments)
AboutDto.of(it, imageURL, attachmentResponses)
}

return facilities
Expand All @@ -89,7 +89,7 @@ class AboutServiceImpl(
override fun readAllDirections(): List<AboutDto> {
val directions = aboutRepository.findAllByPostTypeOrderByName(AboutPostType.DIRECTIONS).map {
val imageURL = mainImageService.createImageURL(it.mainImage)
val attachments = attachmentService.createAttachments(it.attachments)
val attachments = attachmentService.createAttachmentResponses(it.attachments)
AboutDto.of(it, imageURL, attachments)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ data class AcademicsDto(
val attachments: List<AttachmentResponse>?,
) {
companion object {
fun of(entity: AcademicsEntity, attachments: List<AttachmentResponse>?) : AcademicsDto = entity.run {
fun of(entity: AcademicsEntity, attachmentResponses: List<AttachmentResponse>) : AcademicsDto = entity.run {
AcademicsDto(
id = this.id,
name = this.name,
description = this.description,
year = this.year,
createdAt = this.createdAt,
modifiedAt = this.modifiedAt,
attachments = attachments,
attachments = attachmentResponses,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ class AcademicsServiceImpl(
val newAcademics = AcademicsEntity.of(enumStudentType, enumPostType, request)

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

academicsRepository.save(newAcademics)

val attachments = attachmentService.createAttachments(newAcademics.attachments)
val attachmentResponses = attachmentService.createAttachmentResponses(newAcademics.attachments)


return AcademicsDto.of(newAcademics, attachments)
return AcademicsDto.of(newAcademics, attachmentResponses)
}

@Transactional(readOnly = true)
Expand All @@ -56,9 +56,9 @@ class AcademicsServiceImpl(

val academics = academicsRepository.findByStudentTypeAndPostType(enumStudentType, enumPostType)

val attachments = attachmentService.createAttachments(academics.attachments)
val attachmentResponses = attachmentService.createAttachmentResponses(academics.attachments)

return AcademicsDto.of(academics, attachments)
return AcademicsDto.of(academics, attachmentResponses)
}

@Transactional
Expand All @@ -68,28 +68,28 @@ class AcademicsServiceImpl(

courseRepository.save(course)

val attachments = attachmentService.createAttachments(course.attachments)
val attachmentResponses = attachmentService.createAttachmentResponses(course.attachments)

return CourseDto.of(course, attachments)
return CourseDto.of(course, attachmentResponses)
}

@Transactional(readOnly = true)
override fun readAllCourses(studentType: String): List<CourseDto> {
val enumStudentType = makeStringToAcademicsStudentType(studentType)

val courseDtoList = courseRepository.findAllByStudentTypeOrderByNameAsc(enumStudentType).map {
val attachments = attachmentService.createAttachments(it.attachments)
CourseDto.of(it, attachments)
val attachmentResponses = attachmentService.createAttachmentResponses(it.attachments)
CourseDto.of(it, attachmentResponses)
}
return courseDtoList
}

@Transactional(readOnly = true)
override fun readCourse(name: String): CourseDto {
val course = courseRepository.findByName(name)
val attachments = attachmentService.createAttachments(course.attachments)
val attachmentResponses = attachmentService.createAttachmentResponses(course.attachments)

return CourseDto.of(course, attachments)
return CourseDto.of(course, attachmentResponses)
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ class ProfessorController(
@PatchMapping("/{professorId}")
fun updateProfessor(
@PathVariable professorId: Long,
@RequestBody updateProfessorRequest: ProfessorDto
@RequestPart("request") updateProfessorRequest: ProfessorDto,
@RequestPart("mainImage") mainImage: MultipartFile?,
): ResponseEntity<ProfessorDto> {
return ResponseEntity.ok(professorService.updateProfessor(professorId, updateProfessorRequest))
return ResponseEntity.ok(professorService.updateProfessor(professorId, updateProfessorRequest, mainImage))
}

@DeleteMapping("/{professorId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ class StaffController(
return ResponseEntity.ok(staffService.getAllStaff())
}

@PatchMapping("/{staffId}")
fun updateStaff(@PathVariable staffId: Long, @RequestBody updateStaffRequest: StaffDto): ResponseEntity<StaffDto> {
return ResponseEntity.ok(staffService.updateStaff(staffId, updateStaffRequest))
fun updateStaff(
@PathVariable staffId: Long,
@RequestPart("request") updateStaffRequest: StaffDto,
@RequestPart("mainImage") mainImage: MultipartFile?,
): ResponseEntity<StaffDto> {
return ResponseEntity.ok(staffService.updateStaff(staffId, updateStaffRequest, mainImage))
}

@DeleteMapping("/{staffId}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.wafflestudio.csereal.core.member.database

import com.wafflestudio.csereal.common.config.BaseTimeEntity
import com.wafflestudio.csereal.common.controller.ImageContentEntityType
import com.wafflestudio.csereal.common.controller.MainImageContentEntityType
import com.wafflestudio.csereal.core.member.dto.ProfessorDto
import com.wafflestudio.csereal.core.research.database.LabEntity
import com.wafflestudio.csereal.core.resource.mainImage.database.MainImageEntity
Expand Down Expand Up @@ -44,7 +44,7 @@ class ProfessorEntity(
@OneToOne
var mainImage: MainImageEntity? = null,

) : BaseTimeEntity(), ImageContentEntityType {
) : BaseTimeEntity(), MainImageContentEntityType {
override fun bringMainImage(): MainImageEntity? = mainImage

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.wafflestudio.csereal.core.member.database

import com.wafflestudio.csereal.common.config.BaseTimeEntity
import com.wafflestudio.csereal.common.controller.ImageContentEntityType
import com.wafflestudio.csereal.common.controller.MainImageContentEntityType
import com.wafflestudio.csereal.core.member.dto.StaffDto
import com.wafflestudio.csereal.core.resource.mainImage.database.MainImageEntity
import jakarta.persistence.CascadeType
Expand All @@ -24,7 +24,7 @@ class StaffEntity(
@OneToOne
var mainImage: MainImageEntity? = null,

) : BaseTimeEntity(), ImageContentEntityType {
) : BaseTimeEntity(), MainImageContentEntityType {
override fun bringMainImage(): MainImageEntity? = mainImage

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface ProfessorService {
fun getProfessor(professorId: Long): ProfessorDto
fun getActiveProfessors(): ProfessorPageDto
fun getInactiveProfessors(): List<SimpleProfessorDto>
fun updateProfessor(professorId: Long, updateProfessorRequest: ProfessorDto): ProfessorDto
fun updateProfessor(professorId: Long, updateProfessorRequest: ProfessorDto, mainImage: MultipartFile?): ProfessorDto
fun deleteProfessor(professorId: Long)
}

Expand Down Expand Up @@ -94,8 +94,7 @@ class ProfessorServiceImpl(
.sortedBy { it.name }
}

override fun updateProfessor(professorId: Long, updateProfessorRequest: ProfessorDto): ProfessorDto {

override fun updateProfessor(professorId: Long, updateProfessorRequest: ProfessorDto, mainImage: MultipartFile?): ProfessorDto {
val professor = professorRepository.findByIdOrNull(professorId)
?: throw CserealException.Csereal404("해당 교수님을 찾을 수 없습니다. professorId: ${professorId}")

Expand All @@ -107,6 +106,10 @@ class ProfessorServiceImpl(

professor.update(updateProfessorRequest)

if(mainImage != null) {
mainImageService.uploadMainImage(professor, mainImage)
}

// 학력 업데이트
val oldEducations = professor.educations.map { it.name }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface StaffService {
fun createStaff(createStaffRequest: StaffDto, mainImage: MultipartFile?): StaffDto
fun getStaff(staffId: Long): StaffDto
fun getAllStaff(): List<SimpleStaffDto>
fun updateStaff(staffId: Long, updateStaffRequest: StaffDto): StaffDto
fun updateStaff(staffId: Long, updateStaffRequest: StaffDto, mainImage: MultipartFile?): StaffDto
fun deleteStaff(staffId: Long)
}

Expand Down Expand Up @@ -62,13 +62,16 @@ class StaffServiceImpl(
}.sortedBy { it.name }
}

override fun updateStaff(staffId: Long, updateStaffRequest: StaffDto): StaffDto {

override fun updateStaff(staffId: Long, updateStaffRequest: StaffDto, mainImage: MultipartFile?): StaffDto {
val staff = staffRepository.findByIdOrNull(staffId)
?: throw CserealException.Csereal404("해당 행정직원을 찾을 수 없습니다. staffId: ${staffId}")

staff.update(updateStaffRequest)

if(mainImage != null) {
mainImageService.uploadMainImage(staff, mainImage)
}

// 주요 업무 업데이트
val oldTasks = staff.tasks.map { it.name }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.wafflestudio.csereal.core.news.database

import com.wafflestudio.csereal.common.config.BaseTimeEntity
import com.wafflestudio.csereal.common.controller.AttachmentContentEntityType
import com.wafflestudio.csereal.common.controller.ImageContentEntityType
import com.wafflestudio.csereal.common.controller.MainImageContentEntityType
import com.wafflestudio.csereal.core.news.dto.NewsDto
import com.wafflestudio.csereal.core.resource.attachment.database.AttachmentEntity
import com.wafflestudio.csereal.core.resource.mainImage.database.MainImageEntity
Expand Down Expand Up @@ -30,7 +30,7 @@ class NewsEntity(
@OneToMany(mappedBy = "news", cascade = [CascadeType.ALL])
var newsTags: MutableSet<NewsTagEntity> = mutableSetOf()

): BaseTimeEntity(), ImageContentEntityType, AttachmentContentEntityType {
): BaseTimeEntity(), MainImageContentEntityType, AttachmentContentEntityType {
override fun bringMainImage() = mainImage
override fun bringAttachments() = attachments

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ data class NewsDto(
val attachments: List<AttachmentResponse>?,
) {
companion object {
fun of(entity: NewsEntity, imageURL: String?, attachments: List<AttachmentResponse>?, prevNext: Array<NewsEntity?>?) : NewsDto = entity.run {
fun of(entity: NewsEntity, imageURL: String?, attachmentResponses: List<AttachmentResponse>, prevNext: Array<NewsEntity?>?) : NewsDto = entity.run {
NewsDto(
id = this.id,
title = this.title,
Expand All @@ -36,7 +36,7 @@ data class NewsDto(
nextId = prevNext?.get(1)?.id,
nextTitle = prevNext?.get(1)?.title,
imageURL = imageURL,
attachments = attachments,
attachments = attachmentResponses,
)
}
}
Expand Down
Loading