Skip to content

Commit

Permalink
Merge branch 'develop' into fix/get-notice
Browse files Browse the repository at this point in the history
  • Loading branch information
leeeryboy authored Sep 12, 2023
2 parents 1233bb3 + 33372fe commit dd8ab71
Show file tree
Hide file tree
Showing 21 changed files with 905 additions and 78 deletions.
2 changes: 1 addition & 1 deletion docker-compose-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
- 8080:8080
volumes:
- ./cse-files:/app/cse-files
- ./attachment:/app/attachment
- ./files:/app/files

environment:
SPRING_DATASOURCE_URL: "jdbc:mysql://host.docker.internal:3306/${MYSQL_DATABASE}?serverTimezone=Asia/Seoul&useSSL=false&allowPublicKeyRetrieval=true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.wafflestudio.csereal.core.conference.api

import com.wafflestudio.csereal.common.aop.AuthenticatedStaff
import com.wafflestudio.csereal.core.conference.dto.ConferenceModifyRequest
import com.wafflestudio.csereal.core.conference.dto.ConferencePage
import com.wafflestudio.csereal.core.conference.service.ConferenceService
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.*

@RequestMapping("/api/v1/conference")
@RestController
Expand All @@ -18,4 +18,15 @@ class ConferenceController(
return ResponseEntity.ok(conferenceService.getConferencePage())
}

