Skip to content

Commit

Permalink
feat(quicktask): quicktask and backend routes updated and working
Browse files Browse the repository at this point in the history
  • Loading branch information
patela22 committed Mar 14, 2024
1 parent 23c2fee commit 72e17fa
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 51 deletions.
14 changes: 9 additions & 5 deletions backend/db/migrations/3.task.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ CREATE TABLE IF NOT EXISTS task (
created_date timestamp NOT NULL, -- add default val with current timestamp?
start_date timestamp,
end_date timestamp,
quick_task BOOLEAN DEFAULT FALSE,
notes varchar,
repeating BOOLEAN DEFAULT FALSE,
repeating_interval varchar,
Expand All @@ -38,12 +39,15 @@ 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 (group_id, created_by, created_date, start_date, end_date, notes, task_status, task_type, quick_task)
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')
(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', FALSE),
(2, 'user3', '2024-02-20 23:59:59', '2024-02-10 14:30:00', NULL, 'Schedule doctor appointment', 'INCOMPLETE', 'other', FALSE),
(3, 'user4', '2020-02-05 11:00:00', NULL, '2024-02-20 23:59:59', 'Submit insurance claim', 'PARTIAL', 'financial', FALSE),
(4, 'user1', '2006-01-02 15:04:05', NULL, NULL, 'Refill water pitcher', 'COMPLETE', 'other', TRUE),
(5, 'user1', '2024-02-05 11:00:00', '2024-02-05 11:00:00', '2024-02-05 11:00:00', 'Get medications', 'INCOMPLETE', 'dr_appt', TRUE),
(5, 'user2', '2024-02-05 11:00:00', '2024-02-05 11:00:00', '2024-02-05 11:00:00', 'File Papers', 'INCOMPLETE', 'med_mgmt', TRUE),
(5, 'user3', '2024-02-05 11:00:00', '2024-02-05 11:00:00', '2024-02-05 11:00:00', 'Send check to Drs', 'INCOMPLETE', 'financial', TRUE)
;

INSERT INTO task_assignees (task_id, user_id, assignment_status, assigned_by, assigned_date)
Expand Down
11 changes: 11 additions & 0 deletions backend/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,11 @@ const docTemplate = `{
"name": "groupID",
"in": "query"
},
{
"type": "string",
"name": "quickTask",
"in": "query"
},
{
"type": "string",
"name": "startDate",
Expand Down Expand Up @@ -1166,6 +1171,9 @@ const docTemplate = `{
"notes": {
"type": "string"
},
"quick_task": {
"type": "boolean"
},
"repeating": {
"type": "boolean"
},
Expand Down Expand Up @@ -1304,6 +1312,9 @@ const docTemplate = `{
"notes": {
"type": "string"
},
"quick_task": {
"type": "boolean"
},
"repeating": {
"type": "boolean"
},
Expand Down
11 changes: 11 additions & 0 deletions backend/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,11 @@
"name": "groupID",
"in": "query"
},
{
"type": "string",
"name": "quickTask",
"in": "query"
},
{
"type": "string",
"name": "startDate",
Expand Down Expand Up @@ -1159,6 +1164,9 @@
"notes": {
"type": "string"
},
"quick_task": {
"type": "boolean"
},
"repeating": {
"type": "boolean"
},
Expand Down Expand Up @@ -1297,6 +1305,9 @@
"notes": {
"type": "string"
},
"quick_task": {
"type": "boolean"
},
"repeating": {
"type": "boolean"
},
Expand Down
7 changes: 7 additions & 0 deletions backend/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ definitions:
type: integer
notes:
type: string
quick_task:
type: boolean
repeating:
type: boolean
repeating_end_date:
Expand Down Expand Up @@ -178,6 +180,8 @@ definitions:
type: integer
notes:
type: string
quick_task:
type: boolean
repeating:
type: boolean
repeating_end_date:
Expand Down Expand Up @@ -757,6 +761,9 @@ paths:
- in: query
name: groupID
type: string
- in: query
name: quickTask
type: string
- in: query
name: startDate
type: string
Expand Down
1 change: 1 addition & 0 deletions backend/models/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Task struct {
CreatedDate time.Time `json:"created_date"`
StartDate *time.Time `json:"start_date"`
EndDate *time.Time `json:"end_date"`
QuickTask bool `json:"quick_task"`
Notes *string `json:"notes"`
Repeating bool `json:"repeating"`
RepeatingInterval *string `json:"repeating_interval"`
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 @@ -70,6 +70,7 @@ type TaskQuery struct {
TaskType string `form:"taskType"`
StartDate string `form:"startDate"`
EndDate string `form:"endDate"`
QuickTask string `form:"quickTask"`
}

// GetFilteredTasks godoc
Expand Down Expand Up @@ -192,6 +193,7 @@ type TaskBody struct {
CreatedDate time.Time `json:"created_date"`
StartDate *time.Time `json:"start_date"`
EndDate *time.Time `json:"end_date"`
QuickTask bool `json:"quick_task"`
Notes *string `json:"notes"`
Repeating bool `json:"repeating"`
RepeatingInterval *string `json:"repeating_interval"`
Expand Down
71 changes: 49 additions & 22 deletions backend/schema/tasks/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func TestTaskGroup(t *testing.T) {
TaskType: "other",
StartDate: "",
EndDate: "",
QuickTask: "",
}

w := httptest.NewRecorder()
Expand All @@ -58,6 +59,7 @@ func TestTaskGroup(t *testing.T) {
query.Set("taskType", getRequest.TaskType)
query.Set("startDate", getRequest.StartDate)
query.Set("endDate", getRequest.EndDate)
query.Set("quickTask", getRequest.QuickTask)

req, _ := http.NewRequest("GET", "/tasks/filtered?"+query.Encode(), nil)
router.ServeHTTP(w, req)
Expand All @@ -73,23 +75,41 @@ func TestTaskGroup(t *testing.T) {
t.Error("Failed to unmarshal json")
}
start_date_1 := time.Date(2024, 2, 10, 14, 30, 0, 0, time.UTC)
expectedTasks := []models.Task{
notes_1 := "Schedule doctor appointment"
notes_2 := "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,
GroupID: 2,
CreatedBy: "user3",
CreatedDate: time.Date(2024, 2, 20, 23, 59, 59, 0, time.UTC),
StartDate: &start_date_1,
EndDate: nil,
QuickTask: false,
Notes: &notes_1,
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,
GroupID: 4,
CreatedBy: "user1",
CreatedDate: time.Date(2006, 1, 2, 15, 4, 5, 0, time.UTC),
StartDate: nil,
EndDate: nil,
QuickTask: true,
Notes: &notes_2,
Repeating: false,
RepeatingInterval: nil,
RepeatingEndDate: nil,
TaskStatus: "COMPLETE",
TaskType: "other",
TaskInfo: nil,
},
}

Expand Down Expand Up @@ -192,13 +212,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,
GroupID: 4,
CreatedBy: "user1",
CreatedDate: time.Date(2006, 1, 2, 15, 4, 5, 0, time.UTC),
StartDate: nil,
EndDate: nil,
QuickTask: true,
Notes: &note,
Repeating: false,
RepeatingInterval: nil,
RepeatingEndDate: nil,
TaskStatus: "COMPLETE",
TaskType: "other",
TaskInfo: nil,
},
}

Expand Down Expand Up @@ -257,10 +284,10 @@ func TestTaskGroup(t *testing.T) {
TaskID: 1,
GroupID: 1,
CreatedBy: "user1",
CreatedDate: time.Now().UTC(),
StartDate: &startDate,
EndDate: &endDate,
Notes: &notes,
QuickTask: false,
Repeating: repeating,
RepeatingInterval: &repeatingInterval,
RepeatingEndDate: &repeatingEndDate,
Expand Down
17 changes: 10 additions & 7 deletions backend/schema/tasks/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ func GetTasksByQueryFromDB(pool *pgx.Conn, filterQuery TaskQuery) ([]models.Task
filterQuery.TaskStatus,
filterQuery.TaskType,
filterQuery.StartDate,
filterQuery.EndDate}
filterQuery.EndDate,
filterQuery.QuickTask}

field_names := []string{"task_id =", "group_id =", "created_by =", "task_status =", "task_type =", "start_date >=", "end_date <="}
field_names := []string{"task_id =", "group_id =", "created_by =", "task_status =", "task_type =", "start_date >=", "end_date <=", "quick_task ="}
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 task_id, group_id, created_by, created_date, start_date, end_date, quick_task, notes, task_status, task_type, task_info FROM task WHERE "+query, args...)

if err != nil {
print(err, "error selecting tasks by query")
Expand All @@ -47,7 +48,7 @@ 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.GroupID, &task.CreatedBy, &task.CreatedDate, &task.StartDate, &task.EndDate, &task.QuickTask, &task.Notes, &task.TaskStatus, &task.TaskType, &task.TaskInfo)

if err != nil {
print(err, "error scanning tasks by query")
Expand Down Expand Up @@ -144,7 +145,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.GroupID, &task.CreatedBy, &task.CreatedDate, &task.StartDate, &task.EndDate, &task.QuickTask, &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 @@ -159,7 +160,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, quick_task, 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, $13) RETURNING task_id`

var newTaskID int
err := pool.QueryRow(
Expand All @@ -169,6 +170,7 @@ func CreateTaskInDB(pool *pgx.Conn, newTask models.Task) (int, error) {
time.Now(), // Assuming created_date should be the current timestamp
newTask.StartDate,
newTask.EndDate,
newTask.QuickTask,
newTask.Notes,
newTask.Repeating,
newTask.RepeatingInterval,
Expand Down Expand Up @@ -202,7 +204,7 @@ 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`
SELECT task_id, group_id, created_by, created_date, start_date, end_date, quick_task, notes, repeating, repeating_interval, repeating_end_date, task_status, task_type, task_info FROM task WHERE task_id = $1`

var task models.Task
err := pool.QueryRow(query, taskID).Scan(
Expand All @@ -212,6 +214,7 @@ func GetTaskByID(pool *pgx.Conn, taskID int) (models.Task, error) {
&task.CreatedDate,
&task.StartDate,
&task.EndDate,
&task.QuickTask,
&task.Notes,
&task.Repeating,
&task.RepeatingInterval,
Expand Down
4 changes: 2 additions & 2 deletions client/components/QuickTaskCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export const QuickTaskCard = ({
name,
label
}: {
name: String;
label: String;
name: string;
label: string;
}): JSX.Element => {
return (
<View className="border-black h-[82px] w-[346px] self-center overflow-hidden rounded-[20px] border border-solid">
Expand Down
Loading

0 comments on commit 72e17fa

Please sign in to comment.