-
Notifications
You must be signed in to change notification settings - Fork 3
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a00444e
add : create Question Mock Api
xonmin 195cda7
refactor : ktlint
xonmin a5ca4f8
add : swagger annotation
xonmin 58b663e
update : question service to interface di
xonmin 49d1a46
refactor : imageUrl property to emojiImageId
xonmin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 = "μ§λ¬Έμ§ μμ±") | ||
@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) } | ||
} | ||
} |
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,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>, | ||
) |
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
51 changes: 51 additions & 0 deletions
51
service/src/main/kotlin/com/mashup/dojo/service/DefaultQuestionService.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,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 | ||
) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
service/src/main/kotlin/com/mashup/dojo/usecase/QuestionUseCase.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,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 | ||
) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ§λ¬Έμ§ μμ±μ μ΄λλ―Ό μ± κΈ°λ₯μ΄λΌ, authκ° λ³λλ‘ λ€μ΄κ°μΌκ² λ€μ.
κ·Έλ¬λ©΄ νΌλΈλ¦ API / μΈν°λ API prefixκ° κ°κ° λ€λ₯Έκ² μ’μΌλ €λμ? (λΌλ μκ°μ΄ κ°μκΈ° λ€μ)