-
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.
Showing
30 changed files
with
592 additions
and
75 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
12 changes: 12 additions & 0 deletions
12
plu-api/src/main/kotlin/com/th/plu/api/config/converter/YearMonthConverter.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,12 @@ | ||
package com.th.plu.api.config.converter | ||
|
||
import org.springframework.core.convert.converter.Converter | ||
import org.springframework.stereotype.Component | ||
import java.time.YearMonth | ||
import java.time.format.DateTimeFormatter | ||
|
||
@Component | ||
class YearMonthConverter : Converter<String, YearMonth> { | ||
override fun convert(source: String): YearMonth = | ||
YearMonth.parse(source, DateTimeFormatter.ofPattern("yyyyMM")) | ||
} |
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
6 changes: 6 additions & 0 deletions
6
plu-api/src/main/kotlin/com/th/plu/api/controller/answer/dto/AnswerResponseDto.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,6 @@ | ||
package com.th.plu.api.controller.answer.dto | ||
|
||
data class AnswerResponseDto( | ||
val id: Long, | ||
val body: String, | ||
) |
5 changes: 5 additions & 0 deletions
5
plu-api/src/main/kotlin/com/th/plu/api/controller/answer/dto/ReactionResponseDto.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,5 @@ | ||
package com.th.plu.api.controller.answer.dto | ||
|
||
data class ReactionResponseDto( | ||
val likeCount: Long, | ||
) |
17 changes: 17 additions & 0 deletions
17
plu-api/src/main/kotlin/com/th/plu/api/controller/answer/dto/WritingAnswerRequestDto.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,17 @@ | ||
package com.th.plu.api.controller.answer.dto | ||
|
||
import com.th.plu.domain.domain.answer.AnswerWriting | ||
|
||
data class WritingAnswerRequestDto( | ||
val body: String, | ||
val settings: AnswerSettingRequestDto, | ||
) | ||
|
||
data class AnswerSettingRequestDto( | ||
val open: Boolean, | ||
) | ||
|
||
fun toAnswerWriting(writingAnswerRequestDto: WritingAnswerRequestDto) = AnswerWriting( | ||
body = writingAnswerRequestDto.body, | ||
open = writingAnswerRequestDto.settings.open, | ||
) |
29 changes: 29 additions & 0 deletions
29
plu-api/src/main/kotlin/com/th/plu/api/controller/answer/dto/WritingAnswerResponseDto.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,29 @@ | ||
package com.th.plu.api.controller.answer.dto | ||
|
||
import com.th.plu.api.controller.question.dto.QuestionResponseDto | ||
import com.th.plu.domain.domain.answer.WritingAnswerResult | ||
|
||
data class WritingAnswerResponseDto( | ||
val question: QuestionResponseDto, | ||
val answer: AnswerResponseDto, | ||
val reaction: ReactionResponseDto, | ||
) | ||
|
||
internal fun toWritingAnswerResponse(writingAnswerResult: WritingAnswerResult) = WritingAnswerResponseDto( | ||
question = QuestionResponseDto( | ||
id = writingAnswerResult.questionId, | ||
title = writingAnswerResult.questionTitle, | ||
content = writingAnswerResult.questionContent, | ||
exposedAt = writingAnswerResult.questionExposedAt, | ||
elementType = writingAnswerResult.questionElementType, | ||
characterImageUrl = writingAnswerResult.characterImageUrl, | ||
answered = writingAnswerResult.questionAnswered, | ||
), | ||
answer = AnswerResponseDto( | ||
id = writingAnswerResult.answerId, | ||
body = writingAnswerResult.answerBody, | ||
), | ||
reaction = ReactionResponseDto( | ||
likeCount = writingAnswerResult.reactionLikeCount, | ||
) | ||
) |
48 changes: 48 additions & 0 deletions
48
plu-api/src/main/kotlin/com/th/plu/api/controller/question/QuestionController.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,48 @@ | ||
package com.th.plu.api.controller.question | ||
|
||
import com.th.plu.api.config.interceptor.Auth | ||
import com.th.plu.api.config.resolver.MemberId | ||
import com.th.plu.api.controller.question.dto.* | ||
import com.th.plu.common.dto.response.ApiResponse | ||
import com.th.plu.api.service.question.QuestionService | ||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.tags.Tag | ||
import org.springframework.format.annotation.DateTimeFormat | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RequestParam | ||
import org.springframework.web.bind.annotation.RestController | ||
import java.time.YearMonth | ||
|
||
@Tag(name = "Questions") | ||
@RestController | ||
class QuestionController( | ||
private val questionService: QuestionService, | ||
) { | ||
@Auth | ||
@Operation(summary = "오늘의 질문") | ||
@GetMapping("/api/v1/questions/today") | ||
fun getQuestionToday( | ||
@MemberId memberId: Long, | ||
): ApiResponse<QuestionTodayResponseDto> = questionService.getQuestionToday(memberId).let { | ||
ApiResponse.success(toQuestionTodayResponseDto(it)) | ||
} | ||
|
||
@Auth | ||
@Operation(summary = "내가 답변한 질문 월별 조회") | ||
@GetMapping("/api/v1/questions/my") | ||
fun getQuestionsWhatIAnsweredMonthly( | ||
@MemberId memberId: Long, | ||
@RequestParam("yearMonth") @DateTimeFormat(pattern = "yyyyMM") selectedYearMonth: YearMonth, | ||
): ApiResponse<QuestionListResponseDto> = | ||
questionService.getQuestionsAnsweredMonthly(memberId, selectedYearMonth).let { | ||
ApiResponse.success(toQuestionListResponseDto(it)) | ||
} | ||
|
||
@Auth | ||
@Operation(summary = "답변 기록이 있는 년월 얻기") | ||
@GetMapping("/api/v1/questions/answeredDate") | ||
fun getYearMonthWhenIAnswered( | ||
@MemberId memberId: Long, | ||
): ApiResponse<QuestionAnsweredResponseDto> = | ||
questionService.getYearMonthAnswered(memberId).let { ApiResponse.success(toQuestionAnsweredResponse(it)) } | ||
} |
20 changes: 20 additions & 0 deletions
20
...api/src/main/kotlin/com/th/plu/api/controller/question/dto/QuestionAnsweredResponseDto.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,20 @@ | ||
package com.th.plu.api.controller.question.dto | ||
|
||
import java.time.YearMonth | ||
|
||
data class QuestionAnsweredResponseDto( | ||
val year: List<Int>, | ||
val yearMonth: List<YearMonthResponseDto> | ||
) | ||
|
||
data class YearMonthResponseDto( | ||
val year: Int, | ||
val month: Int, | ||
) | ||
|
||
internal fun toQuestionAnsweredResponse(yearMonths: Set<YearMonth>) = QuestionAnsweredResponseDto( | ||
year = yearMonths.map { it.year }.sortedDescending(), | ||
yearMonth = yearMonths.map { toYearMonthResponse(it) } | ||
) | ||
|
||
internal fun toYearMonthResponse(yearMonth: YearMonth) = YearMonthResponseDto(year = yearMonth.year, month = yearMonth.monthValue) |
13 changes: 13 additions & 0 deletions
13
plu-api/src/main/kotlin/com/th/plu/api/controller/question/dto/QuestionListResponseDto.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,13 @@ | ||
package com.th.plu.api.controller.question.dto | ||
|
||
import com.th.plu.domain.domain.question.QuestionResultDto | ||
|
||
data class QuestionListResponseDto( | ||
val answerCount: Int, | ||
val questions: List<QuestionResponseDto>, | ||
) | ||
|
||
internal fun toQuestionListResponseDto(resultList: List<QuestionResultDto>): QuestionListResponseDto = QuestionListResponseDto( | ||
answerCount = resultList.size, | ||
questions = resultList.map { toQuestionResponseDto(it) } | ||
) |
25 changes: 25 additions & 0 deletions
25
plu-api/src/main/kotlin/com/th/plu/api/controller/question/dto/QuestionResponseDto.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,25 @@ | ||
package com.th.plu.api.controller.question.dto | ||
|
||
import com.th.plu.domain.domain.question.ElementType | ||
import com.th.plu.domain.domain.question.QuestionResultDto | ||
import java.time.LocalDateTime | ||
|
||
data class QuestionResponseDto( | ||
val id: Long, | ||
val title: String, | ||
val content: String, | ||
val exposedAt: LocalDateTime, | ||
val characterImageUrl: String, | ||
val elementType: ElementType, | ||
val answered: Boolean, | ||
) | ||
|
||
internal fun toQuestionResponseDto(result: QuestionResultDto) = QuestionResponseDto( | ||
id = result.questionId, | ||
title = result.title, | ||
content = result.content, | ||
exposedAt = result.exposedAt, | ||
characterImageUrl = result.elementType.characterImageUrl, | ||
elementType = result.elementType, | ||
answered = result.answered, | ||
) |
11 changes: 11 additions & 0 deletions
11
plu-api/src/main/kotlin/com/th/plu/api/controller/question/dto/QuestionTodayResponseDto.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 com.th.plu.api.controller.question.dto | ||
|
||
import com.th.plu.domain.domain.question.QuestionResultDto | ||
|
||
data class QuestionTodayResponseDto( | ||
val question: QuestionResponseDto, | ||
) | ||
|
||
internal fun toQuestionTodayResponseDto(result: QuestionResultDto): QuestionTodayResponseDto = QuestionTodayResponseDto( | ||
question = toQuestionResponseDto(result) | ||
) |
Oops, something went wrong.