-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
360 additions
and
80 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
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/site/qbox/qboxserver/domain/image/ImageRepo.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,7 @@ | ||
package site.qbox.qboxserver.domain.image | ||
|
||
import org.springframework.web.multipart.MultipartFile | ||
|
||
interface ImageRepo { | ||
fun save(file: MultipartFile, name: String) : String | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/site/qbox/qboxserver/domain/image/ImageSvc.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,23 @@ | ||
package site.qbox.qboxserver.domain.image | ||
|
||
import org.springframework.web.multipart.MultipartFile | ||
import site.qbox.qboxserver.domain.image.dto.ImageRes | ||
import site.qbox.qboxserver.global.annotation.CommandService | ||
import java.util.* | ||
|
||
@CommandService | ||
class ImageSvc( | ||
private val imageRepo: ImageRepo, | ||
private val imageValidator: ImageValidator, | ||
) { | ||
fun save(file: MultipartFile): ImageRes { | ||
imageValidator.validate(file) | ||
return ImageRes(imageRepo.save(file, generateName(file))) | ||
} | ||
|
||
private fun generateName(file: MultipartFile): String = | ||
"${UUID.randomUUID()}.${extractExtension(file)}" | ||
|
||
private fun extractExtension(file: MultipartFile): String = | ||
file.name.substringAfterLast(".") | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/site/qbox/qboxserver/domain/image/ImageValidator.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,19 @@ | ||
package site.qbox.qboxserver.domain.image | ||
|
||
import org.springframework.stereotype.Component | ||
import org.springframework.web.multipart.MultipartFile | ||
import site.qbox.qboxserver.domain.image.exception.NotAllowedImageException | ||
|
||
@Component | ||
class ImageValidator { | ||
companion object { | ||
private val ALLOW_EXTENSIONS = listOf("png", "jpg", "jpeg", "gif", "bmp", "webp", "ico", "tiff", "tif", "svg") | ||
} | ||
|
||
fun validate(file: MultipartFile) { | ||
require(extractExtension(file) in ALLOW_EXTENSIONS) { throw NotAllowedImageException() } | ||
} | ||
|
||
private fun extractExtension(file: MultipartFile): String = | ||
file.name.substringAfterLast(".") | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/kotlin/site/qbox/qboxserver/domain/image/dto/ImageRes.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,3 @@ | ||
package site.qbox.qboxserver.domain.image.dto | ||
|
||
data class ImageRes(val location: String) |
3 changes: 3 additions & 0 deletions
3
src/main/kotlin/site/qbox/qboxserver/domain/image/exception/NotAllowedImageException.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,3 @@ | ||
package site.qbox.qboxserver.domain.image.exception | ||
|
||
class NotAllowedImageException : RuntimeException() |
18 changes: 18 additions & 0 deletions
18
src/main/kotlin/site/qbox/qboxserver/domain/image/local/LocalStorageImageRepo.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,18 @@ | ||
package site.qbox.qboxserver.domain.image.local | ||
|
||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.stereotype.Repository | ||
import org.springframework.web.multipart.MultipartFile | ||
import site.qbox.qboxserver.domain.image.ImageRepo | ||
import java.io.File | ||
|
||
@Repository | ||
class LocalStorageImageRepo( | ||
@Value("\${local-storage.directory}") private val localStorageDirectory: String, | ||
@Value("\${local-storage.url}") private val localStorageUrl: String, | ||
) : ImageRepo { | ||
override fun save(file: MultipartFile, name: String): String { | ||
file.transferTo(File(localStorageDirectory, name)) | ||
return "${localStorageUrl}/${name}" | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/site/qbox/qboxserver/domain/question/query/dto/QuestionCondition.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,21 @@ | ||
package site.qbox.qboxserver.domain.question.query.dto | ||
|
||
import com.querydsl.core.types.dsl.BooleanExpression | ||
import site.qbox.qboxserver.domain.lecture.command.entity.LectureId | ||
import site.qbox.qboxserver.domain.member.command.entity.QMember.member | ||
import site.qbox.qboxserver.domain.question.command.entity.QQuestion.question | ||
|
||
data class QuestionCondition( | ||
val title: String = "", | ||
val body: String = "", | ||
val writerNickname: String = "", | ||
val lectureCode: String, | ||
val lectureDepart: Long, | ||
) { | ||
|
||
fun toFilter(): BooleanExpression = | ||
question.lecture.eq(LectureId(lectureCode, lectureDepart)) | ||
.and(question.title.contains(title)) | ||
.and(question.body.contains(body)) | ||
.and(member.nickname.contains(writerNickname)) | ||
} |
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
3 changes: 1 addition & 2 deletions
3
src/main/kotlin/site/qbox/qboxserver/global/exception/NotFoundException.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,4 +1,3 @@ | ||
package site.qbox.qboxserver.global.exception | ||
|
||
class NotFoundException : RuntimeException("Not found") { | ||
} | ||
class NotFoundException : RuntimeException("Not found") |
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
Oops, something went wrong.