-
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.
feat: implement Paper Find API (#69)
- Loading branch information
1 parent
4e4cb6e
commit eb9f0c3
Showing
27 changed files
with
1,168 additions
and
23 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
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
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
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 @@ | ||
post: | ||
tags: | ||
- Papers | ||
operationId: papers-find | ||
summary: Find paper | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
$ref: ../../schemas/interface/papers/find/PaperFindRequest.yaml | ||
responses: | ||
"200": | ||
description: OK - Returns found paper | ||
content: | ||
application/json: | ||
schema: | ||
$ref: ../../schemas/interface/papers/find/PaperFindResponse.yaml | ||
"400": | ||
description: Bad Request - Invalid request | ||
content: | ||
application/json: | ||
schema: | ||
$ref: ../../schemas/interface/papers/find/PaperFindErrorResponse.yaml | ||
"404": | ||
description: Not Found - Paper not found or not authorized | ||
content: | ||
application/json: | ||
schema: | ||
$ref: ../../schemas/interface/papers/find/PaperFindErrorResponse.yaml | ||
"500": | ||
description: Internal Server Error - Server error | ||
content: | ||
application/json: | ||
schema: | ||
$ref: ../../schemas/interface/app/ApplicationErrorResponse.yaml |
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,9 @@ | ||
type: object | ||
description: Chapter object with only ID | ||
properties: | ||
id: | ||
type: string | ||
description: Auto-generated chapter ID | ||
example: 123e4567-e89b-12d3-a456-426614174000 | ||
required: | ||
- 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,7 @@ | ||
type: object | ||
description: Error Message for ChapterOnlyId object | ||
properties: | ||
id: | ||
type: string | ||
description: Error message for project ID | ||
example: "project id is required, but got ''" |
13 changes: 13 additions & 0 deletions
13
docs/openapi/schemas/interface/papers/find/PaperFindErrorResponse.yaml
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 @@ | ||
type: object | ||
description: Request Body for Paper Find API | ||
properties: | ||
message: | ||
type: string | ||
description: Error message when request body format is invalid | ||
example: unexpected EOF | ||
user: | ||
$ref: ../../../entity/user/UserOnlyIdError.yaml | ||
project: | ||
$ref: ../../../entity/project/ProjectOnlyIdError.yaml | ||
chapter: | ||
$ref: ../../../entity/chapter/ChapterOnlyIdError.yaml |
13 changes: 13 additions & 0 deletions
13
docs/openapi/schemas/interface/papers/find/PaperFindRequest.yaml
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 @@ | ||
type: object | ||
description: Request Body for Paper Find API | ||
properties: | ||
user: | ||
$ref: ../../../entity/user/UserOnlyId.yaml | ||
project: | ||
$ref: ../../../entity/project/ProjectOnlyId.yaml | ||
chapter: | ||
$ref: ../../../entity/chapter/ChapterOnlyId.yaml | ||
required: | ||
- user | ||
- project | ||
- chapter |
7 changes: 7 additions & 0 deletions
7
docs/openapi/schemas/interface/papers/find/PaperFindResponse.yaml
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 @@ | ||
type: object | ||
description: Request Body for Paper Find API | ||
properties: | ||
paper: | ||
$ref: ../../../entity/paper/Paper.yaml | ||
required: | ||
- paper |
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
Binary file modified
BIN
+0 Bytes
(100%)
fixtures/firestore_export/all_namespaces/all_kinds/all_namespaces_all_kinds.export_metadata
Binary file not shown.
Binary file modified
BIN
+1.07 KB
(120%)
fixtures/firestore_export/all_namespaces/all_kinds/output-0
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
fixtures/firestore_export/firestore_export.overall_export_metadata
Binary file not shown.
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,60 @@ | ||
package api | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/kumachan-mis/knodeledge-api/internal/model" | ||
"github.com/kumachan-mis/knodeledge-api/internal/usecase" | ||
) | ||
|
||
type PaperApi interface { | ||
HandleFind(c *gin.Context) | ||
} | ||
|
||
type paperApi struct { | ||
usecase usecase.PaperUseCase | ||
} | ||
|
||
func NewPaperApi(usecase usecase.PaperUseCase) PaperApi { | ||
return paperApi{usecase: usecase} | ||
} | ||
|
||
func (api paperApi) HandleFind(c *gin.Context) { | ||
var request model.PaperFindRequest | ||
if err := c.ShouldBindJSON(&request); err != nil { | ||
c.JSON(http.StatusBadRequest, model.PaperFindErrorResponse{ | ||
Message: JsonBindErrorToMessage(err), | ||
}) | ||
return | ||
} | ||
|
||
res, ucErr := api.usecase.FindPaper(request) | ||
|
||
if ucErr != nil && ucErr.Code() == usecase.DomainValidationError { | ||
resErr := UseCaseErrorToResponse(ucErr) | ||
c.JSON(http.StatusBadRequest, model.PaperFindErrorResponse{ | ||
Message: UseCaseErrorToMessage(ucErr), | ||
User: resErr.User, | ||
Project: resErr.Project, | ||
Chapter: resErr.Chapter, | ||
}) | ||
return | ||
} | ||
|
||
if ucErr != nil && ucErr.Code() == usecase.NotFoundError { | ||
c.JSON(http.StatusNotFound, model.PaperFindErrorResponse{ | ||
Message: UseCaseErrorToMessage(ucErr), | ||
}) | ||
return | ||
} | ||
|
||
if ucErr != nil { | ||
c.JSON(http.StatusInternalServerError, model.ApplicationErrorResponse{ | ||
Message: UseCaseErrorToMessage(ucErr), | ||
}) | ||
return | ||
} | ||
|
||
c.JSON(http.StatusOK, res) | ||
} |
Oops, something went wrong.