Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

Commit

Permalink
WorkItem Update should use the ID passed in URL (#125)
Browse files Browse the repository at this point in the history
* WorkItem Update should happen by ID passed in URL

The WorkItem to be updated should be referred by its ID in the URL as a api/workitem/:id and the code should not be reading it from the payload since its not an editable field. This changed required a change in the goa design. The make task autogenerates sources inside the app/ dir

Fixes #95 #47

Signed-off-by: Shoubhik <shoubhik@dhcp35-156.lab.eng.blr.redhat.com>
  • Loading branch information
sbose78 authored and tsmaeder committed Aug 17, 2016
1 parent d1e1289 commit 829fdae
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
9 changes: 6 additions & 3 deletions design/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,13 @@ var _ = Resource("workitem", func() {
})
Action("update", func() {
Routing(
PUT(""),
PUT("/:id"),
)
Description("update the given work item.")
Payload(WorkItem)
Description("update the given work item with given id.")
Params(func() {
Param("id", String, "id")
})
Payload(UpdateWorkItemPayload)
Response(OK, func() {
Media(WorkItem)
})
Expand Down
11 changes: 11 additions & 0 deletions design/user_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,14 @@ var CreateWorkItemPayload = Type("CreateWorkItemPayload", func() {
Attribute("fields", HashOf(String, Any), "The field values, must conform to the type")
Required("type", "name", "fields")
})

// UpdateWorkItemPayload has been added because the design.WorkItem could
// not be used since it mand, wi.IDated the presence of the ID in the payload
// which ideally should be optional. The ID should be passed on to REST URL.
var UpdateWorkItemPayload = Type("UpdateWorkItemPayload", func() {
Attribute("type", String, "The type of the newly created work item")
Attribute("name", String, "User Readable Name of this item")
Attribute("fields", HashOf(String, Any), "The field values, must conform to the type")
Attribute("version", Integer, "Version for optimistic concurrency control")
Required("type", "name", "fields", "version")
})
2 changes: 1 addition & 1 deletion workitem.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (c *WorkitemController) Update(ctx *app.UpdateWorkitemContext) error {
return transaction.Do(c.ts, func() error {

toSave := app.WorkItem{
ID: ctx.Payload.ID,
ID: ctx.ID,
Name: ctx.Payload.Name,
Type: ctx.Payload.Type,
Version: ctx.Payload.Version,
Expand Down
3 changes: 1 addition & 2 deletions workitem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,12 @@ func TestGetWorkItem(t *testing.T) {

wi.Fields["system.owner"] = "thomas"
payload2 := app.UpdateWorkitemPayload{
ID: wi.ID,
Name: wi.Name,
Type: wi.Type,
Version: wi.Version,
Fields: wi.Fields,
}
_, updated := test.UpdateWorkitemOK(t, nil, nil, &controller, &payload2)
_, updated := test.UpdateWorkitemOK(t, nil, nil, &controller, wi.ID, &payload2)
if updated.Version != result.Version+1 {
t.Errorf("expected version %d, but got %d", result.Version+1, updated.Version)
}
Expand Down

0 comments on commit 829fdae

Please sign in to comment.