Skip to content

Commit

Permalink
feat: 소개 탭 CRUD
Browse files Browse the repository at this point in the history
  • Loading branch information
leeeryboy committed Aug 28, 2024
1 parent 06e2a35 commit dbb8b81
Show file tree
Hide file tree
Showing 14 changed files with 385 additions and 335 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ package com.wafflestudio.csereal.core.about.api

import com.wafflestudio.csereal.common.aop.AuthenticatedStaff
import com.wafflestudio.csereal.common.enums.LanguageType
import com.wafflestudio.csereal.core.about.api.req.*
import com.wafflestudio.csereal.core.about.api.res.AboutSearchResBody
import com.wafflestudio.csereal.core.about.dto.*
import com.wafflestudio.csereal.core.about.dto.AboutRequest
import com.wafflestudio.csereal.core.about.dto.FutureCareersRequest
import com.wafflestudio.csereal.core.about.service.AboutService
import jakarta.validation.Valid
import jakarta.validation.constraints.Positive
import org.springframework.context.annotation.Profile
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import org.springframework.web.multipart.MultipartFile
Expand All @@ -24,18 +22,6 @@ class AboutController(
// postType: directions / name -> by-public-transit, by-car, from-far-away

// Todo: 학부장 인사말(greetings) signature
@AuthenticatedStaff
@PostMapping("/{postType}")
fun createAbout(
@PathVariable postType: String,
@Valid
@RequestPart("request")
request: AboutDto,
@RequestPart("mainImage") mainImage: MultipartFile?,
@RequestPart("attachments") attachments: List<MultipartFile>?
): ResponseEntity<AboutDto> {
return ResponseEntity.ok(aboutService.createAbout(postType, request, mainImage, attachments))
}

// read 목록이 하나
@GetMapping("/{postType}")
Expand All @@ -46,34 +32,101 @@ class AboutController(
return ResponseEntity.ok(aboutService.readAbout(language, postType))
}

@AuthenticatedStaff
@PutMapping("/{postType}")
fun updateAbout(
@PathVariable postType: String,
@RequestPart request: UpdateAboutReq,
@RequestPart newMainImage: MultipartFile?,
@RequestPart newAttachments: List<MultipartFile>?
) = aboutService.updateAbout(postType, request, newMainImage, newAttachments)

@AuthenticatedStaff
@PostMapping("/student-clubs")
fun createClub(
@RequestPart request: CreateClubReq,
@RequestPart mainImage: MultipartFile?
) = aboutService.createClub(request, mainImage)

@AuthenticatedStaff
@PutMapping("/student-clubs/{engName}")
fun updateClub(
@PathVariable("engName") name: String,
@RequestPart request: UpdateDescriptionReq,
@RequestPart newMainImage: MultipartFile?
) = aboutService.updateClub(name, request, newMainImage)

@AuthenticatedStaff
@DeleteMapping("/student-clubs/{engName}")
fun deleteClub(@PathVariable("engName") name: String) = aboutService.deleteClub(name)

@GetMapping("/student-clubs")
fun readAllClubs(
@RequestParam(required = false, defaultValue = "ko") language: String
): ResponseEntity<List<StudentClubDto>> {
return ResponseEntity.ok(aboutService.readAllClubs(language))
}

@AuthenticatedStaff
@PostMapping("/facilities")
fun createFacilities(@RequestPart request: CreateFacReq, @RequestPart mainImage: MultipartFile?) =
aboutService.createFacilities(request, mainImage)

@AuthenticatedStaff
@PutMapping("/facilities/{id}")
fun updateFacility(
@PathVariable id: Long,
@RequestPart request: CreateFacReq,
@RequestPart newMainImage: MultipartFile?
) = aboutService.updateFacility(id, request, newMainImage)

@AuthenticatedStaff
@DeleteMapping("/facilities/{id}")
fun deleteFacility(@PathVariable id: Long) = aboutService.deleteFacility(id)

@GetMapping("/facilities")
fun readAllFacilities(
@RequestParam(required = false, defaultValue = "ko") language: String
): ResponseEntity<List<AboutDto>> {
return ResponseEntity.ok(aboutService.readAllFacilities(language))
}

@PutMapping("/directions/{id}")
fun updateDirection(@PathVariable id: Long, @RequestBody request: UpdateDescriptionReq) =
aboutService.updateDirection(id, request)

@GetMapping("/directions")
fun readAllDirections(
@RequestParam(required = false, defaultValue = "ko") language: String
): ResponseEntity<List<AboutDto>> {
return ResponseEntity.ok(aboutService.readAllDirections(language))
}

@AuthenticatedStaff
@PutMapping("/future-careers")
fun updateFutureCareersPage(@RequestBody request: UpdateDescriptionReq) =
aboutService.updateFutureCareersPage(request)

@GetMapping("/future-careers")
fun readFutureCareers(
@RequestParam(required = false, defaultValue = "ko") language: String
): ResponseEntity<FutureCareersPage> {
return ResponseEntity.ok(aboutService.readFutureCareers(language))
}

@AuthenticatedStaff
@PostMapping("/future-careers/company")
fun createCompany(@RequestBody request: CreateCompanyReq) = aboutService.createCompany(request)

@AuthenticatedStaff
@PutMapping("/future-careers/company/{id}")
fun updateCompany(@PathVariable id: Long, @RequestBody request: CreateCompanyReq) =
aboutService.updateCompany(id, request)

@AuthenticatedStaff
@DeleteMapping("/future-careers/company/{id}")
fun deleteCompany(@PathVariable id: Long) = aboutService.deleteCompany(id)

@GetMapping("/search/top")
fun searchTopAbout(
@RequestParam(required = true) keyword: String,
Expand Down Expand Up @@ -101,56 +154,4 @@ class AboutController(
pageNum,
amount
)

@Profile("!prod")
@PostMapping("/migrate")
fun migrateAbout(
@RequestBody requestList: List<AboutRequest>
): ResponseEntity<List<AboutDto>> {
return ResponseEntity.ok(aboutService.migrateAbout(requestList))
}

@Profile("!prod")
@PostMapping("/future-careers/migrate")
fun migrateFutureCareers(
@RequestBody request: FutureCareersRequest
): ResponseEntity<FutureCareersPage> {
return ResponseEntity.ok(aboutService.migrateFutureCareers(request))
}

@Profile("!prod")
@PostMapping("/student-clubs/migrate")
fun migrateStudentClubs(
@RequestBody requestList: List<StudentClubDto>
): ResponseEntity<List<StudentClubDto>> {
return ResponseEntity.ok(aboutService.migrateStudentClubs(requestList))
}

@Profile("!prod")
@PostMapping("/facilities/migrate")
fun migrateFacilities(
@RequestBody requestList: List<FacilityDto>
): ResponseEntity<List<FacilityDto>> {
return ResponseEntity.ok(aboutService.migrateFacilities(requestList))
}

@Profile("!prod")
@PostMapping("/directions/migrate")
fun migrateDirections(
@RequestBody requestList: List<DirectionDto>
): ResponseEntity<List<DirectionDto>> {
return ResponseEntity.ok(aboutService.migrateDirections(requestList))
}

@Profile("!prod")
@PatchMapping("/migrateImage/{aboutId}")
fun migrateAboutImageAndAttachment(
@PathVariable aboutId: Long,
@RequestPart("mainImage") mainImage: MultipartFile?,
@RequestPart("attachments") attachments: List<MultipartFile>?
): ResponseEntity<AboutDto> {
return ResponseEntity.ok(
aboutService.migrateAboutImageAndAttachments(aboutId, mainImage, attachments)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.wafflestudio.csereal.core.about.api.req

data class CreateClubReq(
val ko: ClubDto,
val en: ClubDto
)

data class ClubDto(
val name: String,
val description: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.wafflestudio.csereal.core.about.api.req

data class CreateCompanyReq(
val name: String,
val url: String?,
val year: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.wafflestudio.csereal.core.about.api.req

data class CreateFacReq(
val ko: FacDto,
val en: FacDto
)

data class FacDto(
val name: String,
val description: String,
val locations: MutableList<String>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.wafflestudio.csereal.core.about.api.req

data class UpdateAboutReq(
val ko: BasicAbout,
val en: BasicAbout
)

data class BasicAbout(
val description: String,
val deleteIds: List<Long>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.wafflestudio.csereal.core.about.api.req

data class UpdateDescriptionReq(
val koDescription: String,
val enDescription: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ class AboutEntity(
@Column(columnDefinition = "mediumText")
var description: String,

var year: Int?,

@Column(columnDefinition = "TEXT")
@Convert(converter = StringListConverter::class)
var locations: MutableList<String> = mutableListOf(),

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

@OneToOne
@OneToOne(fetch = FetchType.LAZY, cascade = [CascadeType.ALL], orphanRemoval = true)
var mainImage: MainImageEntity? = null,

@Column(columnDefinition = "TEXT")
Expand All @@ -52,7 +50,6 @@ class AboutEntity(
language = languageType,
name = aboutDto.name,
description = aboutDto.description,
year = aboutDto.year,
locations = aboutDto.locations?.toMutableList() ?: mutableListOf(),
searchContent = ""
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.wafflestudio.csereal.core.about.database

import com.wafflestudio.csereal.common.config.BaseTimeEntity
import jakarta.persistence.*

@Entity(name = "about_language")
class AboutLanguageEntity(
@OneToOne(fetch = FetchType.LAZY, cascade = [CascadeType.ALL], orphanRemoval = true)
@JoinColumn(name = "korean_id")
val koAbout: AboutEntity,

@OneToOne(fetch = FetchType.LAZY, cascade = [CascadeType.ALL], orphanRemoval = true)
@JoinColumn(name = "english_id")
val enAbout: AboutEntity
) : BaseTimeEntity()
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.wafflestudio.csereal.core.about.database

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

interface AboutLanguageRepository : JpaRepository<AboutLanguageEntity, Long> {
fun findByKoAbout(koAboutEntity: AboutEntity): AboutLanguageEntity?
fun findByEnAbout(enAboutEntity: AboutEntity): AboutLanguageEntity?
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@ interface AboutRepository : JpaRepository<AboutEntity, Long>, AboutCustomReposit
languageType: LanguageType,
postType: AboutPostType
): List<AboutEntity>

fun findByLanguageAndPostType(
languageType: LanguageType,
postType: AboutPostType
): AboutEntity

fun findByLanguageAndPostTypeAndNameContaining(
languageType: LanguageType,
postType: AboutPostType,
keyword: String
): AboutEntity
}

interface AboutCustomRepository {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package com.wafflestudio.csereal.core.about.database
import org.springframework.data.jpa.repository.JpaRepository

interface CompanyRepository : JpaRepository<CompanyEntity, Long> {
fun findAllByOrderByYearDesc(): List<CompanyEntity>
fun findAllByOrderByNameDesc(): List<CompanyEntity>
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ data class AboutDto(
val language: String,
val name: String?,
val description: String,
val year: Int?,
val createdAt: LocalDateTime?,
val modifiedAt: LocalDateTime?,
val locations: List<String>?,
Expand All @@ -30,7 +29,6 @@ data class AboutDto(
language = LanguageType.makeLowercase(this.language),
name = this.name,
description = this.description,
year = this.year,
createdAt = this.createdAt,
modifiedAt = this.modifiedAt,
locations = this.locations,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ data class StudentClubDto(
val name: String,
val engName: String,
val description: String,
val year: Int?,
val createdAt: LocalDateTime?,
val modifiedAt: LocalDateTime?,
val locations: List<String>?,
Expand All @@ -34,7 +33,6 @@ data class StudentClubDto(
name = name,
engName = engName,
description = this.description,
year = this.year,
createdAt = this.createdAt,
modifiedAt = this.modifiedAt,
locations = this.locations,
Expand Down
Loading

0 comments on commit dbb8b81

Please sign in to comment.