Skip to content

Commit

Permalink
fix: research에서 isPublic 제거, feat: lab에서 attachments 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
skfotakf committed Sep 1, 2023
1 parent a1783da commit 069212e
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class StaffServiceImpl(
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 @@ -7,6 +7,7 @@ import com.wafflestudio.csereal.core.research.service.ResearchService
import jakarta.validation.Valid
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import org.springframework.web.multipart.MultipartFile

@RequestMapping("/api/v1/research")
@RestController
Expand Down Expand Up @@ -40,9 +41,10 @@ class ResearchController(

@PostMapping("/lab")
fun createLab(
@Valid @RequestBody request: LabDto
@Valid @RequestPart("request") request: LabDto,
@RequestPart("attachments") attachments: List<MultipartFile>?
) : ResponseEntity<LabDto> {
return ResponseEntity.ok(researchService.createLab(request))
return ResponseEntity.ok(researchService.createLab(request, attachments))
}

@GetMapping("/labs")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.wafflestudio.csereal.core.research.database

import com.wafflestudio.csereal.common.config.BaseTimeEntity
import com.wafflestudio.csereal.common.controller.AttachmentContentEntityType
import com.wafflestudio.csereal.core.member.database.ProfessorEntity
import com.wafflestudio.csereal.core.research.dto.LabDto
import com.wafflestudio.csereal.core.resource.attachment.database.AttachmentEntity
import jakarta.persistence.*

@Entity(name = "lab")
class LabEntity(

val name: String,

@OneToMany(mappedBy = "lab")
Expand All @@ -24,11 +25,13 @@ class LabEntity(
var research: ResearchEntity,

val description: String?,

val websiteURL: String?,
val isPublic: Boolean,

) : BaseTimeEntity() {
@OneToMany(mappedBy = "lab", cascade = [CascadeType.ALL], orphanRemoval = true)
var attachments: MutableList<AttachmentEntity> = mutableListOf(),

) : BaseTimeEntity(), AttachmentContentEntityType {
override fun bringAttachments() = attachments
companion object {
fun of(researchGroup: ResearchEntity, labDto: LabDto) : LabEntity {
return LabEntity(
Expand All @@ -41,7 +44,6 @@ class LabEntity(
research = researchGroup,
description = labDto.description,
websiteURL = labDto.websiteURL,
isPublic = labDto.isPublic,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ class ResearchEntity(
var postType: ResearchPostType,

var name: String,

var description: String?,

var websiteURL: String?,

var isPublic: Boolean,

@OneToMany(mappedBy = "research", cascade = [CascadeType.ALL], orphanRemoval = true)
var labs: MutableList<LabEntity> = mutableListOf()
): BaseTimeEntity() {
Expand All @@ -27,7 +23,6 @@ class ResearchEntity(
name = researchDto.name,
description = researchDto.description,
websiteURL = researchDto.websiteURL,
isPublic = researchDto.isPublic
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ data class LabDto(
val group: String,
val description: String?,
val websiteURL: String?,
val isPublic: Boolean,
) {
companion object {
fun of(entity: LabEntity): LabDto = entity.run {
Expand All @@ -29,7 +28,6 @@ data class LabDto(
group = this.research.name,
description = this.description,
websiteURL = this.websiteURL,
isPublic = this.isPublic
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ data class ResearchDto(
val websiteURL: String?,
val createdAt: LocalDateTime?,
val modifiedAt: LocalDateTime?,
val isPublic: Boolean,
val labsId: List<Long>?
) {
companion object {
Expand All @@ -25,7 +24,6 @@ data class ResearchDto(
websiteURL = this.websiteURL,
createdAt = this.createdAt,
modifiedAt = this.modifiedAt,
isPublic = this.isPublic,
labsId = this.labs.map { it.id }
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,27 @@ import com.wafflestudio.csereal.core.research.database.*
import com.wafflestudio.csereal.core.research.dto.LabDto
import com.wafflestudio.csereal.core.research.dto.ResearchDto
import com.wafflestudio.csereal.core.research.dto.ResearchGroupResponse
import com.wafflestudio.csereal.core.resource.attachment.service.AttachmentService
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import org.springframework.web.multipart.MultipartFile

interface ResearchService {
fun createResearchDetail(request: ResearchDto): ResearchDto
fun readAllResearchGroups(): ResearchGroupResponse
fun readAllResearchCenters(): List<ResearchDto>
fun updateResearchDetail(researchId: Long, request: ResearchDto): ResearchDto
fun createLab(request: LabDto): LabDto

fun createLab(request: LabDto, attachments: List<MultipartFile>?): LabDto
fun readAllLabs(): List<LabDto>
}

@Service
class ResearchServiceImpl(
private val researchRepository: ResearchRepository,
private val labRepository: LabRepository,
private val professorRepository: ProfessorRepository
private val professorRepository: ProfessorRepository,
private val attachmentService: AttachmentService,
) : ResearchService {
@Transactional
override fun createResearchDetail(request: ResearchDto): ResearchDto {
Expand Down Expand Up @@ -98,7 +100,7 @@ class ResearchServiceImpl(
}

@Transactional
override fun createLab(request: LabDto): LabDto {
override fun createLab(request: LabDto, attachments: List<MultipartFile>?): LabDto {
val researchGroup = researchRepository.findByName(request.group)
?: throw CserealException.Csereal404("해당 연구그룹을 찾을 수 없습니다.(researchGroupId = ${request.group}")

Expand All @@ -118,6 +120,14 @@ class ResearchServiceImpl(
*/
val newLab = LabEntity.of(researchGroup, request)

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

labRepository.save(newLab)

val attachments = attachmentService.createAttachments(newLab.attachments)

labRepository.save(newLab)
return LabDto.of(newLab)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.wafflestudio.csereal.core.about.database.AboutEntity
import com.wafflestudio.csereal.core.academics.database.AcademicsEntity
import com.wafflestudio.csereal.core.academics.database.CourseEntity
import com.wafflestudio.csereal.core.news.database.NewsEntity
import com.wafflestudio.csereal.core.research.database.LabEntity
import com.wafflestudio.csereal.core.seminar.database.SeminarEntity
import jakarta.persistence.*

Expand Down Expand Up @@ -37,6 +38,10 @@ class AttachmentEntity(
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "course_id")
var course: CourseEntity? = null,

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "lab_id")
var lab: LabEntity? = null,
) : BaseTimeEntity() {

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.wafflestudio.csereal.core.about.database.AboutEntity
import com.wafflestudio.csereal.core.academics.database.AcademicsEntity
import com.wafflestudio.csereal.core.academics.database.CourseEntity
import com.wafflestudio.csereal.core.news.database.NewsEntity
import com.wafflestudio.csereal.core.research.database.LabEntity
import com.wafflestudio.csereal.core.resource.attachment.database.AttachmentEntity
import com.wafflestudio.csereal.core.resource.attachment.database.AttachmentRepository
import com.wafflestudio.csereal.core.resource.attachment.dto.AttachmentDto
Expand Down Expand Up @@ -109,6 +110,10 @@ class AttachmentServiceImpl(
contentEntity.attachments.add(attachment)
attachment.course = contentEntity
}
is LabEntity -> {
contentEntity.attachments.add(attachment)
attachment.lab = contentEntity
}
}
}
}

0 comments on commit 069212e

Please sign in to comment.