Skip to content

Add write support for assignments (POST, PUT, DELETE)#26

Merged
joefitzgerald merged 2 commits into
joefitzgerald:mainfrom
Dylan-Bon:main
May 21, 2026
Merged

Add write support for assignments (POST, PUT, DELETE)#26
joefitzgerald merged 2 commits into
joefitzgerald:mainfrom
Dylan-Bon:main

Conversation

@Dylan-Bon
Copy link
Copy Markdown
Contributor

@Dylan-Bon Dylan-Bon commented Apr 29, 2026

Hi, I hope this is welcome.
I see that of the 3 Forecast API libraries mentioned here, none of them support mutations. I'd like to add support to create assignments as this as it would help my use case.

Summary

Adds write support for the assignments endpoint, enabling programmatic scheduling in Forecast.

Changes

assignment.go

  • CreateAssignment(assignment AssignmentRequest) (Assignment, error)
  • UpdateAssignment(assignment AssignmentRequest, assignmentID int) (Assignment, error)
  • DeleteAssignment(assignmentID int) error
  • AssignmentRequest — a new type used as the request payload for mutations. Kept separate from Assignment (the GET response type) to avoid a breaking change, and because the shapes differ — request payloads don't include server-assigned fields like id, updated_at, and updated_by_id. Nullable fields use pointer types to correctly represent JSON null.

api.go

  • mutate handles requests with a body (POST, PUT)
  • mutateNoBody handles requests without a body (DELETE)
  • Extracted initClient() to remove duplicated HTTP client initialisation across get and the new mutation functions

Test Results

Suite: forecast
Total: 37 | Focused: 0 | Pending: 0
.....................................
Passed: 37 | Failed: 0 | Skipped: 0

PASS
ok github.com/joefitzgerald/forecast 0.377s

Copy link
Copy Markdown
Owner

@joefitzgerald joefitzgerald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. Please let me know your thoughts on my feedback here...

Comment thread assignment.go Outdated
Comment thread assignment.go Outdated
Comment thread api.go
}
defer r.Body.Close()
if r.StatusCode >= http.StatusBadRequest {
body, err := io.ReadAll(r.Body)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like we shouldn't be throwing away the body? Shouldn't a create return the created entity (which would include its ID)? And shouldn't an update return the updated entity? That implies that doRequest should really also be generic, so that you can unmarshal the body into the expected response type?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agree, not including that was an oversight. Will fix this!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have addressed this in the latest commit

@Dylan-Bon Dylan-Bon requested a review from joefitzgerald May 19, 2026 16:03
@joefitzgerald joefitzgerald merged commit 1b0f057 into joefitzgerald:main May 21, 2026
2 checks passed
@joefitzgerald
Copy link
Copy Markdown
Owner

Thanks @Dylan-Bon 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants