summaryrefslogtreecommitdiff
path: root/grocy/chores.go
diff options
context:
space:
mode:
authorCara Salter <cara@devcara.com>2023-09-03 11:51:38 -0400
committerCara Salter <cara@devcara.com>2023-09-03 11:51:38 -0400
commit1a69cd2e8b919ab450b42802ae578c2d23948a07 (patch)
tree2e0e1bfaa96e80f0a671b80cb197ad81f953ece1 /grocy/chores.go
downloadgrocy-reminders-1a69cd2e8b919ab450b42802ae578c2d23948a07.tar.gz
grocy-reminders-1a69cd2e8b919ab450b42802ae578c2d23948a07.zip
Initial commit
Create API client for grocy
Diffstat (limited to 'grocy/chores.go')
-rw-r--r--grocy/chores.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/grocy/chores.go b/grocy/chores.go
new file mode 100644
index 0000000..3dcdf2e
--- /dev/null
+++ b/grocy/chores.go
@@ -0,0 +1,53 @@
+package grocy
+
+import (
+ "context"
+ "fmt"
+ "net/http"
+)
+
+type Chore struct {
+ ID int `json:"id"`
+ ChoreID int `json:"chore_id"`
+ ChoreName string `json:"chore_name"`
+ LastTrackedTime string `json:"last_tracked_time"`
+ NextEstimatedExecutionTime string `json:"next_estimated_execution_time"`
+ TrackDateOnly int `json:"track_date_only"`
+ NextExecutionAssignedToUserID int `json:"next_execution_assigned_to_user_id"`
+ IsRescheduled int `json:"is_rescheduled"`
+ IsReassigned int `json:"is_reassigned"`
+ NextExecutionAssignedUser User `json:"next_execution_assigned_user"`
+}
+
+type ChoreList []Chore
+
+func (c *Client) GetChores(ctx context.Context) (ChoreList, error) {
+ req, err := http.NewRequest("GET", fmt.Sprintf("%s/chores", c.BaseUrl), nil)
+
+ if err != nil {
+ return nil, err
+ }
+ req.WithContext(ctx)
+
+ var res ChoreList
+ if err := c.sendRequest(req, &res); err != nil {
+ return nil, err
+ }
+
+ return res, nil
+}
+
+func (c *Client) GetChore(ctx context.Context, choreId int) (Chore, error) {
+ req, err := http.NewRequest("GET", fmt.Sprintf("%s/chores/%d", c.BaseUrl, choreId), nil)
+
+ if err != nil {
+ return *new(Chore), err
+ }
+ req.WithContext(ctx)
+
+ var res Chore
+ if err := c.sendRequest(req, &res); err != nil {
+ return *new(Chore), err
+ }
+ return res, nil
+}