-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from juwon-code/main
[Feat] 긴급 픽스 병합 요청
- Loading branch information
Showing
41 changed files
with
572 additions
and
488 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,4 @@ services: | |
ports: | ||
- "8082:8000" | ||
environment: | ||
- SPRING_PROFILES_ACTIVE=prod | ||
- SPRING_PROFILES_ACTIVE=prod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/org/tenten/bittakotlin/media/service/ProfileImageService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.tenten.bittakotlin.media.service | ||
|
||
import org.tenten.bittakotlin.media.dto.MediaRequestDto | ||
import org.tenten.bittakotlin.media.dto.MediaResponseDto | ||
import org.tenten.bittakotlin.profile.entity.Profile | ||
|
||
interface ProfileImageService { | ||
fun upload(requestDto: MediaRequestDto.Upload, profile: Profile): MediaResponseDto.PublicUpload | ||
|
||
fun delete(requestDto: MediaRequestDto.Delete) | ||
} |
81 changes: 81 additions & 0 deletions
81
src/main/kotlin/org/tenten/bittakotlin/media/service/ProfileImageServiceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.tenten.bittakotlin.media.service | ||
|
||
import org.slf4j.Logger | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
import org.tenten.bittakotlin.media.constant.MediaError | ||
import org.tenten.bittakotlin.media.constant.MediaType | ||
import org.tenten.bittakotlin.media.dto.MediaRequestDto | ||
import org.tenten.bittakotlin.media.dto.MediaResponseDto | ||
import org.tenten.bittakotlin.media.entity.Media | ||
import org.tenten.bittakotlin.media.exception.MediaException | ||
import org.tenten.bittakotlin.media.repository.MediaRepository | ||
import org.tenten.bittakotlin.profile.entity.Profile | ||
import java.util.* | ||
|
||
@Service | ||
class ProfileImageServiceImpl ( | ||
private val mediaRepository: MediaRepository, | ||
|
||
private val s3Service: S3Service, | ||
|
||
@Value("\${file.max.size.image}") | ||
private val maxsize: Int | ||
) : ProfileImageService { | ||
companion object { | ||
private val logger: Logger = LoggerFactory.getLogger(ProfileImageServiceImpl::class.java) | ||
} | ||
|
||
@Transactional | ||
override fun upload(requestDto: MediaRequestDto.Upload, profile: Profile): MediaResponseDto.PublicUpload { | ||
val filetype: MediaType = checkMimetype(requestDto.mimetype) | ||
val filename: String = UUID.randomUUID().toString() + getExtension(requestDto.mimetype) | ||
val filesize: Int = checkFileSize(requestDto.filesize) | ||
|
||
mediaRepository.save(Media( | ||
filename = filename, | ||
filetype = filetype, | ||
filesize = filesize, | ||
profile = profile | ||
)) | ||
|
||
return s3Service.getPublicUploadUrl(filename, requestDto.mimetype) | ||
} | ||
|
||
@Transactional | ||
override fun delete(requestDto: MediaRequestDto.Delete) { | ||
val filename: String = requestDto.filename | ||
|
||
mediaRepository.findByFilename(filename).orElseThrow { MediaException(MediaError.CANNOT_FOUND) } | ||
} | ||
|
||
private fun getExtension(mimetype: String): String? { | ||
val mimetypeMap = mapOf( | ||
"image/jpeg" to "jpg", | ||
"image/png" to "png", | ||
"image/gif" to "gif", | ||
"image/bmp" to "bmp", | ||
"image/webp" to "webp", | ||
"image/svg+xml" to "svg", | ||
) | ||
return mimetypeMap[mimetype] | ||
} | ||
|
||
private fun checkMimetype(mimetype: String): MediaType { | ||
if (mimetype.matches(Regex("image/(jpeg|png|gif|bmp|webp|svg\\+xml)"))) { | ||
return MediaType.IMAGE | ||
} | ||
|
||
throw MediaException(MediaError.WRONG_MIME_TYPE) | ||
} | ||
|
||
private fun checkFileSize(filesize: Int): Int { | ||
if (filesize > maxsize) { | ||
throw MediaException(MediaError.WRONG_FILE_SIZE) | ||
} | ||
|
||
return filesize | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/kotlin/org/tenten/bittakotlin/media/service/S3Service.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
package org.tenten.bittakotlin.media.service | ||
|
||
import org.tenten.bittakotlin.media.dto.MediaResponseDto | ||
|
||
interface S3Service { | ||
fun getReadUrl(name: String): String | ||
|
||
fun getUploadUrl(name: String, contentType: String): String | ||
|
||
fun getPublicUploadUrl(name: String, contentType: String): MediaResponseDto.PublicUpload | ||
|
||
fun delete(filename: String): Unit | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,4 @@ data class Member( | |
|
||
@Column(nullable = false) | ||
var role: String? = null | ||
|
||
|
||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.