Skip to content

Commit

Permalink
feat: enable to return sections from Chapter API (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
kumachan-mis authored Aug 11, 2024
1 parent d0508e4 commit d0c39c4
Show file tree
Hide file tree
Showing 50 changed files with 1,132 additions and 128 deletions.
2 changes: 2 additions & 0 deletions docs/openapi/paths/_index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
$ref: ./papers/find.yaml
/api/papers/update:
$ref: ./papers/update.yaml
/api/papers/sectionalize:
$ref: ./papers/sectionalize.yaml
35 changes: 35 additions & 0 deletions docs/openapi/paths/papers/sectionalize.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
post:
tags:
- Papers
operationId: papers-sectionalize
summary: Sectionalize paper
requestBody:
content:
application/json:
schema:
$ref: ../../schemas/interface/papers/sectionalize/PaperSectionalizeRequest.yaml
responses:
"200":
description: OK - Returns sectionalized paper
content:
application/json:
schema:
$ref: ../../schemas/interface/papers/sectionalize/PaperSectionalizeResponse.yaml
"400":
description: Bad Request - Invalid request
content:
application/json:
schema:
$ref: ../../schemas/interface/papers/sectionalize/PaperSectionalizeErrorResponse.yaml
"404":
description: Not Found - Paper not found or not authorized
content:
application/json:
schema:
$ref: ../../schemas/interface/papers/sectionalize/PaperSectionalizeErrorResponse.yaml
"500":
description: Internal Server Error - Server error
content:
application/json:
schema:
$ref: ../../schemas/interface/app/ApplicationErrorResponse.yaml
2 changes: 1 addition & 1 deletion docs/openapi/schemas/entity/chapter/ChapterError.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Error Message for Chapter object
properties:
id:
type: string
description: Error message for chapter id
description: Error message for chapter ID
example: chapter id is required, but got ''
name:
type: string
Expand Down
4 changes: 2 additions & 2 deletions docs/openapi/schemas/entity/chapter/ChapterOnlyIdError.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ description: Error Message for ChapterOnlyId object
properties:
id:
type: string
description: Error message for project ID
example: "project id is required, but got ''"
description: Error message for chapter ID
example: "chapter id is required, but got ''"
2 changes: 1 addition & 1 deletion docs/openapi/schemas/entity/paper/PaperError.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Error Message for Paper object
properties:
id:
type: string
description: Error message for paper id
description: Error message for paper ID
example: paper id is required, but got ''
content:
type: string
Expand Down
9 changes: 9 additions & 0 deletions docs/openapi/schemas/entity/paper/PaperOnlyId.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type: object
description: Paper object with only ID
properties:
id:
type: string
description: Auto-generated paper ID
example: 123e4567-e89b-12d3-a456-426614174000
required:
- id
7 changes: 7 additions & 0 deletions docs/openapi/schemas/entity/paper/PaperOnlyIdError.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type: object
description: Error Message for PaperOnlyId object
properties:
id:
type: string
description: Error message for paper ID
example: "paper id is required, but got ''"
2 changes: 1 addition & 1 deletion docs/openapi/schemas/entity/project/ProjectError.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Error Message for Project object
properties:
id:
type: string
description: Error message for project id
description: Error message for project ID
example: project id is required, but got ''
name:
type: string
Expand Down
11 changes: 11 additions & 0 deletions docs/openapi/schemas/entity/section/SectionWithoutAutofield.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type: object
description: Section object without auto-generated fields
properties:
name:
type: string
maxLength: 100
description: Section name
example: Overview
required:
- name
- content
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type: object
description: Error Message for SectionWithoutAutofield object
properties:
name:
type: string
description: Error message for section name
example: section name is required, but got ''
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
type: object
description: Error Response Body for Paper Sectionalize API
properties:
user:
$ref: ../../../entity/user/UserOnlyIdError.yaml
project:
$ref: ../../../entity/project/ProjectOnlyIdError.yaml
paper:
$ref: ../../../entity/paper/PaperOnlyIdError.yaml
sections:
type: array
items:
$ref: ../../../entity/section/SectionWithoutAutofieldError.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
type: object
description: Request Body for Paper Sectionalize API
properties:
user:
$ref: ../../../entity/user/UserOnlyId.yaml
project:
$ref: ../../../entity/project/ProjectOnlyId.yaml
paper:
$ref: ../../../entity/paper/PaperOnlyId.yaml
sections:
type: array
items:
$ref: ../../../entity/section/SectionWithoutAutofield.yaml
required:
- user
- project
- paper
- sections
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
type: object
description: Response Body for Paper Sectionalize API
properties:
sections:
type: array
items:
$ref: ../../../entity/section/Section.yaml
required:
- sections
4 changes: 2 additions & 2 deletions fixtures/firebase-export-metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "13.9.0",
"version": "13.13.0",
"firestore": {
"version": "1.19.6",
"version": "1.19.7",
"path": "firestore_export",
"metadata_file": "firestore_export/firestore_export.overall_export_metadata"
}
Expand Down
Binary file not shown.
Binary file modified fixtures/firestore_export/all_namespaces/all_kinds/output-0
Binary file not shown.
Binary file not shown.
17 changes: 13 additions & 4 deletions internal/api/chapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,19 @@ func TestChapterList(t *testing.T) {
assert.Equal(t, map[string]any{
"chapters": []any{
map[string]any{
"id": "CHAPTER_ONE",
"name": "Chapter One",
"number": float64(1), // json.Unmarshal converts number to float64
"sections": []any{},
"id": "CHAPTER_ONE",
"name": "Chapter One",
"number": float64(1), // json.Unmarshal converts number to float64
"sections": []any{
map[string]any{
"id": "SECTION_ONE",
"name": "Section One",
},
map[string]any{
"id": "SECTION_TWO",
"name": "Section Two",
},
},
},
map[string]any{
"id": "CHAPTER_TWO",
Expand Down
4 changes: 2 additions & 2 deletions internal/api/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ func TestProjectFindInternalError(t *testing.T) {
"id": testutil.ErrorUserId(0),
},
"project": map[string]any{
"id": "PROJECT_WITH_NAME_ERROR",
"id": "PROJECT_WITH_INVALID_NAME",
},
})
req, _ := http.NewRequest("POST", "/api/projects/find", strings.NewReader(string(requestBody)))
Expand Down Expand Up @@ -908,7 +908,7 @@ func TestProjectUpdateInternalError(t *testing.T) {
"id": testutil.ErrorUserId(0),
},
"project": map[string]any{
"id": "PROJECT_WITH_NAME_ERROR",
"id": "PROJECT_WITH_INVALID_NAME",
"name": "Updated Project",
},
})
Expand Down
12 changes: 9 additions & 3 deletions internal/document/document_chapter_values.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ package document
import "time"

type ChapterValues struct {
Name string `firestore:"name"`
CreatedAt time.Time `firestore:"createdAt"`
UpdatedAt time.Time `firestore:"updatedAt"`
Name string `firestore:"name"`
Sections []SectionValues `firestore:"sections"`
CreatedAt time.Time `firestore:"createdAt"`
UpdatedAt time.Time `firestore:"updatedAt"`
}

type SectionValues struct {
Id string `firestore:"id"`
Name string `firestore:"name"`
}
1 change: 1 addition & 0 deletions internal/document/document_project_values.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "time"
type ProjectValues struct {
Name string `firestore:"name"`
Description string `firestore:"description,omitempty"`
ChapterIds []string `firestore:"chapterIds,omitempty"`
UserId string `firestore:"userId"`
CreatedAt time.Time `firestore:"createdAt"`
UpdatedAt time.Time `firestore:"updatedAt"`
Expand Down
12 changes: 0 additions & 12 deletions internal/document/document_project_with_chapter_ids_values.go

This file was deleted.

7 changes: 7 additions & 0 deletions internal/domain/chapter_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type ChapterEntity struct {
id ChapterIdObject
name ChapterNameObject
number ChapterNumberObject
sections []SectionEntity
createdAt CreatedAtObject
updatedAt UpdatedAtObject
}
Expand All @@ -12,6 +13,7 @@ func NewChapterEntity(
id ChapterIdObject,
name ChapterNameObject,
number ChapterNumberObject,
sections []SectionEntity,
createdAt CreatedAtObject,
updatedAt UpdatedAtObject,

Expand All @@ -20,6 +22,7 @@ func NewChapterEntity(
id: id,
name: name,
number: number,
sections: sections,
createdAt: createdAt,
updatedAt: updatedAt,
}
Expand All @@ -37,6 +40,10 @@ func (e *ChapterEntity) Number() *ChapterNumberObject {
return &e.number
}

func (e *ChapterEntity) Sections() []SectionEntity {
return e.sections
}

func (e *ChapterEntity) CreatedAt() *CreatedAtObject {
return &e.createdAt
}
Expand Down
16 changes: 11 additions & 5 deletions internal/domain/chapter_without_autofield_entity.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package domain

type ChapterWithoutAutofieldEntity struct {
name ChapterNameObject
number ChapterNumberObject
name ChapterNameObject
number ChapterNumberObject
sections []SectionWithoutAutofieldEntity
}

func NewChapterWithoutAutofieldEntity(
name ChapterNameObject,
number ChapterNumberObject,

sections []SectionWithoutAutofieldEntity,
) *ChapterWithoutAutofieldEntity {
return &ChapterWithoutAutofieldEntity{
name: name,
number: number,
name: name,
number: number,
sections: sections,
}
}

Expand All @@ -23,3 +25,7 @@ func (e *ChapterWithoutAutofieldEntity) Name() *ChapterNameObject {
func (e *ChapterWithoutAutofieldEntity) Number() *ChapterNumberObject {
return &e.number
}

func (e *ChapterWithoutAutofieldEntity) Sections() []SectionWithoutAutofieldEntity {
return e.sections
}
38 changes: 38 additions & 0 deletions internal/domain/section_entity.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package domain

type SectionEntity struct {
id SectionIdObject
name SectionNameObject
createdAt CreatedAtObject
updatedAt UpdatedAtObject
}

func NewSectionEntity(
id SectionIdObject,
name SectionNameObject,
createdAt CreatedAtObject,
updatedAt UpdatedAtObject,
) *SectionEntity {
return &SectionEntity{
id: id,
name: name,
createdAt: createdAt,
updatedAt: updatedAt,
}
}

func (e *SectionEntity) Id() *SectionIdObject {
return &e.id
}

func (e *SectionEntity) Name() *SectionNameObject {
return &e.name
}

func (e *SectionEntity) CreatedAt() *CreatedAtObject {
return &e.createdAt
}

func (e *SectionEntity) UpdatedAt() *UpdatedAtObject {
return &e.updatedAt
}
18 changes: 18 additions & 0 deletions internal/domain/section_id_object.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package domain

import "fmt"

type SectionIdObject struct {
value string
}

func NewSectionIdObject(sectionId string) (*SectionIdObject, error) {
if sectionId == "" {
return nil, fmt.Errorf("section id is required, but got '%v'", sectionId)
}
return &SectionIdObject{value: sectionId}, nil
}

func (o *SectionIdObject) Value() string {
return o.value
}
21 changes: 21 additions & 0 deletions internal/domain/section_name_object.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package domain

import "fmt"

type SectionNameObject struct {
value string
}

func NewSectionNameObject(name string) (*SectionNameObject, error) {
if name == "" {
return nil, fmt.Errorf("section name is required, but got '%v'", name)
}
if len(name) > 100 {
return nil, fmt.Errorf("section name cannot be longer than 100 characters, but got '%v'", name)
}
return &SectionNameObject{value: name}, nil
}

func (o *SectionNameObject) Value() string {
return o.value
}
Loading

0 comments on commit d0c39c4

Please sign in to comment.