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

feat : create Question Mock Api #17

Merged
merged 5 commits into from
Jun 29, 2024
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
35 changes: 35 additions & 0 deletions api/src/main/kotlin/com/mashup/dojo/QuestionController.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.mashup.dojo

import com.mashup.dojo.common.DojoApiResponse
import com.mashup.dojo.domain.QuestionId
import com.mashup.dojo.dto.QuestionCreateRequest
import com.mashup.dojo.usecase.QuestionUseCase
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import jakarta.validation.Valid
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@Tag(name = "Question", description = "μ§ˆλ¬Έμ§€ κ΄€λ ¨ API μž…λ‹ˆλ‹€")
@RequestMapping("/question")
@RestController
class QuestionController(
private val questionUseCase: QuestionUseCase,
) {
// todo : add auth param
@Operation(summary = "create Question API", description = "μ§ˆλ¬Έμ§€ 생성")
Comment on lines +21 to +22
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ§ˆλ¬Έμ§€ 생성은 μ–΄λ“œλ―Ό μ„± κΈ°λŠ₯이라, authκ°€ λ³„λ„λ‘œ λ“€μ–΄κ°€μ•Όκ² λ„€μš”.
그러면 퍼블릭 API / 인터널 API prefixκ°€ 각각 λ‹€λ₯Έκ²Œ μ’‹μœΌλ €λ‚˜μš”? (λΌλŠ” 생각이 κ°‘μžκΈ° λ“€μŒ)

@PostMapping
fun createQuestion(
@Valid @RequestBody request: QuestionCreateRequest,
): DojoApiResponse<QuestionId> {
return questionUseCase.create(
QuestionUseCase.CreateCommand(
content = request.content,
type = request.type,
emojiImageId = request.emojiImageId
)
).let { DojoApiResponse.success(it.id) }
}
}
24 changes: 24 additions & 0 deletions api/src/main/kotlin/com/mashup/dojo/dto/QuestionDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.mashup.dojo.dto

import com.mashup.dojo.domain.ImageId
import com.mashup.dojo.domain.QuestionType
import io.swagger.v3.oas.annotations.media.Schema
import jakarta.validation.constraints.NotBlank
import jakarta.validation.constraints.NotNull

@Schema(description = "질문 등둝 μš”μ²­")
data class QuestionCreateRequest(
@field:NotBlank
val content: String,
@field:NotNull
val type: QuestionType,
@field:NotBlank
@Schema(description = "질문 이λͺ¨μ§€ 이미지 id")
val emojiImageId: ImageId,
)

@Schema(description = "질문 등둝 bulk μš”μ²­")
data class QuestionBulkCreateRequest(
@Schema(description = "질문 μš”μ²­ list")
val questionList: List<QuestionCreateRequest>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ data class Question(
val content: String,
val type: QuestionType,
// Todo μ •μ±… ν™•μΈν•˜κ³  이름 ν™•μ‹€ν•˜κ²Œ 짓기
val imageUrl: String,
val emojiImageId: ImageId,
val createdAt: LocalDateTime,
val deletedAt: LocalDateTime?,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.mashup.dojo.service

import com.mashup.dojo.domain.ImageId
import com.mashup.dojo.domain.Question
import com.mashup.dojo.domain.QuestionId
import com.mashup.dojo.domain.QuestionType
import io.github.oshai.kotlinlogging.KotlinLogging
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.time.LocalDateTime

private val log = KotlinLogging.logger {}

interface QuestionService {
fun createQuestion(
content: String,
type: QuestionType,
emojiImageId: ImageId,
): Question
}

@Service
@Transactional(readOnly = true)
class DefaultQuestionService : QuestionService {
@Transactional
override fun createQuestion(
content: String,
type: QuestionType,
emojiImageId: ImageId,
): Question {
// todo create questionEntity
// return QuestionRepository.save(content, type, imageUrl).toQuestion
val question = SAMPLE_QUESTION

log.info { "Create Question Success : $question" }

return SAMPLE_QUESTION
}

companion object {
val SAMPLE_QUESTION =
Question(
id = QuestionId(8181818),
content = "μ„Έμƒμ—μ„œ 제일 λ©‹μŸμ΄μΈ μ‚¬λžŒ",
type = QuestionType.FRIEND,
emojiImageId = ImageId(1),
createdAt = LocalDateTime.now(),
deletedAt = null
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.mashup.dojo.usecase

import com.mashup.dojo.domain.ImageId
import com.mashup.dojo.domain.Question
import com.mashup.dojo.domain.QuestionType
import com.mashup.dojo.service.QuestionService
import org.springframework.stereotype.Component

interface QuestionUseCase {
data class CreateCommand(
val content: String,
val type: QuestionType,
val emojiImageId: ImageId,
)

fun create(command: CreateCommand): Question
}

@Component
class QuestionCreateUseCase(
private val questionService: QuestionService,
) : QuestionUseCase {
override fun create(command: QuestionUseCase.CreateCommand): Question {
return questionService.createQuestion(
command.content,
command.type,
command.emojiImageId
)
}
}
Loading