Add write support for assignments (POST, PUT, DELETE)#26
Merged
Conversation
Owner
joefitzgerald
left a comment
There was a problem hiding this comment.
Thanks for the contribution. Please let me know your thoughts on my feedback here...
| } | ||
| defer r.Body.Close() | ||
| if r.StatusCode >= http.StatusBadRequest { | ||
| body, err := io.ReadAll(r.Body) |
Owner
There was a problem hiding this comment.
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?
Contributor
Author
There was a problem hiding this comment.
Totally agree, not including that was an oversight. Will fix this!
Contributor
Author
There was a problem hiding this comment.
I have addressed this in the latest commit
Owner
|
Thanks @Dylan-Bon 🙏 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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) errorAssignmentRequest— a new type used as the request payload for mutations. Kept separate fromAssignment(the GET response type) to avoid a breaking change, and because the shapes differ — request payloads don't include server-assigned fields likeid,updated_at, andupdated_by_id. Nullable fields use pointer types to correctly represent JSONnull.api.go
mutatehandles requests with a body (POST, PUT)mutateNoBodyhandles requests without a body (DELETE)initClient()to remove duplicated HTTP client initialisation acrossgetand the new mutation functionsTest Results
Suite: forecast
Total: 37 | Focused: 0 | Pending: 0
.....................................
Passed: 37 | Failed: 0 | Skipped: 0
PASS
ok github.com/joefitzgerald/forecast 0.377s