Skip to content

Commit

Permalink
Merge branch 'main' into feature/edit-task-screen
Browse files Browse the repository at this point in the history
  • Loading branch information
MattCMcCoy committed Apr 18, 2024
2 parents 603869a + 96d301a commit 3bdf086
Show file tree
Hide file tree
Showing 30 changed files with 1,120 additions and 199 deletions.
8 changes: 7 additions & 1 deletion backend/db/migrations/4.label.sql
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,11 @@ VALUES
(3, 3, 'Financial'),
(4, 4, 'Household'),
(6, 5, 'Financial'),
(7, 5, 'Appointments')
(7, 5, 'Appointments'),
(12, 4, 'Household'),
(13, 5, 'Financial'),
(14, 5, 'Appointments'),
(15, 4, 'Household'),
(16, 5, 'Financial'),
(17, 5, 'Appointments')
;
78 changes: 78 additions & 0 deletions backend/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,45 @@ const docTemplate = `{
}
}
},
"/tasks/labels/tasks": {
"get": {
"description": "gets the information about multiple labals given their task id",
"tags": [
"task labels"
],
"summary": "gets the information about multiple labels",
"parameters": [
{
"type": "array",
"items": {
"type": "string"
},
"collectionFormat": "csv",
"description": "Task IDs",
"name": "taskIDs",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/models.Task_Label"
}
}
},
"400": {
"description": "Bad Request",
"schema": {
"type": "string"
}
}
}
}
},
"/tasks/{tid}": {
"get": {
"description": "get a task given its id",
Expand Down Expand Up @@ -1125,6 +1164,45 @@ const docTemplate = `{
}
}
},
"/tasks/{tid}/status/{status}": {
"get": {
"description": "Get list of users assigned to a task by task ID",
"tags": [
"tasks"
],
"summary": "Get list of users assigned to a task",
"parameters": [
{
"type": "integer",
"description": "Task ID",
"name": "tid",
"in": "path",
"required": true
},
{
"type": "integer",
"description": "Task Status",
"name": "status",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"400": {
"description": "Bad Request",
"schema": {
"type": "string"
}
}
}
}
},
"/user": {
"get": {
"description": "gets the information about multiple users given their user id",
Expand Down
78 changes: 78 additions & 0 deletions backend/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,45 @@
}
}
},
"/tasks/labels/tasks": {
"get": {
"description": "gets the information about multiple labals given their task id",
"tags": [
"task labels"
],
"summary": "gets the information about multiple labels",
"parameters": [
{
"type": "array",
"items": {
"type": "string"
},
"collectionFormat": "csv",
"description": "Task IDs",
"name": "taskIDs",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/models.Task_Label"
}
}
},
"400": {
"description": "Bad Request",
"schema": {
"type": "string"
}
}
}
}
},
"/tasks/{tid}": {
"get": {
"description": "get a task given its id",
Expand Down Expand Up @@ -1118,6 +1157,45 @@
}
}
},
"/tasks/{tid}/status/{status}": {
"get": {
"description": "Get list of users assigned to a task by task ID",
"tags": [
"tasks"
],
"summary": "Get list of users assigned to a task",
"parameters": [
{
"type": "integer",
"description": "Task ID",
"name": "tid",
"in": "path",
"required": true
},
{
"type": "integer",
"description": "Task Status",
"name": "status",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"400": {
"description": "Bad Request",
"schema": {
"type": "string"
}
}
}
}
},
"/user": {
"get": {
"description": "gets the information about multiple users given their user id",
Expand Down
52 changes: 52 additions & 0 deletions backend/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,32 @@ paths:
summary: Remove Users From Task
tags:
- tasks
/tasks/{tid}/status/{status}:
get:
description: Get list of users assigned to a task by task ID
parameters:
- description: Task ID
in: path
name: tid
required: true
type: integer
- description: Task Status
in: path
name: status
required: true
type: integer
responses:
"200":
description: OK
schema:
type: string
"400":
description: Bad Request
schema:
type: string
summary: Get list of users assigned to a task
tags:
- tasks
/tasks/assigned:
get:
description: get tasks assigned to given users
Expand Down Expand Up @@ -961,6 +987,32 @@ paths:
summary: Get Filtered Tasks
tags:
- tasks
/tasks/labels/tasks:
get:
description: gets the information about multiple labals given their task id
parameters:
- collectionFormat: csv
description: Task IDs
in: query
items:
type: string
name: taskIDs
required: true
type: array
responses:
"200":
description: OK
schema:
items:
$ref: '#/definitions/models.Task_Label'
type: array
"400":
description: Bad Request
schema:
type: string
summary: gets the information about multiple labels
tags:
- task labels
/user:
get:
description: gets the information about multiple users given their user id
Expand Down
54 changes: 50 additions & 4 deletions backend/schema/task_labels/routes.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package task_labels

import (
"carewallet/models"
"net/http"
"strings"

"github.com/gin-gonic/gin"
"github.com/jackc/pgx/v5/pgxpool"
Expand All @@ -13,16 +15,60 @@ type PgModel struct {

func TaskGroup(v1 *gin.RouterGroup, c *PgModel) *gin.RouterGroup {

tasks := v1.Group(":tid/labels")
tasks := v1.Group("")
{
tasks.POST("", c.addLabelToTask)
tasks.DELETE("", c.removeLabelFromTask)
tasks.GET("", c.getLabelsByTask)
labelByTaskID := tasks.Group(":tid/labels")
{
labelByTaskID.POST("", c.addLabelToTask)
labelByTaskID.DELETE("", c.removeLabelFromTask)
labelByTaskID.GET("", c.getLabelsByTask)
}

labelByTaskIDs := tasks.Group("labels/tasks")
{
labelByTaskIDs.GET("", c.getLabelsByTasks)
}
}

return tasks
}

type LabelsQuery struct {
TaskIDs []string `form:"taskIDs"`
}

// getLabelsByTasks godoc
//
// @summary gets the information about multiple labels
// @description gets the information about multiple labals given their task id
// @tags task labels
//
// @param taskIDs query []string true "Task IDs"
//
// @success 200 {array} models.Task_Label
// @failure 400 {object} string
// @router /tasks/labels/tasks [GET]
func (pg *PgModel) getLabelsByTasks(c *gin.Context) {

taskIDs := c.Query("taskIDs")
taskQuery := LabelsQuery{
TaskIDs: strings.Split(taskIDs, ","),
}

var labels []models.Task_Label

for _, element := range taskQuery.TaskIDs {
label, err := getLabelsByTaskInDB(pg.Conn, element)
if err != nil {
c.JSON(http.StatusBadRequest, err.Error())
return
}
labels = append(labels, label...)
}

c.JSON(http.StatusOK, labels)
}

// GetLabelsByTask godoc
//
// @summary get a tasks labels
Expand Down
2 changes: 1 addition & 1 deletion backend/schema/task_labels/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func getLabelsByTaskInDB(conn *pgxpool.Pool, taskId string) ([]models.Task_Label

for rows.Next() {
task := models.Task_Label{}
err := rows.Scan(&task.GroupId, &task.TaskId, &task.LabelName)
err := rows.Scan(&task.TaskId, &task.GroupId, &task.LabelName)

if err != nil {
print(err, "error scanning tasks by query")
Expand Down
30 changes: 30 additions & 0 deletions backend/schema/tasks/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TaskGroup(v1 *gin.RouterGroup, c *PgModel) *gin.RouterGroup {
{
byId.GET("", c.getTaskByID)
byId.DELETE("", c.deleteTask)
byId.PUT("/status/:status", c.updateTaskStatus)
byId.PUT("", c.updateTaskInfo)
byId.GET("/assigned", c.getUsersAssignedToTask)
byId.POST("/assign", c.assignUsersToTask)
Expand Down Expand Up @@ -351,3 +352,32 @@ func (pg *PgModel) getUsersAssignedToTask(c *gin.Context) {

c.JSON(http.StatusOK, userIDs)
}

// GetUsersAssignedToTask godoc
//
// @summary Get list of users assigned to a task
// @description Get list of users assigned to a task by task ID
// @tags tasks
// @param tid path int true "Task ID"
// @param status path int true "Task Status"
// @success 200 {object} string
// @failure 400 {object} string
// @router /tasks/{tid}/status/{status} [get]
func (pg *PgModel) updateTaskStatus(c *gin.Context) {
taskIDStr := c.Param("tid")
newStatus := c.Param("status")
fmt.Print(newStatus)
taskID, err := strconv.Atoi(taskIDStr)
if err != nil {
c.JSON(http.StatusBadRequest, err.Error())
return
}

err = updateTaskStatusInDB(pg.Conn, taskID, newStatus)
if err != nil {
c.JSON(http.StatusBadRequest, err.Error())
return
}

c.JSON(http.StatusOK, "")
}
Loading

0 comments on commit 3bdf086

Please sign in to comment.