-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
fa127f3
commit a4857fa
Showing
8 changed files
with
201 additions
and
0 deletions.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
api/src/main/kotlin/com/few/api/web/controller/admin/AdminController.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,106 @@ | ||
package com.few.api.web.controller.admin | ||
|
||
import com.few.api.domain.admin.document.dto.* | ||
import com.few.api.domain.admin.document.usecase.AddArticleUseCase | ||
import com.few.api.domain.admin.document.usecase.AddWorkbookUseCase | ||
import com.few.api.domain.admin.document.usecase.ConvertContentUseCase | ||
import com.few.api.domain.admin.document.usecase.MapArticleUseCase | ||
import com.few.api.web.controller.admin.request.AddArticleRequest | ||
import com.few.api.web.controller.admin.request.AddWorkbookRequest | ||
import com.few.api.web.controller.admin.request.ConvertContentRequest | ||
import com.few.api.web.controller.admin.request.MapArticleRequest | ||
import com.few.api.web.controller.admin.response.AddArticleResponse | ||
import com.few.api.web.controller.admin.response.AddWorkbookResponse | ||
import com.few.api.web.controller.admin.response.ConvertContentResponse | ||
import com.few.api.web.support.ApiResponse | ||
import com.few.api.web.support.ApiResponseGenerator | ||
import com.few.api.web.support.MessageCode | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.http.MediaType | ||
import org.springframework.validation.annotation.Validated | ||
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 | ||
|
||
@Validated | ||
@RestController | ||
@RequestMapping(value = ["/api/v1/admin"]) | ||
class AdminController( | ||
private val addArticleUseCase: AddArticleUseCase, | ||
private val addWorkbookUseCase: AddWorkbookUseCase, | ||
private val mapArticleUseCase: MapArticleUseCase, | ||
private val convertContentUseCase: ConvertContentUseCase | ||
) { | ||
@PostMapping("/workbooks") | ||
fun addWorkbook(@RequestBody request: AddWorkbookRequest): ApiResponse<ApiResponse.SuccessBody<AddWorkbookResponse>> { | ||
val useCaseOut = AddWorkbookUseCaseIn( | ||
title = request.title, | ||
mainImageUrl = request.mainImageUrl, | ||
category = request.category, | ||
description = request.description | ||
).let { | ||
addWorkbookUseCase.execute(it) | ||
} | ||
|
||
return AddWorkbookResponse(useCaseOut.workbookId).let { | ||
ApiResponseGenerator.success(it, HttpStatus.OK) | ||
} | ||
} | ||
|
||
@PostMapping("/articles") | ||
fun addArticle( | ||
@RequestBody request: AddArticleRequest | ||
): ApiResponse<ApiResponse.SuccessBody<AddArticleResponse>> { | ||
val useCaseOut = AddArticleUseCaseIn( | ||
writerEmail = request.writerEmail, | ||
articleImageUrl = request.articleImageUrl, | ||
title = request.title, | ||
category = request.category, | ||
contentSource = request.contentSource, | ||
problemData = ProblemDetail( | ||
title = request.problemData.title, | ||
contents = request.problemData.contents.map { | ||
ProblemContentDetail( | ||
number = it.number, | ||
content = it.content | ||
) | ||
}, | ||
answer = request.problemData.answer, | ||
explanation = request.problemData.explanation | ||
) | ||
).let { useCaseIn -> | ||
addArticleUseCase.execute(useCaseIn) | ||
} | ||
|
||
return AddArticleResponse(useCaseOut).let { | ||
ApiResponseGenerator.success(it, HttpStatus.OK) | ||
} | ||
} | ||
|
||
@PostMapping("/relations/articles") | ||
fun mapArticle(@RequestBody request: MapArticleRequest): ApiResponse<ApiResponse.Success> { | ||
MapArticleUseCaseIn( | ||
workbookId = request.workbookId, | ||
articleId = request.articleId, | ||
dayCol = request.dayCol | ||
).let { | ||
mapArticleUseCase.execute(it) | ||
} | ||
|
||
return ApiResponseGenerator.success(HttpStatus.OK, MessageCode.RESOURCE_CREATED) | ||
} | ||
|
||
@PostMapping("/utilities/conversion/content", consumes = [MediaType.MULTIPART_FORM_DATA_VALUE]) | ||
fun convertContent( | ||
request: ConvertContentRequest | ||
): ApiResponse<ApiResponse.SuccessBody<ConvertContentResponse>> { | ||
val useCaseOut = ConvertContentUseCaseIn(request.content).let { | ||
convertContentUseCase.execute(it) | ||
} | ||
|
||
ConvertContentResponse(useCaseOut.content, useCaseOut.originDownLoadUrl).let { | ||
return ApiResponseGenerator.success(it, HttpStatus.OK) | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
api/src/main/kotlin/com/few/api/web/controller/admin/request/AddArticleRequest.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,34 @@ | ||
package com.few.api.web.controller.admin.request | ||
|
||
import jakarta.validation.constraints.NotBlank | ||
import java.net.URL | ||
|
||
data class AddArticleRequest( | ||
/** Article MST */ | ||
@field:NotBlank(message = "{email.notblank}") | ||
val writerEmail: String, | ||
@field:NotBlank(message = "{image.url.notblank}") | ||
val articleImageUrl: URL, | ||
@field:NotBlank(message = "{title.notblank}") | ||
val title: String, | ||
@field:NotBlank(message = "{category.notblank}") | ||
val category: String, | ||
/** Article IFO */ | ||
@field:NotBlank(message = "{content.source.notblank}") | ||
val contentSource: String, | ||
val problemData: ProblemDto | ||
) | ||
|
||
data class ProblemDto( | ||
@field:NotBlank(message = "{problem.title.notblank}") | ||
val title: String, | ||
val contents: List<ProblemContentDto>, | ||
@field:NotBlank(message = "{problem.answer.notblank}") | ||
val answer: String, | ||
@field:NotBlank(message = "{problem.explanation.notblank}") | ||
val explanation: String | ||
) | ||
data class ProblemContentDto( | ||
val number: Long, | ||
val content: String | ||
) |
15 changes: 15 additions & 0 deletions
15
api/src/main/kotlin/com/few/api/web/controller/admin/request/AddWorkbookRequest.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,15 @@ | ||
package com.few.api.web.controller.admin.request | ||
|
||
import jakarta.validation.constraints.NotBlank | ||
import java.net.URL | ||
|
||
data class AddWorkbookRequest( | ||
@field:NotBlank(message = "{workbook.title.notblank}") | ||
val title: String, | ||
@field:NotBlank(message = "{image.url.notblank}") | ||
val mainImageUrl: URL, | ||
@field:NotBlank(message = "{category.notblank}") | ||
val category: String, | ||
@field:NotBlank(message = "{workbook.description.notblank}") | ||
val description: String | ||
) |
7 changes: 7 additions & 0 deletions
7
api/src/main/kotlin/com/few/api/web/controller/admin/request/ConvertContentRequest.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 com.few.api.web.controller.admin.request | ||
|
||
import org.springframework.web.multipart.MultipartFile | ||
|
||
data class ConvertContentRequest( | ||
val content: MultipartFile | ||
) |
15 changes: 15 additions & 0 deletions
15
api/src/main/kotlin/com/few/api/web/controller/admin/request/MapArticleRequest.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,15 @@ | ||
package com.few.api.web.controller.admin.request | ||
|
||
import jakarta.validation.constraints.Max | ||
import jakarta.validation.constraints.Min | ||
import jakarta.validation.constraints.NotBlank | ||
|
||
data class MapArticleRequest( | ||
@field:NotBlank(message = "{min.id}") | ||
val workbookId: Long, | ||
@field:NotBlank(message = "{min.id}") | ||
val articleId: Long, | ||
@field:Min(value = 1, message = "{min.id}") | ||
@field:Max(value = 7, message = "{max.day}") | ||
val dayCol: Int | ||
) |
11 changes: 11 additions & 0 deletions
11
api/src/main/kotlin/com/few/api/web/controller/admin/response/AddArticleResponse.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.few.api.web.controller.admin.response | ||
|
||
import com.few.api.domain.admin.document.dto.AddArticleUseCaseOut | ||
|
||
data class AddArticleResponse( | ||
val articleId: Long | ||
) { | ||
constructor(useCaseOut: AddArticleUseCaseOut) : this( | ||
articleId = useCaseOut.articleId | ||
) | ||
} |
5 changes: 5 additions & 0 deletions
5
api/src/main/kotlin/com/few/api/web/controller/admin/response/AddWorkbookResponse.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.few.api.web.controller.admin.response | ||
|
||
data class AddWorkbookResponse( | ||
val workbookId: Long | ||
) |
8 changes: 8 additions & 0 deletions
8
api/src/main/kotlin/com/few/api/web/controller/admin/response/ConvertContentResponse.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,8 @@ | ||
package com.few.api.web.controller.admin.response | ||
|
||
import java.net.URL | ||
|
||
data class ConvertContentResponse( | ||
val content: String, | ||
val originDownLoadUrl: URL | ||
) |