Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐Ÿ”€ :: (ENTRY-190) ์ฒจ๋ถ€ํŒŒ์ผ ์—ฌ๋Ÿฌ๊ฐœ ์ž…๋ ฅ๋ฐ›์„์ˆ˜ ์žˆ๊ฒŒ ๋ณ€๊ฒฝ #46

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,5 @@ import javax.persistence.Entity
@Entity(name = "tbl_attach_file")
class AttachFile(
id: UUID? = null,
var attachFile: String
) : BaseEntity(id) {
fun modifyAttachFile(
attachFile: String
) {
this.attachFile = attachFile
}
}
var attachFileName: String
) : BaseEntity(id)
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import org.springframework.data.jpa.repository.JpaRepository
import java.util.UUID

interface AttachFileRepository : JpaRepository<AttachFile, UUID> {
fun findByAttachFile(attachFile: String): AttachFile?
fun findByAttachFileName(attachFileName: String): AttachFile?
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class AttachFileController(
) {
@PostMapping
fun createAttachFile(
@RequestPart(value = "attach_file") attachFile: MultipartFile
@RequestPart(value = "attach_file") attachFile: List<MultipartFile>
) = createAttachFileService.execute(attachFile)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ class CreateAttachFileService(
private val attachFileRepository: AttachFileRepository,
private val fileUtil: FileUtil
) {
fun execute(attachFile: MultipartFile): CreateAttachFileResponse {
val attachFileName = fileUtil.upload(attachFile, PathList.ATTACH_FILE)
attachFileRepository.save(
AttachFile(
attachFile = attachFileName
)
)
return CreateAttachFileResponse(attachFileName, getUrl(attachFileName))
}
fun execute(attachFile: List<MultipartFile>): List<CreateAttachFileResponse> {
val attachFileResponses = mutableListOf<CreateAttachFileResponse>()

attachFile.forEach { file ->
val uploadedFilename = fileUtil.upload(file, PathList.ATTACH_FILE)
val attachFileEntity = AttachFile(attachFileName = uploadedFilename)
attachFileRepository.save(attachFileEntity)

private fun getUrl(attachFileUrl: String) =
fileUtil.generateObjectUrl(attachFileUrl, PathList.ATTACH_FILE)
val url = fileUtil.generateObjectUrl(uploadedFilename, PathList.ATTACH_FILE)
attachFileResponses.add(CreateAttachFileResponse(uploadedFilename, url))
}

return attachFileResponses
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ data class GetNoticeResponse(
val createdAt: LocalDateTime,
val type: NoticeType,
val imageURL: String?,
val attachFileUrl: List<String>?
val attachFileUrl: List<String> = emptyList()
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CreateNoticeService(
) {
val admin = userUtils.getCurrentUserId()
val attachFile = request.attachFileName?.map {
attachFileRepository.findByAttachFile(it) ?: throw AttachFileNotFoundException
attachFileRepository.findByAttachFileName(it) ?: throw AttachFileNotFoundException
}

noticeRepository.save(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class GetNoticeService(

val attachFileUrls =
notice.attachFile?.map {
getUrl(it.attachFile, PathList.ATTACH_FILE)
getUrl(it.attachFileName, PathList.ATTACH_FILE)
}

return notice.run {
Expand All @@ -32,7 +32,7 @@ class GetNoticeService(
createdAt = createdAt,
type = type,
imageURL = imageURL,
attachFileUrl = attachFileUrls
attachFileUrl = attachFileUrls!!
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class SecurityConfig(
.hasRole(ADMIN_ROLE)
.antMatchers(HttpMethod.POST, "/screen")
.hasRole(ADMIN_ROLE)
.antMatchers(HttpMethod.POST, "/attach-file")
.hasRole(ADMIN_ROLE)
.anyRequest()
.authenticated()

Expand Down
Loading