Skip to content

Commit

Permalink
fix: research 패키지 프론트에 맞춰 협의 (#52)
Browse files Browse the repository at this point in the history
* fix: professor, staff에 uploadImage 추가

* fix: research에서 isPublic 제거, feat: lab에서 attachments 추가

* fix: attachments -> attachmentResponses 변경

* feat: LabProfessorResponse 추가

* fix: pdf를 list가 아닌 단일항목으로 수정

* feat: readLab 추가

* feat: ResearchLabReponse 추가 및 주석 삭제

* fix: researchDetail에 사진, 첨부파일 업로드 추가

* fix: pr 리뷰 수정

* fix: 오타 수정
  • Loading branch information
skfotakf authored Sep 2, 2023
1 parent 8b38588 commit 3565704
Show file tree
Hide file tree
Showing 30 changed files with 320 additions and 172 deletions.
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

0 comments on commit 3565704

Please sign in to comment.