Skip to content

Commit

Permalink
feat: implement Graph Update API (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
kumachan-mis authored Sep 14, 2024
1 parent eb31fe4 commit 413b169
Show file tree
Hide file tree
Showing 29 changed files with 1,199 additions and 51 deletions.
1 change: 1 addition & 0 deletions cmd/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func main() {

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

err = router.Run(":8080")
Expand Down
18 changes: 18 additions & 0 deletions docs/openapi/schemas/entity/graph/GraphContent.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
type: object
description: Graph object with only content fields
properties:
id:
type: string
description: Auto-generated section ID
example: 123e4567-e89b-12d3-a456-426614174000
paragraph:
type: string
maxLength: 40000
description: Graph paragraph
example: |
## Introduction
This is the introduction of the paper.
required:
- id
- name
- paragraph
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
type: object
description: Error Message for Graph object
description: Error Message for GraphContent object
properties:
id:
type: string
description: Error message for graph ID
example: "graph id is required, but got ''"
name:
type: string
description: Error message for graph name
example: graph name is required, but got ''
paragraph:
type: string
description: Error message for graph paragraph
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ properties:
chapter:
$ref: ../../../entity/chapter/ChapterOnlyIdError.yaml
graph:
$ref: ../../../entity/graph/GraphError.yaml
$ref: ../../../entity/graph/GraphContentError.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ properties:
chapter:
$ref: ../../../entity/chapter/ChapterOnlyId.yaml
graph:
$ref: ../../../entity/graph/Graph.yaml
$ref: ../../../entity/graph/GraphContent.yaml
required:
- user
- project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ type: object
description: Response Body for Graph Update API
properties:
graph:
$ref: ../../../entity/graph/Graph.yaml
$ref: ../../../entity/graph/GraphContent.yaml
required:
- graph
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 @@ -90,7 +90,7 @@ func TestChapterListEmpty(t *testing.T) {
})
}

func TestChapterListProjectNotFound(t *testing.T) {
func TestChapterListNotFound(t *testing.T) {
tt := []struct {
name string
request map[string]any
Expand Down Expand Up @@ -302,7 +302,7 @@ func TestChapterCreate(t *testing.T) {
}, responseBody)
}

func TestChapterCreateProjectNotFound(t *testing.T) {
func TestChapterCreateNotFound(t *testing.T) {
tt := []struct {
name string
request map[string]any
Expand Down
41 changes: 41 additions & 0 deletions internal/api/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

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

Expand Down Expand Up @@ -61,6 +62,46 @@ func (api graphApi) HandleFind(c *gin.Context) {
c.JSON(http.StatusOK, res)
}

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

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

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

if ucErr != nil && ucErr.Code() == usecase.NotFoundError {
c.JSON(http.StatusNotFound, model.GraphUpdateErrorResponse{
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 413b169

Please sign in to comment.