Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feature/addtitletotaskmodel' int…
Browse files Browse the repository at this point in the history
…o feature/single-task-display-screen
  • Loading branch information
narayansharma-21 committed Mar 18, 2024
2 parents 0039498 + 17bc80a commit 7cfd5f7
Show file tree
Hide file tree
Showing 21 changed files with 308 additions and 115 deletions.
11 changes: 6 additions & 5 deletions backend/db/migrations/3.task.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CREATE TYPE task_type AS ENUM ('med_mgmt', 'dr_appt', 'financial', 'other');

CREATE TABLE IF NOT EXISTS task (
task_id serial NOT NULL,
task_title varchar NOT NULL,
group_id integer NOT NULL,
created_by varchar NOT NULL,
created_date timestamp NOT NULL, -- add default val with current timestamp?
Expand Down Expand Up @@ -38,12 +39,12 @@ CREATE TABLE IF NOT EXISTS task_assignees (
FOREIGN KEY (assigned_by) REFERENCES users (user_id)
);

INSERT INTO task (group_id, created_by, created_date, start_date, end_date, notes, task_status, task_type)
INSERT INTO task (task_title, group_id, created_by, created_date, start_date, end_date, notes, task_status, task_type)
VALUES
(1, 'user2', '2024-02-03 10:45:00', '2024-02-05 10:00:00', '2024-02-05 11:00:00', 'Pick up medication from pharmacy', 'INCOMPLETE', 'med_mgmt'),
(2, 'user3', '2024-02-20 23:59:59', '2024-02-10 14:30:00', NULL, 'Schedule doctor appointment', 'INCOMPLETE', 'other'),
(3, 'user4', '2020-02-05 11:00:00', NULL, '2024-02-20 23:59:59', 'Submit insurance claim', 'PARTIAL', 'financial'),
(4, 'user1', '2006-01-02 15:04:05', NULL, NULL, 'Refill water pitcher', 'COMPLETE', 'other')
('task 1', 1, 'user2', '2024-02-03 10:45:00', '2024-02-05 10:00:00', '2024-02-05 11:00:00', 'Pick up medication from pharmacy', 'INCOMPLETE', 'med_mgmt'),
('task 2', 2, 'user3', '2024-02-20 23:59:59', '2024-02-10 14:30:00', NULL, 'Schedule doctor appointment', 'INCOMPLETE', 'other'),
('task 3', 3, 'user4', '2020-02-05 11:00:00', NULL, '2024-02-20 23:59:59', 'Submit insurance claim', 'PARTIAL', 'financial'),
('task 4', 4, 'user1', '2006-01-02 15:04:05', NULL, NULL, 'Refill water pitcher', 'COMPLETE', 'other')
;

INSERT INTO task_assignees (task_id, user_id, assignment_status, assigned_by, assigned_date)
Expand Down
8 changes: 8 additions & 0 deletions backend/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,11 @@ const docTemplate = `{
"name": "taskStatus",
"in": "query"
},
{
"type": "string",
"name": "taskTitle",
"in": "query"
},
{
"type": "string",
"name": "taskType",
Expand Down Expand Up @@ -1187,6 +1192,9 @@ const docTemplate = `{
"task_status": {
"type": "string"
},
"task_title": {
"type": "string"
},
"task_type": {
"type": "string"
}
Expand Down
8 changes: 8 additions & 0 deletions backend/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,11 @@
"name": "taskStatus",
"in": "query"
},
{
"type": "string",
"name": "taskTitle",
"in": "query"
},
{
"type": "string",
"name": "taskType",
Expand Down Expand Up @@ -1180,6 +1185,9 @@
"task_status": {
"type": "string"
},
"task_title": {
"type": "string"
},
"task_type": {
"type": "string"
}
Expand Down
5 changes: 5 additions & 0 deletions backend/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ definitions:
type: string
task_status:
type: string
task_title:
type: string
task_type:
type: string
type: object
Expand Down Expand Up @@ -766,6 +768,9 @@ paths:
- in: query
name: taskStatus
type: string
- in: query
name: taskTitle
type: string
- in: query
name: taskType
type: string
Expand Down
17 changes: 10 additions & 7 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"carewallet/schema/tasks"
"carewallet/schema/user"
"fmt"
"log"
"os"

"github.com/gin-gonic/gin"
Expand All @@ -39,7 +40,14 @@ func main() {

defer conn.Close()

r := gin.Default()
// prepare gin
// uncomment below mode if want to get back to release debug mode
//gin.SetMode(gin.ReleaseMode)

// gin with default setup
r := gin.New()
r.Use(gin.Logger())
r.Use(gin.Recovery())

v1 := r.Group("/")
{
Expand Down Expand Up @@ -67,10 +75,5 @@ func main() {
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
}

err = r.Run(":8080")

if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
log.Fatalf("%v", r.Run(":8080"))
}
1 change: 1 addition & 0 deletions backend/models/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

type Task struct {
TaskID int `json:"task_id"`
TaskTitle string `json:"task_title"`
GroupID int `json:"group_id"`
CreatedBy string `json:"created_by"` // User ID
CreatedDate time.Time `json:"created_date"`
Expand Down
2 changes: 2 additions & 0 deletions backend/schema/tasks/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (pg *PgModel) GetTaskByID(c *gin.Context) {

type TaskQuery struct {
TaskID string `form:"taskID"`
TaskTitle string `form:"taskTitle"`
GroupID string `form:"groupID"`
CreatedBy string `form:"createdBy"`
TaskStatus string `form:"taskStatus"`
Expand All @@ -87,6 +88,7 @@ func (pg *PgModel) GetFilteredTasks(c *gin.Context) {
var filterQuery TaskQuery
if err := c.ShouldBindQuery(&filterQuery); err != nil {
c.JSON(http.StatusBadRequest, err.Error())
fmt.Println("error binding to query: ", err)
return
}
tasks, err := GetTasksByQueryFromDB(pg.Conn, filterQuery)
Expand Down
89 changes: 62 additions & 27 deletions backend/schema/tasks/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestTaskGroup(t *testing.T) {

t.Run("TestGetFilteredTasks", func(t *testing.T) {
getRequest := TaskQuery{
TaskTitle: "",
GroupID: "",
CreatedBy: "",
TaskStatus: "",
Expand All @@ -64,37 +65,57 @@ func TestTaskGroup(t *testing.T) {

if http.StatusOK != w.Code {
t.Error("Failed to retrieve tasks by filter query.")
return
}

var responseTasks []models.Task
err = json.Unmarshal(w.Body.Bytes(), &responseTasks)

if err != nil {
t.Error("Failed to unmarshal json")
return
}
start_date_1 := time.Date(2024, 2, 10, 14, 30, 0, 0, time.UTC)
note := "Schedule doctor appointment"
note2 := "Refill water pitcher"
expectedTasks := []models.Task{
{
TaskID: 2,
GroupID: 2,
CreatedBy: "user3",
CreatedDate: time.Date(2024, 2, 20, 23, 59, 59, 0, time.UTC),
StartDate: &start_date_1,
TaskStatus: "INCOMPLETE",
TaskType: "other",
TaskID: 2,
TaskTitle: "task 2",
GroupID: 2,
CreatedBy: "user3",
CreatedDate: time.Date(2024, 2, 20, 23, 59, 59, 0, time.UTC),
StartDate: &start_date_1,
EndDate: nil,
Notes: &note,
Repeating: false,
RepeatingInterval: nil,
RepeatingEndDate: nil,
TaskStatus: "INCOMPLETE",
TaskType: "other",
TaskInfo: nil,
},
{
TaskID: 4,
GroupID: 4,
CreatedBy: "user1",
CreatedDate: time.Date(2006, 1, 2, 15, 4, 5, 0, time.UTC),
TaskStatus: "COMPLETE",
TaskType: "other",
TaskID: 4,
TaskTitle: "task 4",
GroupID: 4,
CreatedBy: "user1",
CreatedDate: time.Date(2006, 1, 2, 15, 4, 5, 0, time.UTC),
StartDate: nil,
EndDate: nil,
Notes: &note2,
Repeating: false,
RepeatingInterval: nil,
RepeatingEndDate: nil,
TaskStatus: "COMPLETE",
TaskType: "other",
TaskInfo: nil,
},
}

if !reflect.DeepEqual(expectedTasks, responseTasks) {
t.Error("Result was not correct")
return
}
})

Expand Down Expand Up @@ -192,13 +213,20 @@ func TestTaskGroup(t *testing.T) {
note := "Refill water pitcher"
expectedTasks := []models.Task{
{
TaskID: 4,
GroupID: 4,
CreatedBy: "user1",
CreatedDate: time.Date(2006, 1, 2, 15, 4, 5, 0, time.UTC),
Notes: &note,
TaskStatus: "COMPLETE",
TaskType: "other",
TaskID: 4,
TaskTitle: "task 4",
GroupID: 4,
CreatedBy: "user1",
CreatedDate: time.Date(2006, 1, 2, 15, 4, 5, 0, time.UTC),
StartDate: nil,
EndDate: nil,
Notes: &note,
Repeating: false,
RepeatingInterval: nil,
RepeatingEndDate: nil,
TaskStatus: "COMPLETE",
TaskType: "other",
TaskInfo: nil,
},
}

Expand Down Expand Up @@ -226,13 +254,20 @@ func TestTaskGroup(t *testing.T) {
note := "Refill water pitcher"
expectedTasks := []models.Task{
{
TaskID: 4,
GroupID: 4,
CreatedBy: "user1",
CreatedDate: time.Date(2006, 1, 2, 15, 4, 5, 0, time.UTC),
Notes: &note,
TaskStatus: "COMPLETE",
TaskType: "other",
TaskID: 4,
TaskTitle: "task 4",
GroupID: 4,
CreatedBy: "user1",
CreatedDate: time.Date(2006, 1, 2, 15, 4, 5, 0, time.UTC),
StartDate: nil,
EndDate: nil,
Notes: &note,
Repeating: false,
RepeatingInterval: nil,
RepeatingEndDate: nil,
TaskStatus: "COMPLETE",
TaskType: "other",
TaskInfo: nil,
},
}

Expand Down
31 changes: 10 additions & 21 deletions backend/schema/tasks/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import (
func GetTasksByQueryFromDB(pool *pgx.Conn, filterQuery TaskQuery) ([]models.Task, error) {
query_fields := []string{
filterQuery.TaskID,
filterQuery.TaskTitle,
filterQuery.GroupID,
filterQuery.CreatedBy,
filterQuery.TaskStatus,
filterQuery.TaskType,
filterQuery.StartDate,
filterQuery.EndDate}

field_names := []string{"task_id =", "group_id =", "created_by =", "task_status =", "task_type =", "start_date >=", "end_date <="}
field_names := []string{"task_id =", "task_title =", "group_id =", "created_by =", "task_status =", "task_type =", "start_date >=", "end_date <="}
var query string
var args []interface{}

Expand All @@ -34,7 +35,7 @@ func GetTasksByQueryFromDB(pool *pgx.Conn, filterQuery TaskQuery) ([]models.Task
}
}

rows, err := pool.Query("SELECT task_id, group_id, created_by, created_date, start_date, end_date, task_status, task_type FROM task WHERE "+query, args...)
rows, err := pool.Query("SELECT * FROM task WHERE "+query, args...)

if err != nil {
print(err, "error selecting tasks by query")
Expand All @@ -47,10 +48,10 @@ func GetTasksByQueryFromDB(pool *pgx.Conn, filterQuery TaskQuery) ([]models.Task

for rows.Next() {
task := models.Task{}
err := rows.Scan(&task.TaskID, &task.GroupID, &task.CreatedBy, &task.CreatedDate, &task.StartDate, &task.EndDate, &task.TaskStatus, &task.TaskType)
err := rows.Scan(&task.TaskID, &task.TaskTitle, &task.GroupID, &task.CreatedBy, &task.CreatedDate, &task.StartDate, &task.EndDate, &task.Notes, &task.Repeating, &task.RepeatingInterval, &task.RepeatingEndDate, &task.TaskStatus, &task.TaskType, &task.TaskInfo)

if err != nil {
print(err, "error scanning tasks by query")
print(err.Error(), "error scanning tasks by query")
return nil, err
}

Expand Down Expand Up @@ -143,7 +144,7 @@ func GetTasksByAssignedFromDB(pool *pgx.Conn, userIDs []string) ([]models.Task,
// Get all tasks by task ID
var task models.Task
for _, task_id := range task_ids {
err := pool.QueryRow("SELECT * FROM task WHERE task_id = $1;", task_id).Scan(&task.TaskID, &task.GroupID, &task.CreatedBy, &task.CreatedDate, &task.StartDate, &task.EndDate, &task.Notes, &task.Repeating, &task.RepeatingInterval, &task.RepeatingEndDate, &task.TaskStatus, &task.TaskType, &task.TaskInfo)
err := pool.QueryRow("SELECT * FROM task WHERE task_id = $1;", task_id).Scan(&task.TaskID, &task.TaskTitle, &task.GroupID, &task.CreatedBy, &task.CreatedDate, &task.StartDate, &task.EndDate, &task.Notes, &task.Repeating, &task.RepeatingInterval, &task.RepeatingEndDate, &task.TaskStatus, &task.TaskType, &task.TaskInfo)
if err != nil {
print(err, "error querying task by ID")
return nil, err
Expand All @@ -158,7 +159,7 @@ func GetTasksByAssignedFromDB(pool *pgx.Conn, userIDs []string) ([]models.Task,
// CreateTaskInDB creates a new task in the database and returns its ID
func CreateTaskInDB(pool *pgx.Conn, newTask models.Task) (int, error) {
query := `
INSERT INTO task (group_id, created_by, created_date, start_date, end_date, notes, repeating, repeating_interval, repeating_end_date, task_status, task_type, task_info) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) RETURNING task_id`
INSERT INTO task (group_id, created_by, created_date, start_date, end_date, notes, repeating, repeating_interval, repeating_end_date, task_status, task_type, task_info, task_title) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) RETURNING task_id`

var newTaskID int
err := pool.QueryRow(
Expand All @@ -175,6 +176,7 @@ func CreateTaskInDB(pool *pgx.Conn, newTask models.Task) (int, error) {
newTask.TaskStatus,
newTask.TaskType,
newTask.TaskInfo,
newTask.TaskTitle,
).Scan(&newTaskID)

return newTaskID, err
Expand All @@ -200,24 +202,11 @@ func UpdateTaskInfoInDB(pool *pgx.Conn, taskID int, taskInfo json.RawMessage) er

// GetTaskByID fetches a task from the database by its ID
func GetTaskByID(pool *pgx.Conn, taskID int) (models.Task, error) {
query := `
SELECT task_id, group_id, created_by, created_date, start_date, end_date, notes, repeating, repeating_interval, repeating_end_date, task_status, task_type, task_info FROM task WHERE task_id = $1`
query := `SELECT * FROM task WHERE task_id = $1`

var task models.Task
err := pool.QueryRow(query, taskID).Scan(
&task.TaskID,
&task.GroupID,
&task.CreatedBy,
&task.CreatedDate,
&task.StartDate,
&task.EndDate,
&task.Notes,
&task.Repeating,
&task.RepeatingInterval,
&task.RepeatingEndDate,
&task.TaskStatus,
&task.TaskType,
&task.TaskInfo,
&task.TaskID, &task.TaskTitle, &task.GroupID, &task.CreatedBy, &task.CreatedDate, &task.StartDate, &task.EndDate, &task.Notes, &task.Repeating, &task.RepeatingInterval, &task.RepeatingEndDate, &task.TaskStatus, &task.TaskType, &task.TaskInfo,
)
return task, err
}
Expand Down
Loading

0 comments on commit 7cfd5f7

Please sign in to comment.