Skip to content

Commit

Permalink
Merge pull request #40 from EntryDSM/feature/entry-170-전형-요강-생성-api-개발
Browse files Browse the repository at this point in the history
🔀 :: (ENTRY-170) 전형 요강 생성 api 개발
  • Loading branch information
rudeh2926 authored Apr 16, 2024
2 parents dd180e3 + 672b82d commit c711e25
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/kotlin/hs/kr/equus/feed/domain/screen/domain/Screen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package hs.kr.equus.feed.domain.screen.domain

import hs.kr.equus.feed.domain.BaseEntity
import java.util.UUID
import javax.persistence.Column
import javax.persistence.Entity

@Entity(name = "tbl_screen")
class Screen(

id: UUID? = null,

val image: String,

@Column(columnDefinition = "VARCHAR(255)")
val adminId: UUID
) : BaseEntity(id)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package hs.kr.equus.feed.domain.screen.domain.repository

import hs.kr.equus.feed.domain.screen.domain.Screen
import org.springframework.data.jpa.repository.JpaRepository
import java.util.UUID

interface ScreenRepository : JpaRepository<Screen, UUID>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package hs.kr.equus.feed.domain.screen.presentation

import hs.kr.equus.feed.domain.screen.presentation.dto.response.ScreenResponse
import hs.kr.equus.feed.domain.screen.service.CreateScreenService
import org.springframework.http.HttpStatus
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestPart
import org.springframework.web.bind.annotation.ResponseStatus
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.multipart.MultipartFile

@RestController
@RequestMapping("/screen")
class ScreenController(
private val createScreenService: CreateScreenService
) {

@ResponseStatus(value = HttpStatus.CREATED)
@PostMapping
fun createScreen(
@RequestPart(name = "image") image: MultipartFile
): ScreenResponse =
createScreenService.execute(image)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package hs.kr.equus.feed.domain.screen.presentation.dto.response

data class ScreenResponse(
val image: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package hs.kr.equus.feed.domain.screen.service

import hs.kr.equus.feed.domain.screen.domain.Screen
import hs.kr.equus.feed.domain.screen.domain.repository.ScreenRepository
import hs.kr.equus.feed.domain.screen.presentation.dto.response.ScreenResponse
import hs.kr.equus.feed.global.utils.user.UserUtils
import hs.kr.equus.feed.infrastructure.s3.PathList
import hs.kr.equus.feed.infrastructure.s3.util.FileUtil
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import org.springframework.web.multipart.MultipartFile

@Service
class CreateScreenService(
private val screenRepository: ScreenRepository,
private val fileUtil: FileUtil,
private val userUtils: UserUtils
) {

@Transactional
fun execute(file: MultipartFile): ScreenResponse {
val adminId = userUtils.getCurrentUser().id

val fileName = fileUtil.upload(file, PathList.SCREEN)
screenRepository.save(
Screen(
image = fileName,
adminId = adminId
)
)
return ScreenResponse(fileName)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class SecurityConfig(
.permitAll()
.antMatchers(HttpMethod.POST, "/notice/**")
.hasRole(ADMIN_ROLE)
.antMatchers(HttpMethod.POST, "/screen")
.hasRole(ADMIN_ROLE)
.anyRequest()
.authenticated()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ package hs.kr.equus.feed.infrastructure.s3

object PathList {
const val NOTICE = "notice/"
const val SCREEN = "screen/"
}

0 comments on commit c711e25

Please sign in to comment.