Implements /transactions PUT method #22
2 Participants
Notifications
Due Date
No due date set.
Blocks
Depends on
#25 Fix resources naming scheme
personal-finance/datastore
#19 Implements /transactions POST method
personal-finance/datastore
Reference: personal-finance/datastore#22
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "feature/20-transactions-put"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Implements /transactions PUT method
Adds PUT method to OpenAPI spec.
Given that the transaction IDs are generated on server-side, for the PUT
method to remain idempotent, it can only update existing transactions.
It also adds a TransactionExists method on the DAL.
Issue: #20
WIP: feature/20-transactions-putto feature/20-transactions-putfeature/20-transactions-putto Implements /transactions PUT method35b35f5e40to55bd87c864@ -59,0 +85,4 @@- required:- idresponses:Is this the only response allowed? If you pass an Id that does not exist what would be the expected response?
Fixed on #25. I was initially thinking that a PUT could also create transactions, however the recommendation from the spec is that when the URI of a resource is generated server-side, creations should be implemented in the POST method only. 4.3.4. PUT
@ -11,0 +27,4 @@}return entity.Transaction{Id: id,Does it make sense to create a entity.Transaction with an invalid Id. If the Transaction provided as argument has an t.Id == nil then the entity.Transaction we create is nil. Could this lead to more trouble down the line? Would it make sense to "throw" or have some kind of error message here?
You raise a good question. Logically, I don't think it's possible to have an invalid ID, it should be prevented by the OpenAPI spec. I think at the time this stayed like this to facilitate the type going into the DAL. This would only be an invalid ID when the actual ID is getting created at the DB.
But I could imagine this being an issue down the line, you can create a techdebt and/or question issue on the repo.
PS: this was on the previous commit, can't change it now.
@ -77,0 +76,4 @@return ctx.JSON(http.StatusOK, entity2transaction(*transaction))}func (server *ServerImpl) CreateTransaction(ctx echo.Context) error {Does "error" correspond to the output of this function? Is this name by default? I feel like since you may get error or sucess status code the name could be StatusCode or JSONResult or something like that. But I'm not sure. :)
This is idiomatic Go. If the error == nil, then the function worked. https://go.dev/doc/effective_go#errors
@ -77,0 +107,4 @@return ctx.NoContent(http.StatusInternalServerError)}if exists {I would have inverted this if condition. It would have lowered the number of cascaded ifs below. Not that this is a problem. The number of nested ifs is really small :)
Removed on #25.
I left some small comments which do not affect in the least the fantastic quality of this commit! 5 stars. Would recommend on trip advisor. 😄