From 72e17fac10d83c9fe8dcf42e3f16a4f02dd566b8 Mon Sep 17 00:00:00 2001 From: patela22 <39590072+patela22@users.noreply.github.com> Date: Thu, 14 Mar 2024 15:58:49 -0400 Subject: [PATCH] feat(quicktask): quicktask and backend routes updated and working --- backend/db/migrations/3.task.sql | 14 ++++-- backend/docs/docs.go | 11 +++++ backend/docs/swagger.json | 11 +++++ backend/docs/swagger.yaml | 7 +++ backend/models/task.go | 1 + backend/schema/tasks/routes.go | 2 + backend/schema/tasks/task_test.go | 71 +++++++++++++++++++--------- backend/schema/tasks/transactions.go | 17 ++++--- client/components/QuickTaskCard.tsx | 4 +- client/screens/QuickTasks.tsx | 36 +++++++++----- client/services/task.ts | 3 +- client/types/task.ts | 3 +- 12 files changed, 129 insertions(+), 51 deletions(-) diff --git a/backend/db/migrations/3.task.sql b/backend/db/migrations/3.task.sql index 7da671b..e51152b 100644 --- a/backend/db/migrations/3.task.sql +++ b/backend/db/migrations/3.task.sql @@ -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, @@ -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) diff --git a/backend/docs/docs.go b/backend/docs/docs.go index 751b7a3..e3d2b28 100644 --- a/backend/docs/docs.go +++ b/backend/docs/docs.go @@ -520,6 +520,11 @@ const docTemplate = `{ "name": "groupID", "in": "query" }, + { + "type": "string", + "name": "quickTask", + "in": "query" + }, { "type": "string", "name": "startDate", @@ -1166,6 +1171,9 @@ const docTemplate = `{ "notes": { "type": "string" }, + "quick_task": { + "type": "boolean" + }, "repeating": { "type": "boolean" }, @@ -1304,6 +1312,9 @@ const docTemplate = `{ "notes": { "type": "string" }, + "quick_task": { + "type": "boolean" + }, "repeating": { "type": "boolean" }, diff --git a/backend/docs/swagger.json b/backend/docs/swagger.json index 1336662..9279d36 100644 --- a/backend/docs/swagger.json +++ b/backend/docs/swagger.json @@ -513,6 +513,11 @@ "name": "groupID", "in": "query" }, + { + "type": "string", + "name": "quickTask", + "in": "query" + }, { "type": "string", "name": "startDate", @@ -1159,6 +1164,9 @@ "notes": { "type": "string" }, + "quick_task": { + "type": "boolean" + }, "repeating": { "type": "boolean" }, @@ -1297,6 +1305,9 @@ "notes": { "type": "string" }, + "quick_task": { + "type": "boolean" + }, "repeating": { "type": "boolean" }, diff --git a/backend/docs/swagger.yaml b/backend/docs/swagger.yaml index 91b65c9..e348164 100644 --- a/backend/docs/swagger.yaml +++ b/backend/docs/swagger.yaml @@ -88,6 +88,8 @@ definitions: type: integer notes: type: string + quick_task: + type: boolean repeating: type: boolean repeating_end_date: @@ -178,6 +180,8 @@ definitions: type: integer notes: type: string + quick_task: + type: boolean repeating: type: boolean repeating_end_date: @@ -757,6 +761,9 @@ paths: - in: query name: groupID type: string + - in: query + name: quickTask + type: string - in: query name: startDate type: string diff --git a/backend/models/task.go b/backend/models/task.go index 4f700c2..b89f4c7 100644 --- a/backend/models/task.go +++ b/backend/models/task.go @@ -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"` diff --git a/backend/schema/tasks/routes.go b/backend/schema/tasks/routes.go index 9452a46..9ed97ee 100644 --- a/backend/schema/tasks/routes.go +++ b/backend/schema/tasks/routes.go @@ -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 @@ -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"` diff --git a/backend/schema/tasks/task_test.go b/backend/schema/tasks/task_test.go index 12847d8..3f883de 100644 --- a/backend/schema/tasks/task_test.go +++ b/backend/schema/tasks/task_test.go @@ -48,6 +48,7 @@ func TestTaskGroup(t *testing.T) { TaskType: "other", StartDate: "", EndDate: "", + QuickTask: "", } w := httptest.NewRecorder() @@ -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) @@ -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: ¬es_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: ¬es_2, + Repeating: false, + RepeatingInterval: nil, + RepeatingEndDate: nil, + TaskStatus: "COMPLETE", + TaskType: "other", + TaskInfo: nil, }, } @@ -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: ¬e, - 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: ¬e, + Repeating: false, + RepeatingInterval: nil, + RepeatingEndDate: nil, + TaskStatus: "COMPLETE", + TaskType: "other", + TaskInfo: nil, }, } @@ -257,10 +284,10 @@ func TestTaskGroup(t *testing.T) { TaskID: 1, GroupID: 1, CreatedBy: "user1", - CreatedDate: time.Now().UTC(), StartDate: &startDate, EndDate: &endDate, Notes: ¬es, + QuickTask: false, Repeating: repeating, RepeatingInterval: &repeatingInterval, RepeatingEndDate: &repeatingEndDate, diff --git a/backend/schema/tasks/transactions.go b/backend/schema/tasks/transactions.go index 31895b5..459a109 100644 --- a/backend/schema/tasks/transactions.go +++ b/backend/schema/tasks/transactions.go @@ -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{} @@ -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") @@ -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") @@ -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 @@ -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( @@ -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, @@ -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( @@ -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, diff --git a/client/components/QuickTaskCard.tsx b/client/components/QuickTaskCard.tsx index d8907a0..4c5ed46 100644 --- a/client/components/QuickTaskCard.tsx +++ b/client/components/QuickTaskCard.tsx @@ -5,8 +5,8 @@ export const QuickTaskCard = ({ name, label }: { - name: String; - label: String; + name: string; + label: string; }): JSX.Element => { return ( diff --git a/client/screens/QuickTasks.tsx b/client/screens/QuickTasks.tsx index d49a563..b5eadf7 100644 --- a/client/screens/QuickTasks.tsx +++ b/client/screens/QuickTasks.tsx @@ -7,24 +7,29 @@ import { GestureHandlerRootView } from 'react-native-gesture-handler'; import { Button } from 'react-native-paper'; import { QuickTaskCard } from '../components/QuickTaskCard'; - -// import { fetchTasks } from '../services/taskService'; +import { useCareWalletContext } from '../contexts/CareWalletContext'; +import { useFilteredTasks } from '../services/task'; export default function QuickTasks() { - const tasks = [ - { id: '1', name: 'Take out the trash', label: 'Home' }, - { id: '2', name: 'Do the laundry', label: 'Laundry' }, - { id: '3', name: 'Wash the dishes', label: 'Kitchen' } - ]; + // const tasksEx = [ + // { task_id: 1, notes: 'Take out the trash', task_type: 'Home' }, + // { task_id: 2, notes: 'Do the laundry', task_type: 'Laundry' }, + // { task_id: 3, notes: 'Wash the dishes', task_type: 'Kitchen' } + // ]; - // if (isLoading) { - // return Loading...; - // } + const { user: signedInUser, group } = useCareWalletContext(); + const { tasks, tasksIsLoading } = useFilteredTasks({ + groupID: group.groupID.toString(), + quickTask: true + }); const snapPoints = useMemo(() => ['70%'], []); const bottomSheetRef = useRef(null); - const handleOpenPress = () => bottomSheetRef.current?.expand(); + const handleOpenPress = () => { + bottomSheetRef.current?.expand(); + console.log(tasks); + }; const handleClosePress = () => bottomSheetRef.current?.close(); const renderBackdrop = useCallback( @@ -38,11 +43,16 @@ export default function QuickTasks() { ), [] ); + + if (tasksIsLoading) { + return Loading...; + } return ( } - keyExtractor={(item) => item.id} + keyExtractor={(item) => item.task_id.toString()} renderItem={({ item }) => ( - + )} /> diff --git a/client/services/task.ts b/client/services/task.ts index ba2271c..1036fd3 100644 --- a/client/services/task.ts +++ b/client/services/task.ts @@ -13,12 +13,13 @@ type TaskQueryParams = { taskType?: string; startDate?: string; endDate?: string; + quickTask?: boolean; }; const getFilteredTasks = async ( queryParams: TaskQueryParams ): Promise => { - const { data } = await axios.get(`${api_url}/tasks/filtered?`, { + const { data } = await axios.get(`${api_url}/tasks/filtered`, { params: queryParams }); return data; diff --git a/client/types/task.ts b/client/types/task.ts index 901812b..3e3da09 100644 --- a/client/types/task.ts +++ b/client/types/task.ts @@ -5,10 +5,11 @@ export interface Task { created_date: string; start_date?: string | null; end_date?: string | null; - notes?: string | null; + notes: string; repeating: boolean; repeating_interval?: string | null; repeating_end_date?: string | null; + quick_task: boolean; task_status: string; task_type: string; task_info?: string | null;