diff --git a/backend/docs/docs.go b/backend/docs/docs.go index 0ee1eaa..7579b6b 100644 --- a/backend/docs/docs.go +++ b/backend/docs/docs.go @@ -44,6 +44,45 @@ const docTemplate = `{ } } }, + "/labels/delete/{:gid}/{:lname}": { + "delete": { + "description": "delete a label", + "tags": [ + "labels" + ], + "summary": "Delete A Label", + "parameters": [ + { + "type": "string", + "description": "Group to delete label from", + "name": ":gid", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Name of label to delete", + "name": ":lname", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.Label" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "string" + } + } + } + } + }, "/labels/new": { "post": { "description": "create a new label for a group", @@ -204,7 +243,7 @@ const docTemplate = `{ { "type": "string", "description": "Task ID to assign users to", - "name": "tid", + "name": ":tid", "in": "path", "required": true }, @@ -248,7 +287,7 @@ const docTemplate = `{ { "type": "string", "description": "Task ID to remove users from", - "name": "tid", + "name": ":tid", "in": "path", "required": true }, diff --git a/backend/docs/swagger.json b/backend/docs/swagger.json index c8ba444..376e99d 100644 --- a/backend/docs/swagger.json +++ b/backend/docs/swagger.json @@ -37,6 +37,45 @@ } } }, + "/labels/delete/{:gid}/{:lname}": { + "delete": { + "description": "delete a label", + "tags": [ + "labels" + ], + "summary": "Delete A Label", + "parameters": [ + { + "type": "string", + "description": "Group to delete label from", + "name": ":gid", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "Name of label to delete", + "name": ":lname", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/models.Label" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "type": "string" + } + } + } + } + }, "/labels/new": { "post": { "description": "create a new label for a group", @@ -197,7 +236,7 @@ { "type": "string", "description": "Task ID to assign users to", - "name": "tid", + "name": ":tid", "in": "path", "required": true }, @@ -241,7 +280,7 @@ { "type": "string", "description": "Task ID to remove users from", - "name": "tid", + "name": ":tid", "in": "path", "required": true }, diff --git a/backend/docs/swagger.yaml b/backend/docs/swagger.yaml index 212af03..5b3ec14 100644 --- a/backend/docs/swagger.yaml +++ b/backend/docs/swagger.yaml @@ -120,6 +120,32 @@ paths: summary: Upload a file tags: - file + /labels/delete/{:gid}/{:lname}: + delete: + description: delete a label + parameters: + - description: Group to delete label from + in: path + name: :gid + required: true + type: string + - description: Name of label to delete + in: path + name: :lname + required: true + type: string + responses: + "200": + description: OK + schema: + $ref: '#/definitions/models.Label' + "400": + description: Bad Request + schema: + type: string + summary: Delete A Label + tags: + - labels /labels/new: post: description: create a new label for a group @@ -161,7 +187,7 @@ paths: parameters: - description: Task ID to assign users to in: path - name: tid + name: :tid required: true type: string - description: Users to assign to task and assignee @@ -190,7 +216,7 @@ paths: parameters: - description: Task ID to remove users from in: path - name: tid + name: :tid required: true type: string - description: Users to remove from task diff --git a/backend/schema/labels/label_test.go b/backend/schema/labels/label_test.go index 556dbc8..f125314 100644 --- a/backend/schema/labels/label_test.go +++ b/backend/schema/labels/label_test.go @@ -39,7 +39,7 @@ func TestLabelGroup(t *testing.T) { t.Run("TestCreateNewLabel", func(t *testing.T) { postRequest := LabelCreation{ - GroupID: 1, + GroupID: 3, LabelName: "Laundry", LabelColor: "Orange", } @@ -65,7 +65,7 @@ func TestLabelGroup(t *testing.T) { } expectedResponse := models.Label{ - GroupID: 1, + GroupID: 3, LabelName: "Laundry", LabelColor: "Orange", } @@ -74,4 +74,14 @@ func TestLabelGroup(t *testing.T) { t.Error("Result was not correct") } }) + + t.Run("TestDeleteLabel", func(t *testing.T) { + w := httptest.NewRecorder() + req, _ := http.NewRequest("DELETE", "/labels/delete/2/Appointment", nil) + router.ServeHTTP(w, req) + + if http.StatusOK != w.Code { + t.Error("Failed to delete label.") + } + }) } diff --git a/backend/schema/labels/routes.go b/backend/schema/labels/routes.go index 791feb2..06827b5 100644 --- a/backend/schema/labels/routes.go +++ b/backend/schema/labels/routes.go @@ -16,6 +16,7 @@ func LabelGroup(v1 *gin.RouterGroup, c *PgModel) *gin.RouterGroup { labels := v1.Group("labels") { labels.POST("/new", c.CreateNewLabel) + labels.DELETE("/delete/:gid/:lname", c.DeleteLabel) } return labels @@ -54,3 +55,28 @@ func (pg *PgModel) CreateNewLabel(c *gin.Context) { c.JSON(http.StatusOK, label) } + +// DeleteLabel godoc +// +// @summary Delete A Label +// @description delete a label +// @tags labels +// +// @param :gid path string true "Group to delete label from" +// @param :lname path string true "Name of label to delete" +// +// @success 200 {object} models.Label +// @failure 400 {object} string +// @router /labels/delete/{:gid}/{:lname} [DELETE] +func (pg *PgModel) DeleteLabel(c *gin.Context) { + group_id := c.Param("gid") + label_name := c.Param("lname") + + err := DeleteLabelFromDB(pg.Conn, group_id, label_name) + if err != nil { + c.JSON(http.StatusBadRequest, err.Error()) + return + } + + c.JSON(http.StatusOK, nil) +} diff --git a/backend/schema/labels/transactions.go b/backend/schema/labels/transactions.go index e82edef..66616c0 100644 --- a/backend/schema/labels/transactions.go +++ b/backend/schema/labels/transactions.go @@ -2,6 +2,7 @@ package labels import ( "carewallet/models" + "strconv" "github.com/jackc/pgx" ) @@ -14,6 +15,7 @@ func CreateNewLabelInDB(pool *pgx.Conn, requestBody LabelCreation) (models.Label _, err := pool.Exec("INSERT INTO label (group_id, label_name, label_color) VALUES ($1, $2, $3)", groupID, labelName, labelColor) if err != nil { + print(err.Error()) return models.Label{}, err } @@ -24,3 +26,17 @@ func CreateNewLabelInDB(pool *pgx.Conn, requestBody LabelCreation) (models.Label } return label, nil } + +func DeleteLabelFromDB(pool *pgx.Conn, groupID string, labelName string) error { + groupIDInt, err := strconv.Atoi(groupID) + if err != nil { + return err + } + + _, err = pool.Exec("DELETE FROM label WHERE group_id = $1 AND label_name = $2", groupIDInt, labelName) + if err != nil { + return err + } + + return nil +} diff --git a/backend/schema/tasks/routes.go b/backend/schema/tasks/routes.go index 2ccef46..658ca7e 100644 --- a/backend/schema/tasks/routes.go +++ b/backend/schema/tasks/routes.go @@ -76,11 +76,11 @@ type Assignment struct { // @description assign users to task // @tags tasks // -// @param tid path string true "Task ID to assign users to" -// @param _ body Assignment true "Users to assign to task and assignee" +// @param :tid path string true "Task ID to assign users to" +// @param _ body Assignment true "Users to assign to task and assignee" // -// @success 200 {array} models.TaskUser -// @failure 400 {object} string +// @success 200 {array} models.TaskUser +// @failure 400 {object} string // @router /tasks/{tid}/assign [post] func (pg *PgModel) AssignUsersToTask(c *gin.Context) { var requestBody Assignment @@ -110,11 +110,11 @@ type Removal struct { // @description remove users from task // @tags tasks // -// @param tid path string true "Task ID to remove users from" -// @param _ body Removal true "Users to remove from task" +// @param :tid path string true "Task ID to remove users from" +// @param _ body Removal true "Users to remove from task" // -// @success 200 {array} models.TaskUser -// @failure 400 {object} string +// @success 200 {array} models.TaskUser +// @failure 400 {object} string // @router /tasks/{tid}/remove [delete] func (pg *PgModel) RemoveUsersFromTask(c *gin.Context) { var requestBody Removal