Skip to content

Commit

Permalink
feat: implement Graph Find API (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
kumachan-mis authored Sep 8, 2024
1 parent 9995ee4 commit e3c69ce
Show file tree
Hide file tree
Showing 31 changed files with 1,281 additions and 85 deletions.
1 change: 1 addition & 0 deletions cmd/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func main() {
router.POST("/api/papers/update", paperApi.HandleUpdate)

graphApi := api.NewGraphApi(graphUseCase)
router.POST("/api/graphs/find", graphApi.HandleFind)
router.POST("/api/graphs/sectionalize", graphApi.HandleSectionalize)

err = router.Run(":8080")
Expand Down
4 changes: 2 additions & 2 deletions docs/openapi/paths/_index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
$ref: ./papers/find.yaml
/api/papers/update:
$ref: ./papers/update.yaml
/api/graphs/sectionalize:
$ref: ./graphs/sectionalize.yaml
/api/graphs/find:
$ref: ./graphs/find.yaml
/api/graphs/update:
$ref: ./graphs/update.yaml
/api/graphs/sectionalize:
$ref: ./graphs/sectionalize.yaml
7 changes: 0 additions & 7 deletions docs/openapi/schemas/entity/graph/GraphOnlyIdError.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
type: object
description: Graph object with only ID
description: Section object with only ID
properties:
id:
type: string
description: Auto-generated graph ID
description: Auto-generated section ID
example: 123e4567-e89b-12d3-a456-426614174000
required:
- id
7 changes: 7 additions & 0 deletions docs/openapi/schemas/entity/section/SectionOnlyIdError.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type: object
description: Error Message for SectionOnlyId object
properties:
id:
type: string
description: Error message for section ID
example: "section id is required, but got ''"
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ properties:
$ref: ../../../entity/project/ProjectOnlyIdError.yaml
chapter:
$ref: ../../../entity/chapter/ChapterOnlyIdError.yaml
graph:
$ref: ../../../entity/graph/GraphOnlyIdError.yaml
section:
$ref: ../../../entity/section/SectionOnlyIdError.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ properties:
$ref: ../../../entity/project/ProjectOnlyId.yaml
chapter:
$ref: ../../../entity/chapter/ChapterOnlyId.yaml
graph:
$ref: ../../../entity/graph/GraphOnlyId.yaml
section:
$ref: ../../../entity/section/SectionOnlyId.yaml
required:
- user
- project
- chapter
- graph
- section
Binary file not shown.
Binary file modified fixtures/firestore_export/all_namespaces/all_kinds/output-0
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions internal/api/chapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ func TestChapterList(t *testing.T) {
"sections": []any{
map[string]any{
"id": "SECTION_ONE",
"name": "Section One",
"name": "Introduction",
},
map[string]any{
"id": "SECTION_TWO",
"name": "Section Two",
"name": "Section of Chapter One",
},
},
},
Expand Down
41 changes: 41 additions & 0 deletions internal/api/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

type GraphApi interface {
HandleFind(c *gin.Context)
HandleSectionalize(c *gin.Context)
}

Expand All @@ -20,6 +21,46 @@ func NewGraphApi(usecase usecase.GraphUseCase) GraphApi {
return graphApi{usecase: usecase}
}

func (api graphApi) HandleFind(c *gin.Context) {
var request model.GraphFindRequest
if err := c.ShouldBindJSON(&request); err != nil {
c.JSON(http.StatusBadRequest, model.GraphFindErrorResponse{
Message: JsonBindErrorToMessage(err),
})
return
}

res, ucErr := api.usecase.FindGraph(request)

if ucErr != nil && ucErr.Code() == usecase.DomainValidationError {
resErr := UseCaseErrorToResponse(ucErr)
c.JSON(http.StatusBadRequest, model.GraphFindErrorResponse{
Message: UseCaseErrorToMessage(ucErr),
User: resErr.User,
Project: resErr.Project,
Chapter: resErr.Chapter,
Section: resErr.Section,
})
return
}

if ucErr != nil && ucErr.Code() == usecase.NotFoundError {
c.JSON(http.StatusNotFound, model.GraphFindErrorResponse{
Message: UseCaseErrorToMessage(ucErr),
})
return
}

if ucErr != nil {
c.JSON(http.StatusInternalServerError, model.ApplicationErrorResponse{
Message: UseCaseErrorToMessage(ucErr),
})
return
}

c.JSON(http.StatusOK, res)
}

func (api graphApi) HandleSectionalize(c *gin.Context) {
var request model.GraphSectionalizeRequest
if err := c.ShouldBindJSON(&request); err != nil {
Expand Down
Loading

0 comments on commit e3c69ce

Please sign in to comment.