From 270ef5c3477ad8340ef88f3f2b21978feaa627d6 Mon Sep 17 00:00:00 2001 From: bayusamudra5502 <bayusamudra.55.02.com@gmail.com> Date: Fri, 31 Mar 2023 07:38:06 +0700 Subject: [PATCH] docs: add swagger --- docs/docs.go | 374 ++++++++++++++++++++++++++++ docs/swagger.json | 374 ++++++++++++++++++++++++++++ docs/swagger.yaml | 242 ++++++++++++++++++ handler/material/add_content.go | 14 ++ handler/material/create_material.go | 14 ++ handler/material/delete_content.go | 12 + handler/material/delete_material.go | 11 + handler/material/get_material.go | 10 + 8 files changed, 1051 insertions(+) diff --git a/docs/docs.go b/docs/docs.go index cb0a9f1..2bbdaff 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -480,6 +480,286 @@ const docTemplate = `{ } } }, + "/course/{id}/material": { + "post": { + "description": "Add new material", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "content" + ], + "summary": "Add Material", + "parameters": [ + { + "type": "string", + "description": "Access token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "description": "Material Request", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/material.CreateMaterialRequest" + } + }, + { + "type": "string", + "example": "IF3230", + "description": "Course id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/web.BaseResponse" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/material.CreateMaterialResponse" + } + } + } + ] + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/web.BaseResponse" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/web.BaseResponse" + } + } + } + } + }, + "/course/{id}/materials": { + "get": { + "description": "Get materials", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "content" + ], + "summary": "Get materials", + "parameters": [ + { + "type": "string", + "example": "IF3270", + "description": "Course id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/web.BaseResponse" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/material.Material" + } + } + } + } + ] + } + } + } + } + }, + "/material/{id}": { + "post": { + "description": "Add content of material", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "content" + ], + "summary": "Add Content", + "parameters": [ + { + "type": "string", + "description": "Access token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "description": "Add content request", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/material.NewContentRequest" + } + }, + { + "type": "string", + "format": "uuid", + "description": "Material id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/web.BaseResponse" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/material.NewContentResponse" + } + } + } + ] + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/web.BaseResponse" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/web.BaseResponse" + } + } + } + }, + "delete": { + "description": "Delete material", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "content" + ], + "summary": "Delete material", + "parameters": [ + { + "type": "string", + "description": "Access token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "string", + "format": "uuid", + "description": "Material id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/web.BaseResponse" + } + } + } + } + }, + "/material/{id}/content/{content-id}": { + "delete": { + "description": "Delete content of material", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "content" + ], + "summary": "Delete Content", + "parameters": [ + { + "type": "string", + "description": "Access token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "string", + "format": "uuid", + "description": "Material id", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "string", + "format": "uuid", + "description": "Content id", + "name": "content-id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/web.BaseResponse" + } + } + } + } + }, "/reset/confirm": { "put": { "description": "Do confirmation to reset password", @@ -733,6 +1013,100 @@ const docTemplate = `{ } } }, + "material.Content": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "link": { + "type": "string" + }, + "material_id": { + "type": "string" + }, + "type": { + "$ref": "#/definitions/material.MaterialType" + } + } + }, + "material.CreateMaterialRequest": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string" + } + } + }, + "material.CreateMaterialResponse": { + "type": "object", + "properties": { + "material_id": { + "type": "string" + } + } + }, + "material.Material": { + "type": "object", + "properties": { + "contents": { + "type": "array", + "items": { + "$ref": "#/definitions/material.Content" + } + }, + "course_id": { + "type": "string" + }, + "creator_email": { + "type": "string" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, + "material.MaterialType": { + "type": "integer", + "enum": [ + 1, + 2, + 3 + ], + "x-enum-varnames": [ + "Handout", + "Video", + "External" + ] + }, + "material.NewContentRequest": { + "type": "object", + "required": [ + "type" + ], + "properties": { + "link": { + "type": "string" + }, + "type": { + "$ref": "#/definitions/material.MaterialType" + } + } + }, + "material.NewContentResponse": { + "type": "object", + "properties": { + "upload_link": { + "type": "string" + } + } + }, "refresh.RefreshResponsePayload": { "description": "Refresh endpoint response when process success", "type": "object", diff --git a/docs/swagger.json b/docs/swagger.json index f89ae69..347524a 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -472,6 +472,286 @@ } } }, + "/course/{id}/material": { + "post": { + "description": "Add new material", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "content" + ], + "summary": "Add Material", + "parameters": [ + { + "type": "string", + "description": "Access token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "description": "Material Request", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/material.CreateMaterialRequest" + } + }, + { + "type": "string", + "example": "IF3230", + "description": "Course id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/web.BaseResponse" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/material.CreateMaterialResponse" + } + } + } + ] + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/web.BaseResponse" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/web.BaseResponse" + } + } + } + } + }, + "/course/{id}/materials": { + "get": { + "description": "Get materials", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "content" + ], + "summary": "Get materials", + "parameters": [ + { + "type": "string", + "example": "IF3270", + "description": "Course id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/web.BaseResponse" + }, + { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/material.Material" + } + } + } + } + ] + } + } + } + } + }, + "/material/{id}": { + "post": { + "description": "Add content of material", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "content" + ], + "summary": "Add Content", + "parameters": [ + { + "type": "string", + "description": "Access token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "description": "Add content request", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/material.NewContentRequest" + } + }, + { + "type": "string", + "format": "uuid", + "description": "Material id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "allOf": [ + { + "$ref": "#/definitions/web.BaseResponse" + }, + { + "type": "object", + "properties": { + "data": { + "$ref": "#/definitions/material.NewContentResponse" + } + } + } + ] + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/web.BaseResponse" + } + }, + "401": { + "description": "Unauthorized", + "schema": { + "$ref": "#/definitions/web.BaseResponse" + } + } + } + }, + "delete": { + "description": "Delete material", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "content" + ], + "summary": "Delete material", + "parameters": [ + { + "type": "string", + "description": "Access token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "string", + "format": "uuid", + "description": "Material id", + "name": "id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/web.BaseResponse" + } + } + } + } + }, + "/material/{id}/content/{content-id}": { + "delete": { + "description": "Delete content of material", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "content" + ], + "summary": "Delete Content", + "parameters": [ + { + "type": "string", + "description": "Access token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "string", + "format": "uuid", + "description": "Material id", + "name": "id", + "in": "path", + "required": true + }, + { + "type": "string", + "format": "uuid", + "description": "Content id", + "name": "content-id", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/web.BaseResponse" + } + } + } + } + }, "/reset/confirm": { "put": { "description": "Do confirmation to reset password", @@ -725,6 +1005,100 @@ } } }, + "material.Content": { + "type": "object", + "properties": { + "id": { + "type": "string" + }, + "link": { + "type": "string" + }, + "material_id": { + "type": "string" + }, + "type": { + "$ref": "#/definitions/material.MaterialType" + } + } + }, + "material.CreateMaterialRequest": { + "type": "object", + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string" + } + } + }, + "material.CreateMaterialResponse": { + "type": "object", + "properties": { + "material_id": { + "type": "string" + } + } + }, + "material.Material": { + "type": "object", + "properties": { + "contents": { + "type": "array", + "items": { + "$ref": "#/definitions/material.Content" + } + }, + "course_id": { + "type": "string" + }, + "creator_email": { + "type": "string" + }, + "id": { + "type": "string" + }, + "name": { + "type": "string" + } + } + }, + "material.MaterialType": { + "type": "integer", + "enum": [ + 1, + 2, + 3 + ], + "x-enum-varnames": [ + "Handout", + "Video", + "External" + ] + }, + "material.NewContentRequest": { + "type": "object", + "required": [ + "type" + ], + "properties": { + "link": { + "type": "string" + }, + "type": { + "$ref": "#/definitions/material.MaterialType" + } + } + }, + "material.NewContentResponse": { + "type": "object", + "properties": { + "upload_link": { + "type": "string" + } + } + }, "refresh.RefreshResponsePayload": { "description": "Refresh endpoint response when process success", "type": "object", diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 72093ff..54712e2 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -115,6 +115,68 @@ definitions: description: Token that used to generate new access token type: string type: object + material.Content: + properties: + id: + type: string + link: + type: string + material_id: + type: string + type: + $ref: '#/definitions/material.MaterialType' + type: object + material.CreateMaterialRequest: + properties: + name: + type: string + required: + - name + type: object + material.CreateMaterialResponse: + properties: + material_id: + type: string + type: object + material.Material: + properties: + contents: + items: + $ref: '#/definitions/material.Content' + type: array + course_id: + type: string + creator_email: + type: string + id: + type: string + name: + type: string + type: object + material.MaterialType: + enum: + - 1 + - 2 + - 3 + type: integer + x-enum-varnames: + - Handout + - Video + - External + material.NewContentRequest: + properties: + link: + type: string + type: + $ref: '#/definitions/material.MaterialType' + required: + - type + type: object + material.NewContentResponse: + properties: + upload_link: + type: string + type: object refresh.RefreshResponsePayload: description: Refresh endpoint response when process success properties: @@ -488,6 +550,186 @@ paths: summary: Send Email Verification tags: - auth + /course/{id}/material: + post: + consumes: + - application/json + description: Add new material + parameters: + - description: Access token + in: header + name: Authorization + required: true + type: string + - description: Material Request + in: body + name: data + required: true + schema: + $ref: '#/definitions/material.CreateMaterialRequest' + - description: Course id + example: IF3230 + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/web.BaseResponse' + - properties: + data: + $ref: '#/definitions/material.CreateMaterialResponse' + type: object + "400": + description: Bad Request + schema: + $ref: '#/definitions/web.BaseResponse' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/web.BaseResponse' + summary: Add Material + tags: + - content + /course/{id}/materials: + get: + consumes: + - application/json + description: Get materials + parameters: + - description: Course id + example: IF3270 + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/web.BaseResponse' + - properties: + data: + items: + $ref: '#/definitions/material.Material' + type: array + type: object + summary: Get materials + tags: + - content + /material/{id}: + delete: + consumes: + - application/json + description: Delete material + parameters: + - description: Access token + in: header + name: Authorization + required: true + type: string + - description: Material id + format: uuid + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/web.BaseResponse' + summary: Delete material + tags: + - content + post: + consumes: + - application/json + description: Add content of material + parameters: + - description: Access token + in: header + name: Authorization + required: true + type: string + - description: Add content request + in: body + name: data + required: true + schema: + $ref: '#/definitions/material.NewContentRequest' + - description: Material id + format: uuid + in: path + name: id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + allOf: + - $ref: '#/definitions/web.BaseResponse' + - properties: + data: + $ref: '#/definitions/material.NewContentResponse' + type: object + "400": + description: Bad Request + schema: + $ref: '#/definitions/web.BaseResponse' + "401": + description: Unauthorized + schema: + $ref: '#/definitions/web.BaseResponse' + summary: Add Content + tags: + - content + /material/{id}/content/{content-id}: + delete: + consumes: + - application/json + description: Delete content of material + parameters: + - description: Access token + in: header + name: Authorization + required: true + type: string + - description: Material id + format: uuid + in: path + name: id + required: true + type: string + - description: Content id + format: uuid + in: path + name: content-id + required: true + type: string + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/web.BaseResponse' + summary: Delete Content + tags: + - content /reset/confirm: put: description: Do confirmation to reset password diff --git a/handler/material/add_content.go b/handler/material/add_content.go index 3a6823f..4c8ab78 100644 --- a/handler/material/add_content.go +++ b/handler/material/add_content.go @@ -13,6 +13,20 @@ import ( "gitlab.informatika.org/ocw/ocw-backend/model/web/material" ) +// Index godoc +// +// @Tags content +// @Summary Add Content +// @Description Add content of material +// @Produce json +// @Accept json +// @Param Authorization header string true "Access token" +// @Param data body material.NewContentRequest true "Add content request" +// @Param id path string true "Material id" Format(uuid) +// @Success 200 {object} web.BaseResponse{data=material.NewContentResponse} +// @Success 400 {object} web.BaseResponse +// @Success 401 {object} web.BaseResponse +// @Router /material/{id} [post] func (m MaterialHandlerImpl) AddContent(w http.ResponseWriter, r *http.Request) { payload := material.NewContentRequest{} user, ok := r.Context().Value(guard.UserContext).(authToken.UserClaim) diff --git a/handler/material/create_material.go b/handler/material/create_material.go index de44a1b..0c19f25 100644 --- a/handler/material/create_material.go +++ b/handler/material/create_material.go @@ -11,6 +11,20 @@ import ( "gitlab.informatika.org/ocw/ocw-backend/model/web/material" ) +// Index godoc +// +// @Tags content +// @Summary Add Material +// @Description Add new material +// @Produce json +// @Accept json +// @Param Authorization header string true "Access token" +// @Param data body material.CreateMaterialRequest true "Material Request" +// @Param id path string true "Course id" example(IF3230) +// @Success 200 {object} web.BaseResponse{data=material.CreateMaterialResponse} +// @Success 400 {object} web.BaseResponse +// @Success 401 {object} web.BaseResponse +// @Router /course/{id}/material [post] func (m MaterialHandlerImpl) CreateMaterial(w http.ResponseWriter, r *http.Request) { payload := material.CreateMaterialRequest{} courseId := chi.URLParam(r, "id") diff --git a/handler/material/delete_content.go b/handler/material/delete_content.go index 8b5cfe0..e747539 100644 --- a/handler/material/delete_content.go +++ b/handler/material/delete_content.go @@ -10,6 +10,18 @@ import ( authToken "gitlab.informatika.org/ocw/ocw-backend/model/web/auth/token" ) +// Index godoc +// +// @Tags content +// @Summary Delete Content +// @Description Delete content of material +// @Produce json +// @Accept json +// @Param Authorization header string true "Access token" +// @Param id path string true "Material id" Format(uuid) +// @Param content-id path string true "Content id" Format(uuid) +// @Success 200 {object} web.BaseResponse +// @Router /material/{id}/content/{content-id} [delete] func (m MaterialHandlerImpl) DeleteContent(w http.ResponseWriter, r *http.Request) { materialIdUnparsed := chi.URLParam(r, "material-id") diff --git a/handler/material/delete_material.go b/handler/material/delete_material.go index 6451f07..8f03fba 100644 --- a/handler/material/delete_material.go +++ b/handler/material/delete_material.go @@ -10,6 +10,17 @@ import ( authToken "gitlab.informatika.org/ocw/ocw-backend/model/web/auth/token" ) +// Index godoc +// +// @Tags content +// @Summary Delete material +// @Description Delete material +// @Produce json +// @Accept json +// @Param Authorization header string true "Access token" +// @Param id path string true "Material id" Format(uuid) +// @Success 200 {object} web.BaseResponse +// @Router /material/{id} [delete] func (m MaterialHandlerImpl) DeleteMaterial(w http.ResponseWriter, r *http.Request) { materialIdUnparsed := chi.URLParam(r, "material-id") diff --git a/handler/material/get_material.go b/handler/material/get_material.go index f39195f..b4b56e0 100644 --- a/handler/material/get_material.go +++ b/handler/material/get_material.go @@ -7,6 +7,16 @@ import ( "gitlab.informatika.org/ocw/ocw-backend/model/web" ) +// Index godoc +// +// @Tags content +// @Summary Get materials +// @Description Get materials +// @Produce json +// @Accept json +// @Param id path string true "Course id" example(IF3270) +// @Success 200 {object} web.BaseResponse{data=[]material.Material} +// @Router /course/{id}/materials [get] func (m MaterialHandlerImpl) GetMaterial(w http.ResponseWriter, r *http.Request) { courseId := chi.URLParam(r, "id") -- GitLab