Skip to content

Commit

Permalink
feat: new route backend
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviaseds committed Feb 6, 2024
1 parent 5009975 commit c2a8fc4
Show file tree
Hide file tree
Showing 8 changed files with 258 additions and 61 deletions.
2 changes: 1 addition & 1 deletion backend/db/migrations/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ CREATE TABLE IF NOT EXISTS task (
start_date timestamp,
end_date timestamp,
notes varchar,
repeating BOOLEAN,
repeating BOOLEAN DEFAULT FALSE,
repeating_interval varchar,
repeating_end_date timestamp,
task_status task_status NOT NULL,
Expand Down
39 changes: 38 additions & 1 deletion backend/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,43 @@ const docTemplate = `{
}
}
},
"/tasks/assigned": {
"get": {
"description": "get tasks assigned to given users",
"tags": [
"tasks"
],
"summary": "Get Tasks Assigned To Given Users",
"parameters": [
{
"type": "array",
"items": {
"type": "string"
},
"collectionFormat": "csv",
"name": "userIDs",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/models.Task"
}
}
},
"400": {
"description": "Bad Request",
"schema": {
"type": "string"
}
}
}
}
},
"/tasks/filtered": {
"get": {
"description": "get filtered tasks",
Expand Down Expand Up @@ -122,7 +159,7 @@ const docTemplate = `{
}
}
},
"/tasks/{tid}/assignees": {
"/tasks/{tid}/assign": {
"post": {
"description": "assign users to task",
"tags": [
Expand Down
39 changes: 38 additions & 1 deletion backend/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,43 @@
}
}
},
"/tasks/assigned": {
"get": {
"description": "get tasks assigned to given users",
"tags": [
"tasks"
],
"summary": "Get Tasks Assigned To Given Users",
"parameters": [
{
"type": "array",
"items": {
"type": "string"
},
"collectionFormat": "csv",
"name": "userIDs",
"in": "query"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/models.Task"
}
}
},
"400": {
"description": "Bad Request",
"schema": {
"type": "string"
}
}
}
}
},
"/tasks/filtered": {
"get": {
"description": "get filtered tasks",
Expand Down Expand Up @@ -115,7 +152,7 @@
}
}
},
"/tasks/{tid}/assignees": {
"/tasks/{tid}/assign": {
"post": {
"description": "assign users to task",
"tags": [
Expand Down
26 changes: 25 additions & 1 deletion backend/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ paths:
summary: Get All Meds
tags:
- medications
/tasks/{tid}/assignees:
/tasks/{tid}/assign:
post:
description: assign users to task
parameters:
Expand Down Expand Up @@ -173,6 +173,30 @@ paths:
summary: Remove Users From Task
tags:
- tasks
/tasks/assigned:
get:
description: get tasks assigned to given users
parameters:
- collectionFormat: csv
in: query
items:
type: string
name: userIDs
type: array
responses:
"200":
description: OK
schema:
items:
$ref: '#/definitions/models.Task'
type: array
"400":
description: Bad Request
schema:
type: string
summary: Get Tasks Assigned To Given Users
tags:
- tasks
/tasks/filtered:
get:
description: get filtered tasks
Expand Down
2 changes: 2 additions & 0 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
_ "carewallet/docs"
"carewallet/schema/files"
"carewallet/schema/medication"
"carewallet/schema/tasks"
"fmt"
"os"

Expand Down Expand Up @@ -39,6 +40,7 @@ func main() {
{
medication.GetMedicationGroup(v1, &medication.PgModel{Conn: conn})
files.GetFileGroup(v1, &files.PgModel{Conn: conn})
tasks.TaskGroup(v1, &tasks.PgModel{Conn: conn})
}

if enviroment == configuration.EnvironmentLocal {
Expand Down
50 changes: 43 additions & 7 deletions backend/schema/tasks/routes.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package tasks

import (
"fmt"
"net/http"
"strings"

"github.com/gin-gonic/gin"
"github.com/jackc/pgx"
Expand All @@ -18,6 +20,7 @@ func TaskGroup(v1 *gin.RouterGroup, c *PgModel) *gin.RouterGroup {
tasks.GET("/filtered", c.GetFilteredTasks)
tasks.POST("/:tid/assign", c.AssignUsersToTask)
tasks.DELETE("/:tid/remove", c.RemoveUsersFromTask)
tasks.GET("/assigned", c.GetTasksByAssignedUsers)
}

return tasks
Expand Down Expand Up @@ -45,12 +48,12 @@ type TaskQuery struct {
// @router /tasks/filtered [get]
func (pg *PgModel) GetFilteredTasks(c *gin.Context) {
filterQuery := TaskQuery{
GroupID: c.Query("GroupID"),
CreatedBy: c.Query("CreatedBy"),
TaskStatus: c.Query("TaskStatus"),
TaskType: c.Query("TaskType"),
StartDate: c.Query("StartDate"),
EndDate: c.Query("EndDate"),
GroupID: c.Query("groupID"),
CreatedBy: c.Query("createdBy"),
TaskStatus: c.Query("taskStatus"),
TaskType: c.Query("taskType"),
StartDate: c.Query("startDate"),
EndDate: c.Query("endDate"),
}

tasks, err := GetTasksByQueryFromDB(pg.Conn, filterQuery)
Expand Down Expand Up @@ -79,11 +82,12 @@ type Assignment struct {
//
// @success 200 {array} models.TaskUser
// @failure 400 {object} string
// @router /tasks/{tid}/assignees [post]
// @router /tasks/{tid}/assign [post]
func (pg *PgModel) AssignUsersToTask(c *gin.Context) {
var requestBody Assignment

if err := c.BindJSON(&requestBody); err != nil {
print(err.Error())
c.JSON(http.StatusBadRequest, err.Error())
return
}
Expand Down Expand Up @@ -131,3 +135,35 @@ func (pg *PgModel) RemoveUsersFromTask(c *gin.Context) {

c.JSON(http.StatusOK, removedUsers)
}

type AssignedQuery struct {
UserIDs []string `query:"userIDs"`
}

// GetTasksByAssignedUsers godoc
//
// @summary Get Tasks Assigned To Given Users
// @description get tasks assigned to given users
// @tags tasks
//
// @param _ query AssignedQuery true "Users to return tasks for"
//
// @success 200 {array} models.Task
// @failure 400 {object} string
// @router /tasks/assigned [get]
func (pg *PgModel) GetTasksByAssignedUsers(c *gin.Context) {
userIDs := c.Query("userIDs")
assignedQuery := AssignedQuery{
UserIDs: strings.Split(userIDs, ","),
}
fmt.Println(assignedQuery.UserIDs)

tasks, err := GetTasksByAssignedFromDB(pg.Conn, assignedQuery.UserIDs)

if err != nil {
c.JSON(http.StatusBadRequest, err.Error())
return
}

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

0 comments on commit c2a8fc4

Please sign in to comment.