Skip to content

Commit

Permalink
fix: 프론트랑 협의하여 내용 변경 + news, seminar에 image, attachments update 추가 (#51)
Browse files Browse the repository at this point in the history
* feat: attachments 추가, news request에 attachments 추가

* feat: seminar request에 attachments 추가

* feat: about request에 attachments 추가

* feat: academics request에 attachments 추가

* fix: isPinned 삭제

* fix: image -> mainImage 변경, about에 greetings 추가

* fix: news, seminar update 수정

* fix: 전체적으로 image -> mainImage 변경
  • Loading branch information
skfotakf authored Sep 1, 2023
1 parent b8fca73 commit 8b38588
Show file tree
Hide file tree
Showing 36 changed files with 282 additions and 207 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ class AboutController(
fun createAbout(
@PathVariable postType: String,
@Valid @RequestPart("request") request: AboutDto,
@RequestPart("image") image: MultipartFile?,
@RequestPart("mainImage") mainImage: MultipartFile?,
@RequestPart("attachments") attachments: List<MultipartFile>?,
) : ResponseEntity<AboutDto> {
return ResponseEntity.ok(aboutService.createAbout(postType, request, image))
return ResponseEntity.ok(aboutService.createAbout(postType, request, mainImage, attachments))
}

// read 목록이 하나
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
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.core.about.dto.AboutDto
import com.wafflestudio.csereal.core.resource.attachment.database.AttachmentEntity
import com.wafflestudio.csereal.core.resource.mainImage.database.MainImageEntity
import jakarta.persistence.*

Expand All @@ -18,11 +20,15 @@ class AboutEntity(
@OneToMany(mappedBy = "about", cascade = [CascadeType.ALL], orphanRemoval = true)
val locations: MutableList<LocationEntity> = mutableListOf(),

@OneToMany(mappedBy = "")
var attachments: MutableList<AttachmentEntity> = mutableListOf(),

@OneToOne
var mainImage: MainImageEntity? = null,

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

companion object {
fun of(postType: AboutPostType, aboutDto: AboutDto): AboutEntity {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.wafflestudio.csereal.core.about.database

enum class AboutPostType {
OVERVIEW, HISTORY, FUTURE_CAREERS, CONTACT, STUDENT_CLUBS, FACILITIES, DIRECTIONS,
OVERVIEW, GREETINGS, HISTORY, FUTURE_CAREERS, CONTACT, STUDENT_CLUBS, FACILITIES, DIRECTIONS,
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.wafflestudio.csereal.core.about.dto


import com.wafflestudio.csereal.core.about.database.AboutEntity
import com.wafflestudio.csereal.core.resource.attachment.dto.AttachmentResponse
import java.time.LocalDateTime

data class AboutDto(
Expand All @@ -13,10 +14,11 @@ data class AboutDto(
val createdAt: LocalDateTime?,
val modifiedAt: LocalDateTime?,
val locations: List<String>?,
val imageURL: String?
val imageURL: String?,
val attachments: List<AttachmentResponse>?,
) {
companion object {
fun of(entity: AboutEntity, imageURL: String?) : AboutDto = entity.run {
fun of(entity: AboutEntity, imageURL: String?, attachments: List<AttachmentResponse>?) : AboutDto = entity.run {
AboutDto(
id = this.id,
name = this.name,
Expand All @@ -26,7 +28,8 @@ data class AboutDto(
createdAt = this.createdAt,
modifiedAt = this.modifiedAt,
locations = this.locations.map { it.name },
imageURL = imageURL
imageURL = imageURL,
attachments = attachments,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import com.wafflestudio.csereal.core.about.database.AboutPostType
import com.wafflestudio.csereal.core.about.database.AboutRepository
import com.wafflestudio.csereal.core.about.database.LocationEntity
import com.wafflestudio.csereal.core.about.dto.AboutDto
import com.wafflestudio.csereal.core.resource.mainImage.service.ImageService
import com.wafflestudio.csereal.core.resource.attachment.service.AttachmentService
import com.wafflestudio.csereal.core.resource.mainImage.service.MainImageService
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import org.springframework.web.multipart.MultipartFile

interface AboutService {
fun createAbout(postType: String, request: AboutDto, image: MultipartFile?): AboutDto
fun createAbout(postType: String, request: AboutDto, mainImage: MultipartFile?, attachments: List<MultipartFile>?): AboutDto
fun readAbout(postType: String): AboutDto
fun readAllClubs() : List<AboutDto>
fun readAllFacilities() : List<AboutDto>
Expand All @@ -22,10 +23,11 @@ interface AboutService {
@Service
class AboutServiceImpl(
private val aboutRepository: AboutRepository,
private val imageService: ImageService,
private val mainImageService: MainImageService,
private val attachmentService: AttachmentService,
) : AboutService {
@Transactional
override fun createAbout(postType: String, request: AboutDto, image: MultipartFile?): AboutDto {
override fun createAbout(postType: String, request: AboutDto, mainImage: MultipartFile?, attachments: List<MultipartFile>?): AboutDto {
val enumPostType = makeStringToEnum(postType)
val newAbout = AboutEntity.of(enumPostType, request)

Expand All @@ -35,30 +37,38 @@ class AboutServiceImpl(
}
}

if(image != null) {
imageService.uploadImage(newAbout, image)
if(mainImage != null) {
mainImageService.uploadMainImage(newAbout, mainImage)
}

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

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

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

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


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

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

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

return facilities
Expand All @@ -77,8 +88,9 @@ class AboutServiceImpl(
@Transactional(readOnly = true)
override fun readAllDirections(): List<AboutDto> {
val directions = aboutRepository.findAllByPostTypeOrderByName(AboutPostType.DIRECTIONS).map {
val imageURL = imageService.createImageURL(it.mainImage)
AboutDto.of(it, imageURL)
val imageURL = mainImageService.createImageURL(it.mainImage)
val attachments = attachmentService.createAttachments(it.attachments)
AboutDto.of(it, imageURL, attachments)
}

return directions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@ import com.wafflestudio.csereal.core.academics.dto.ScholarshipPageResponse
import com.wafflestudio.csereal.core.academics.service.AcademicsService
import jakarta.validation.Valid
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.*
import org.springframework.web.multipart.MultipartFile

@RequestMapping("/api/v1/academics")
@RestController
Expand All @@ -25,9 +20,10 @@ class AcademicsController(
fun createAcademics(
@PathVariable studentType: String,
@PathVariable postType: String,
@Valid @RequestBody request: AcademicsDto
): ResponseEntity<AcademicsDto> {
return ResponseEntity.ok(academicsService.createAcademics(studentType, postType, request))
@Valid @RequestPart("request") request: AcademicsDto,
@RequestPart("attachments") attachments: List<MultipartFile>?
) : ResponseEntity<AcademicsDto> {
return ResponseEntity.ok(academicsService.createAcademics(studentType, postType, request, attachments))
}

@GetMapping("/{studentType}/{postType}")
Expand All @@ -42,9 +38,10 @@ class AcademicsController(
@PostMapping("/{studentType}/course")
fun createCourse(
@PathVariable studentType: String,
@Valid @RequestBody request: CourseDto
): ResponseEntity<CourseDto> {
return ResponseEntity.ok(academicsService.createCourse(studentType, request))
@Valid @RequestPart("request") request: CourseDto,
@RequestPart("attachments") attachments: List<MultipartFile>?,
) : ResponseEntity<CourseDto> {
return ResponseEntity.ok(academicsService.createCourse(studentType, request, attachments))
}

@GetMapping("/{studentType}/courses")
Expand All @@ -65,9 +62,10 @@ class AcademicsController(
@PostMapping("/{studentType}/scholarship")
fun createScholarship(
@PathVariable studentType: String,
@Valid @RequestBody request: AcademicsDto
): ResponseEntity<AcademicsDto> {
return ResponseEntity.ok(academicsService.createAcademics(studentType, "scholarship", request))
@Valid @RequestPart("request") request: AcademicsDto,
@RequestPart("attachments") attachments: List<MultipartFile>?,
) : ResponseEntity<AcademicsDto> {
return ResponseEntity.ok(academicsService.createAcademics(studentType, "scholarship", request, attachments))
}

@GetMapping("/scholarship")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.wafflestudio.csereal.core.academics.database

import com.wafflestudio.csereal.common.config.BaseTimeEntity
import com.wafflestudio.csereal.common.controller.AttachmentContentEntityType
import com.wafflestudio.csereal.core.academics.dto.AcademicsDto
import jakarta.persistence.Entity
import jakarta.persistence.EnumType
import jakarta.persistence.Enumerated
import com.wafflestudio.csereal.core.resource.attachment.database.AttachmentEntity
import jakarta.persistence.*

@Entity(name = "academics")
class AcademicsEntity(
Expand All @@ -17,9 +17,14 @@ class AcademicsEntity(
var name: String,
var description: String,
var year: Int?,
var isPublic: Boolean,

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


): BaseTimeEntity(), AttachmentContentEntityType {
override fun bringAttachments() = attachments

companion object {
fun of(studentType: AcademicsStudentType, postType: AcademicsPostType, academicsDto: AcademicsDto): AcademicsEntity {
return AcademicsEntity(
Expand All @@ -28,7 +33,6 @@ class AcademicsEntity(
name = academicsDto.name,
description = academicsDto.description,
year = academicsDto.year,
isPublic = academicsDto.isPublic,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package com.wafflestudio.csereal.core.academics.database

import com.wafflestudio.csereal.common.config.BaseTimeEntity
import com.wafflestudio.csereal.core.academics.dto.CourseDto
import com.wafflestudio.csereal.core.resource.attachment.database.AttachmentEntity
import jakarta.persistence.CascadeType
import jakarta.persistence.Entity
import jakarta.persistence.OneToMany

@Entity(name = "course")
class CourseEntity(
Expand All @@ -12,28 +15,29 @@ class CourseEntity(

var classification: String,

var number: String,
var code: String,

var name: String,

var credit: Int,

var year: String,
var grade: String,

var courseURL: String?,
var description: String?,

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

): BaseTimeEntity() {
companion object {
fun of(studentType: AcademicsStudentType, courseDto: CourseDto): CourseEntity {
return CourseEntity(
studentType = studentType,
classification = courseDto.classification,
number = courseDto.number,
code = courseDto.code,
name = courseDto.name.replace(" ","-"),
credit = courseDto.credit,
year = courseDto.year,
courseURL = courseDto.courseURL,
grade = courseDto.grade,
description = courseDto.description
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package com.wafflestudio.csereal.core.academics.database
import org.springframework.data.jpa.repository.JpaRepository

interface CourseRepository : JpaRepository<CourseEntity, Long> {
fun findAllByStudentTypeOrderByYearAsc(studentType: AcademicsStudentType) : List<CourseEntity>
fun findAllByStudentTypeOrderByNameAsc(studentType: AcademicsStudentType) : List<CourseEntity>
fun findByName(name: String) : CourseEntity
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.wafflestudio.csereal.core.academics.dto

import com.wafflestudio.csereal.core.academics.database.AcademicsEntity
import com.wafflestudio.csereal.core.resource.attachment.dto.AttachmentResponse
import java.time.LocalDateTime

data class AcademicsDto(
Expand All @@ -10,18 +11,18 @@ data class AcademicsDto(
val year: Int?,
val createdAt: LocalDateTime?,
val modifiedAt: LocalDateTime?,
val isPublic: Boolean,
val attachments: List<AttachmentResponse>?,
) {
companion object {
fun of(entity: AcademicsEntity) : AcademicsDto = entity.run {
fun of(entity: AcademicsEntity, attachments: List<AttachmentResponse>?) : AcademicsDto = entity.run {
AcademicsDto(
id = this.id,
name = this.name,
description = this.description,
year = this.year,
createdAt = this.createdAt,
modifiedAt = this.modifiedAt,
isPublic = this.isPublic,
attachments = attachments,
)
}
}
Expand Down
Loading

0 comments on commit 8b38588

Please sign in to comment.