From 0b70bc48005e6ed249cd26b77b007c6f9c285be0 Mon Sep 17 00:00:00 2001 From: bayusamudra5502 <bayusamudra.55.02.com@gmail.com> Date: Fri, 28 Apr 2023 22:31:38 +0700 Subject: [PATCH] fix: bugs on add material --- docs/docs.go | 8 ++++++-- docs/swagger.json | 8 ++++++-- docs/swagger.yaml | 5 ++++- handler/material/create_material.go | 1 + model/web/material/material.go | 1 + repository/material/material.go | 7 ++++--- repository/material/type.go | 4 ++-- service/material/impl.go | 4 ++-- service/material/type.go | 2 +- 9 files changed, 27 insertions(+), 13 deletions(-) diff --git a/docs/docs.go b/docs/docs.go index c5b288a..b498e6d 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -2247,7 +2247,7 @@ const docTemplate = `{ "required": true }, { - "description": "Add Course payload", + "description": "Add Quiz payload", "name": "data", "in": "body", "required": true, @@ -2990,11 +2990,15 @@ const docTemplate = `{ "material.CreateMaterialRequest": { "type": "object", "required": [ - "name" + "name", + "week" ], "properties": { "name": { "type": "string" + }, + "week": { + "type": "integer" } } }, diff --git a/docs/swagger.json b/docs/swagger.json index f3f2ef2..35bc431 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -2239,7 +2239,7 @@ "required": true }, { - "description": "Add Course payload", + "description": "Add Quiz payload", "name": "data", "in": "body", "required": true, @@ -2982,11 +2982,15 @@ "material.CreateMaterialRequest": { "type": "object", "required": [ - "name" + "name", + "week" ], "properties": { "name": { "type": "string" + }, + "week": { + "type": "integer" } } }, diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 969534e..5776745 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -285,8 +285,11 @@ definitions: properties: name: type: string + week: + type: integer required: - name + - week type: object material.CreateMaterialResponse: properties: @@ -2013,7 +2016,7 @@ paths: name: id required: true type: string - - description: Add Course payload + - description: Add Quiz payload in: body name: data required: true diff --git a/handler/material/create_material.go b/handler/material/create_material.go index 5556556..d0c0e83 100644 --- a/handler/material/create_material.go +++ b/handler/material/create_material.go @@ -82,6 +82,7 @@ func (m MaterialHandlerImpl) CreateMaterial(w http.ResponseWriter, r *http.Reque courseId, user.Email, payload.Name, + payload.Week, ) if err != nil { diff --git a/model/web/material/material.go b/model/web/material/material.go index 98f8c6c..84da097 100644 --- a/model/web/material/material.go +++ b/model/web/material/material.go @@ -4,6 +4,7 @@ import "github.com/google/uuid" type CreateMaterialRequest struct { Name string `json:"name" validate:"required"` + Week int `json:"week" validate:"required"` } type CreateMaterialResponse struct { diff --git a/repository/material/material.go b/repository/material/material.go index 87cbd43..3618779 100644 --- a/repository/material/material.go +++ b/repository/material/material.go @@ -35,16 +35,17 @@ func (m MaterialRepositoryImpl) IsUserContributor(id uuid.UUID, email string) (b return true, nil } -func (m MaterialRepositoryImpl) New(courseId string, creatorEmail string, name string) (uuid.UUID, error) { - return m.NewWithTransaction(m.builder.Build(), courseId, creatorEmail, name) +func (m MaterialRepositoryImpl) New(courseId string, creatorEmail string, name string, week int) (uuid.UUID, error) { + return m.NewWithTransaction(m.builder.Build(), courseId, creatorEmail, name, week) } -func (m MaterialRepositoryImpl) NewWithTransaction(tx transaction.Transaction, courseId string, creatorEmail string, name string) (uuid.UUID, error) { +func (m MaterialRepositoryImpl) NewWithTransaction(tx transaction.Transaction, courseId string, creatorEmail string, name string, week int) (uuid.UUID, error) { materialData := &material.Material{ ID: uuid.New(), CourseId: courseId, CreatorEmail: creatorEmail, Name: name, + Week: week, } err := tx.GetTransaction().Create(materialData).Error diff --git a/repository/material/type.go b/repository/material/type.go index 4014763..6e8ddc9 100644 --- a/repository/material/type.go +++ b/repository/material/type.go @@ -7,14 +7,14 @@ import ( ) type MaterialRepository interface { - New(courseId string, creatorEmail string, name string) (uuid.UUID, error) + New(courseId string, creatorEmail string, name string, week int) (uuid.UUID, error) Delete(id uuid.UUID) error Get(materialId uuid.UUID) (*material.Material, error) GetAll(courseId string) ([]material.Material, error) IsUserContributor(id uuid.UUID, email string) (bool, error) - NewWithTransaction(tx transaction.Transaction, courseId string, creatorEmail string, name string) (uuid.UUID, error) + NewWithTransaction(tx transaction.Transaction, courseId string, creatorEmail string, name string, week int) (uuid.UUID, error) DeleteWithTransaction(tx transaction.Transaction, id uuid.UUID) error GetAllWithTransaction(tx transaction.Transaction, courseId string) ([]material.Material, error) } diff --git a/service/material/impl.go b/service/material/impl.go index c50b675..02a5b42 100644 --- a/service/material/impl.go +++ b/service/material/impl.go @@ -32,14 +32,14 @@ func (m MaterialServiceImpl) GetById(materialId uuid.UUID) (*materialDomain.Mate return material, err } -func (m MaterialServiceImpl) Create(courseId string, email string, name string) (uuid.UUID, error) { +func (m MaterialServiceImpl) Create(courseId string, email string, name string, week int) (uuid.UUID, error) { isSuccess := false tx := m.TransactionBuilder.Build() tx.Begin() defer tx.Auto(&isSuccess) - id, err := m.MaterialRepository.NewWithTransaction(tx, courseId, email, name) + id, err := m.MaterialRepository.NewWithTransaction(tx, courseId, email, name, week) if err != nil { return uuid.Nil, err diff --git a/service/material/type.go b/service/material/type.go index ca617ce..9cc1f19 100644 --- a/service/material/type.go +++ b/service/material/type.go @@ -6,7 +6,7 @@ import ( ) type MaterialService interface { - Create(courseId string, email string, name string) (uuid.UUID, error) + Create(courseId string, email string, name string, week int) (uuid.UUID, error) Delete(materialId uuid.UUID, email string) error Get(courseId string) ([]material.Material, error) GetById(materialId uuid.UUID) (*material.Material, error) -- GitLab