diff --git a/docs/docs.go b/docs/docs.go index cb0a9f15cd85048e3c31dbb8c21139959e23b3dd..2bbdaff8e1a5b157ee32e364f8fc3b8f0cdd7ecf 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 f89ae6961a309970cc486d8abe9fdcab656521dd..347524a7ed0d12d203491c11bb782fd25477e17f 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 72093ff9594e71e7ccb9005fbf5c1d2c8f52474a..54712e298fb607ef19d713de3f948d5e9ce255de 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 3a6823fa495d825d95be1b612c8647c20fa94dc7..4c8ab785092385bbfe8a17c750fdb715edd9d57a 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 de44a1baadaab8130098fc59a8fa88c9e5c44846..0c19f25596b9d60fa158dd9dd5981c4632b6a1de 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 8b5cfe0a3cbaf79f7eb209fa8cbaccb4b2a58608..e7475399e30439489365fabb048bcf0837a97ca7 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 6451f0709eddf11bb429f64576ced94c67ef1c39..8f03fba29e225be9ef5954945a4dcf525ebe422c 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 f39195f784281d6dfa53f40535f6783b762c8699..b4b56e07691ce5a96294c380a93b6404eee0bb2a 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")