Skip to content

Commit

Permalink
Merge branch 'feat-image' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
phjppo0918 committed Nov 20, 2023
2 parents 24bea21 + f369f1c commit b1735ea
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 34 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ koverReport {
classes("**.QboxServerApplicationKt")
classes("**.**Config")
classes("**.**Query")
classes("**.local.**")
classes("site.qbox.qboxserver.domain.member.email.svc.MailSvc")
classes("site.qbox.qboxserver.domain.image.local.LocalStorageImageRepo")
classes("**.dto.**")
Expand Down
19 changes: 0 additions & 19 deletions src/main/kotlin/site/qbox/qboxserver/domain/image/ImageCtrl.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ class ImageSvc(
"${UUID.randomUUID()}.${extractExtension(file)}"

private fun extractExtension(file: MultipartFile): String =
file.originalFilename!!.substringAfterLast(".")
file.name.substringAfterLast(".")
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ import site.qbox.qboxserver.domain.image.exception.NotAllowedImageException
@Component
class ImageValidator {
companion object {
val ALLOW_EXTENSIONS = listOf("png", "jpg", "jpeg", "gif", "bmp", "webp", "ico", "tiff", "tif", "svg")
private val ALLOW_EXTENSIONS = listOf("png", "jpg", "jpeg", "gif", "bmp", "webp", "ico", "tiff", "tif", "svg")
}

fun validate(file: MultipartFile) {
file.originalFilename ?: NotAllowedImageException()
file.contentType ?: NotAllowedImageException()
require(extractExtension(file) in ALLOW_EXTENSIONS) { throw NotAllowedImageException() }
}

private fun extractExtension(file: MultipartFile): String =
file.originalFilename!!.substringAfterLast(".")
file.name.substringAfterLast(".")
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.querydsl.core.types.dsl.StringPath
import site.qbox.qboxserver.domain.member.command.entity.QMember.member
import site.qbox.qboxserver.domain.member.query.dto.QMemberSummary

class MemberQuery {
interface MemberQuery {
companion object {
val id: StringPath = member.email.email
val summary = QMemberSummary(id, member.nickname)
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ logging:

service:
url: http://localhost:5172

local-storage:
directory: http://localhost/qbox/image/
url: http://localhost:5172
6 changes: 5 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@ logging:
config: classpath:logback-spring.xml

service:
url: ${SERVICE_URL}
url: ${SERVICE_URL}

local-storage:
directory: ${LOCAL_STORAGE_DIRECTORY}
url: ${LOCAL_STORAGE_URL}

This file was deleted.

27 changes: 27 additions & 0 deletions src/test/kotlin/site/qbox/qboxserver/domain/image/ImageSvcTest.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
package site.qbox.qboxserver.domain.image

import com.ninjasquad.springmockk.MockkBean
import io.kotest.core.spec.style.DescribeSpec
import io.kotest.extensions.spring.SpringExtension
import io.kotest.matchers.shouldBe
import io.mockk.every
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.mock.web.MockMultipartFile

@SpringBootTest
class ImageSvcTest : DescribeSpec() {

override fun extensions() = listOf(SpringExtension)

@Autowired
lateinit var imageSvc: ImageSvc

@MockkBean
lateinit var imageRepo: ImageRepo

val image = MockMultipartFile("asdfasdf.jpg", byteArrayOf(9))
init {
it("저장을 수행한다.") {
val savedUrl = "https://hello.com/user/kkkkk-sdf.jpg"
every { imageRepo.save(image, any(String::class)) } returns savedUrl

val result = imageSvc.save(image)
result.location shouldBe savedUrl
}
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,44 @@
package site.qbox.qboxserver.domain.image

import io.kotest.assertions.throwables.shouldNotThrow
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.DescribeSpec
import io.kotest.extensions.spring.SpringExtension
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.mock.web.MockMultipartFile
import site.qbox.qboxserver.domain.image.exception.NotAllowedImageException

@SpringBootTest
class ImageValidatorTest : DescribeSpec() {

override fun extensions() = listOf(SpringExtension)

@Autowired
lateinit var imageValidator: ImageValidator

init {
it("검증을 수행한다") {
val image = MockMultipartFile("hello.jpg", byteArrayOf(9))
shouldNotThrow<NotAllowedImageException> {
imageValidator.validate(image)
}
}

it("확장자가 명시되어있지 않으면 예외를 반환한다") {
val image = MockMultipartFile("asdfasdf", byteArrayOf(9))
shouldThrow<NotAllowedImageException> {
imageValidator.validate(image)
}
}

it("허용하지 않은 확장자면 예외를 반환한다") {
val image = MockMultipartFile("hello.txt", byteArrayOf(9))
shouldThrow<NotAllowedImageException> {
imageValidator.validate(image)
}
}

}

}
27 changes: 27 additions & 0 deletions src/test/kotlin/site/qbox/qboxserver/study/RequireTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package site.qbox.qboxserver.study

import io.kotest.assertions.throwables.shouldNotThrow
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.DescribeSpec

class RequireTest : DescribeSpec() {


fun requireIn(value: String) {
val list = listOf("A", "B", "C", "D", "E", "F")
require(value in list)
}

init {
it("in 값에 포함되면 예외를 반환하지 않는다.") {
shouldNotThrow<IllegalArgumentException> {
requireIn("A")
}
}
it("in 값에 포함되지 않으면 예외를 반환한다.") {
shouldThrow<IllegalArgumentException> {
requireIn("KK")
}
}
}
}
6 changes: 5 additions & 1 deletion src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ logging:
config: classpath:logback-spring.xml

service:
url: https://aaa.bb.com
url: https://aaa.bb.com

local-storage:
directory: http://localhost/qbox/image/
url: http://localhost:5172

0 comments on commit b1735ea

Please sign in to comment.