@AuthenticatedStaff
@PatchMapping("/page/conferences")
fun modifyConferencePage(
@RequestBody conferenceModifyRequest: ConferenceModifyRequest
): ResponseEntity<ConferencePage> {
return ResponseEntity.ok(
conferenceService.modifyConferences(
conferenceModifyRequest
)
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.wafflestudio.csereal.core.conference.database

import com.wafflestudio.csereal.common.config.BaseTimeEntity
import com.wafflestudio.csereal.core.conference.dto.ConferenceCreateDto
import com.wafflestudio.csereal.core.conference.dto.ConferenceDto
import com.wafflestudio.csereal.core.research.database.ResearchSearchEntity
import jakarta.persistence.*

Expand All @@ -18,4 +20,21 @@ class ConferenceEntity(
@OneToOne(mappedBy = "conferenceElement", cascade = [CascadeType.ALL], orphanRemoval = true)
var researchSearch: ResearchSearchEntity? = null,
) : BaseTimeEntity() {
companion object {
fun of(
conferenceCreateDto: ConferenceCreateDto,
conferencePage: ConferencePageEntity,
) = ConferenceEntity(
code = conferenceCreateDto.code,
abbreviation = conferenceCreateDto.abbreviation,
name = conferenceCreateDto.name,
conferencePage = conferencePage,
)
}

fun update(conferenceDto: ConferenceDto) {
this.code = conferenceDto.code
this.abbreviation = conferenceDto.abbreviation
this.name = conferenceDto.name
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class ConferencePageEntity(

@OneToOne
@JoinColumn(name = "author_id")
val author: UserEntity,
var author: UserEntity,

@OneToMany(mappedBy = "conferencePage")
@OneToMany(mappedBy = "conferencePage", cascade = [CascadeType.ALL], orphanRemoval = true)
@OrderBy("code ASC")
val conferences: List<ConferenceEntity> = mutableListOf()
val conferences: MutableSet<ConferenceEntity> = mutableSetOf()

) : BaseTimeEntity()
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.wafflestudio.csereal.core.conference.database

import org.springframework.data.jpa.repository.JpaRepository

interface ConferenceRepository: JpaRepository<ConferenceEntity, Long>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.wafflestudio.csereal.core.conference.dto

data class ConferenceCreateDto (
val code: String,
val abbreviation: String,
val name: String,
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ package com.wafflestudio.csereal.core.conference.dto
import com.wafflestudio.csereal.core.conference.database.ConferenceEntity

data class ConferenceDto(
val id: Long,
val code: String,
val abbreviation: String,
val name: String
val name: String,
) {
companion object {
fun of(conferenceEntity: ConferenceEntity): ConferenceDto {
return ConferenceDto(
id = conferenceEntity.id,
code = conferenceEntity.code,
abbreviation = conferenceEntity.abbreviation,
name = conferenceEntity.name
name = conferenceEntity.name,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.wafflestudio.csereal.core.conference.dto

data class ConferenceModifyRequest(
val newConferenceList: List<ConferenceCreateDto>,
val modifiedConferenceList: List<ConferenceDto>,
val deleteConfereceIdList: List<Long>
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ data class ConferencePage(
createdAt = conferencePageEntity.createdAt!!,
modifiedAt = conferencePageEntity.modifiedAt!!,
author = conferencePageEntity.author.name,
conferenceList = conferencePageEntity.conferences.map { ConferenceDto.of(it) }
conferenceList = conferencePageEntity.conferences.map {
ConferenceDto.of(it)
}.sortedBy { it.code }
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
package com.wafflestudio.csereal.core.conference.service

import com.wafflestudio.csereal.common.CserealException
import com.wafflestudio.csereal.core.conference.database.ConferenceEntity
import com.wafflestudio.csereal.core.conference.database.ConferencePageEntity
import com.wafflestudio.csereal.core.conference.database.ConferencePageRepository
import com.wafflestudio.csereal.core.conference.database.ConferenceRepository
import com.wafflestudio.csereal.core.conference.dto.ConferenceCreateDto
import com.wafflestudio.csereal.core.conference.dto.ConferenceDto
import com.wafflestudio.csereal.core.conference.dto.ConferenceModifyRequest
import com.wafflestudio.csereal.core.conference.dto.ConferencePage
import com.wafflestudio.csereal.core.research.database.ResearchSearchEntity
import com.wafflestudio.csereal.core.research.service.ResearchSearchService
import com.wafflestudio.csereal.core.user.database.UserEntity
import com.wafflestudio.csereal.core.user.database.UserRepository
import org.springframework.data.repository.findByIdOrNull
import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.security.oauth2.core.oidc.user.OidcUser
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import org.springframework.web.context.request.RequestAttributes
import org.springframework.web.context.request.RequestContextHolder


interface ConferenceService {
fun getConferencePage(): ConferencePage
fun modifyConferences(conferenceModifyRequest: ConferenceModifyRequest): ConferencePage
}

@Service
@Transactional
class ConferenceServiceImpl(
private val conferencePageRepository: ConferencePageRepository
private val conferencePageRepository: ConferencePageRepository,
private val conferenceRepository: ConferenceRepository,
private val userRepository: UserRepository,
private val researchSearchService: ResearchSearchService,
) : ConferenceService {

@Transactional(readOnly = true)
Expand All @@ -23,4 +42,84 @@ class ConferenceServiceImpl(
return ConferencePage.of(conferencePage)
}

}
@Transactional
override fun modifyConferences(conferenceModifyRequest: ConferenceModifyRequest): ConferencePage {
var user = RequestContextHolder.getRequestAttributes()?.getAttribute(
"loggedInUser",
RequestAttributes.SCOPE_REQUEST
) as UserEntity?

if (user == null) {
val oidcUser = SecurityContextHolder.getContext().authentication.principal as OidcUser
val username = oidcUser.idToken.getClaim<String>("username")

user = userRepository.findByUsername(username) ?: throw CserealException.Csereal404("재로그인이 필요합니다.")
}

val conferencePage = conferencePageRepository.findAll()[0]

val newConferenceList = conferenceModifyRequest.newConferenceList.map {
createConferenceWithoutSave(it, conferencePage)
}

val modifiedConferenceList = conferenceModifyRequest.modifiedConferenceList.map {
modifyConferenceWithoutSave(it)
}

val deleteConferenceList = conferenceModifyRequest.deleteConfereceIdList.map {
deleteConference(it, conferencePage)
}

conferencePage.author = user

return ConferencePage.of(conferencePage)
}

@Transactional
fun createConferenceWithoutSave(
conferenceCreateDto: ConferenceCreateDto,
conferencePage: ConferencePageEntity,
): ConferenceEntity {
val newConference = ConferenceEntity.of(
conferenceCreateDto,
conferencePage
)
conferencePage.conferences.add(newConference)

newConference.researchSearch = ResearchSearchEntity.create(newConference)

return newConference
}

@Transactional
fun modifyConferenceWithoutSave(
conferenceDto: ConferenceDto,
): ConferenceEntity {
val conferenceEntity = conferenceRepository.findByIdOrNull(conferenceDto.id)
?: throw CserealException.Csereal404("Conference id:${conferenceDto.id} 가 존재하지 않습니다.")

conferenceEntity.update(conferenceDto)

conferenceEntity.researchSearch?.update(conferenceEntity)
?: let {
conferenceEntity.researchSearch = ResearchSearchEntity.create(conferenceEntity)
}

return conferenceEntity
}

@Transactional
fun deleteConference(
id: Long,
conferencePage: ConferencePageEntity,
) = conferenceRepository.findByIdOrNull(id)
?. let {
it.isDeleted = true
conferencePage.conferences.remove(it)

it.researchSearch?.let {
researchSearchService.deleteResearchSearch(it)
}
it.researchSearch = null
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.wafflestudio.csereal.core.research.api

import com.wafflestudio.csereal.common.aop.AuthenticatedStaff
import com.wafflestudio.csereal.core.research.dto.LabDto
import com.wafflestudio.csereal.core.research.dto.LabUpdateRequest
import com.wafflestudio.csereal.core.research.dto.ResearchDto
import com.wafflestudio.csereal.core.research.dto.ResearchGroupResponse
import com.wafflestudio.csereal.core.research.service.ResearchService
Expand Down Expand Up @@ -62,4 +64,17 @@ class ResearchController(
): ResponseEntity<LabDto> {
return ResponseEntity.ok(researchService.readLab(labId))
}

/**
* Research Group 수정은 일단 제외하였음.
*/
@AuthenticatedStaff
@PatchMapping("/lab/{labId}")
fun updateLab(
@PathVariable labId: Long,
@Valid @RequestPart("request") request: LabUpdateRequest,
@RequestPart("pdf") pdf: MultipartFile?
): ResponseEntity<LabDto> {
return ResponseEntity.ok(researchService.updateLab(labId, request, pdf))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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.research.dto.LabUpdateRequest
import com.wafflestudio.csereal.core.resource.attachment.database.AttachmentEntity
import jakarta.persistence.*

Expand Down Expand Up @@ -48,4 +49,14 @@ class LabEntity(
)
}
}

fun updateWithoutProfessor(labUpdateRequest: LabUpdateRequest) {
this.name = labUpdateRequest.name
this.location = labUpdateRequest.location
this.tel = labUpdateRequest.tel
this.acronym = labUpdateRequest.acronym
this.youtube = labUpdateRequest.youtube
this.description = labUpdateRequest.description
this.websiteURL = labUpdateRequest.websiteURL
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.wafflestudio.csereal.core.research.dto

data class LabUpdateRequest(
val name: String,
val professorIds: List<Long>,
val location: String?,
val tel: String?,
val acronym: String?,
val youtube: String?,
val description: String?,
val websiteURL: String?,
val pdfModified: Boolean,
)
Loading

0 comments on commit dd8ab71

Please sign in to comment.