forked from fabric8-services/fabric8-wit
/
workitems.go
292 lines (270 loc) · 10 KB
/
workitems.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
package design
import (
"strings"
d "github.com/goadesign/goa/design"
a "github.com/goadesign/goa/design/apidsl"
)
// genericLinksForWorkItem defines generic relations links that are specific to a workitem
var genericLinksForWorkItem = a.Type("GenericLinksForWorkItem", func() {
a.Attribute("self", d.String)
a.Attribute("related", d.String)
a.Attribute("meta", a.HashOf(d.String, d.Any))
a.Attribute("editCodebase", d.String, "URL to generate Che-editor's link based on values of codebase field")
})
// workItem defines how an update payload will look like
var workItem = a.Type("WorkItem", func() {
a.Attribute("type", d.String, func() {
a.Enum("workitems")
})
a.Attribute("id", d.UUID, "ID of the work item which is being updated", func() {
a.Example("abcd1234-1234-5678-cafe-0123456789ab")
})
a.Attribute("attributes", a.HashOf(d.String, d.Any), func() {
a.Example(map[string]interface{}{"version": "1", "system.state": "new", "system.title": "Example story"})
})
a.Attribute("relationships", workItemRelationships)
a.Attribute("links", genericLinksForWorkItem)
a.Required("type", "attributes")
})
// WorkItemRelationships defines only `assignee` as of now. To be updated
var workItemRelationships = a.Type("WorkItemRelationships", func() {
a.Attribute("assignees", relationGenericList, "This defines assignees of the Work Item")
a.Attribute("labels", relationGenericList, "List of labels attached to the Work Item")
a.Attribute("creator", relationGeneric, "This defines creator of the Work Item")
a.Attribute("baseType", relationBaseType, "This defines type of Work Item")
a.Attribute("comments", relationGeneric, "This defines comments on the Work Item")
a.Attribute("iteration", relationGeneric, "This defines the iteration this work item belong to")
a.Attribute("area", relationGeneric, "This defines the area this work item belongs to")
a.Attribute("children", relationGeneric, "This defines the children of this work item")
a.Attribute("space", relationSpaces, "This defines the owning space of this work item.")
a.Attribute("parent", relationKindUUID, "This defines the parent of this work item.")
a.Attribute("workItemLinks", relationGeneric, "List of links in which this work item is involved")
})
// relationBaseType is top level block for WorkItemType relationship
var relationBaseType = a.Type("RelationBaseType", func() {
a.Attribute("data", baseTypeData)
a.Attribute("links", genericLinks)
a.Required("data")
})
// baseTypeData is data block for `type` of a work item
var baseTypeData = a.Type("BaseTypeData", func() {
a.Attribute("type", d.String, func() {
a.Enum("workitemtypes")
})
a.Attribute("id", d.UUID, "ID of the work item type")
a.Required("type", "id")
})
// workItemLinks has `self` as of now according to http://jsonapi.org/format/#fetching-resources
var workItemLinks = a.Type("WorkItemLinks", func() {
a.Attribute("self", d.String, func() {
a.Example("http://api.openshift.io/api/workitems.2/1")
})
a.Required("self")
})
// workItemList contains paged results for listing work items and paging links
var workItemList = JSONList(
"WorkItem", "Holds the paginated response to a work item list request",
workItem,
pagingLinks,
meta)
// workItemSingle is the media type for work items
var workItemSingle = JSONSingle(
"WorkItem", "A work item holds field values according to a given field type in JSONAPI form",
workItem,
workItemLinks)
// Reorder creates a UserTypeDefinition for Reorder action
func Reorder(name, description string, data *d.UserTypeDefinition, position *d.UserTypeDefinition) *d.MediaTypeDefinition {
return a.MediaType("application/vnd."+strings.ToLower(name)+"json", func() {
a.UseTrait("jsonapi-media-type")
a.TypeName(name + "Reorder")
a.Description(description)
a.Attribute("data", a.ArrayOf(data))
a.Attribute("position", position)
a.View("default", func() {
a.Attribute("data")
a.Required("data")
})
})
}
// workItemReorder is the media type for reorder of work items
var workItemReorder = Reorder(
"WorkItem", "Holds values for work item reorder",
workItem,
position)
// endpoints that DO NOT depend on the space id (ie, when the work item ID is specified in the URL, there's no need to pass the space ID)
var _ = a.Resource("workitem", func() {
a.BasePath("/workitems")
a.Action("show", func() {
a.Routing(
a.GET("/:wiID"),
)
a.Description("Retrieve a work item from the given id.")
a.Params(func() {
a.Param("wiID", d.UUID, "ID of the work item to show")
})
a.UseTrait("conditional")
a.Response(d.OK, workItemSingle)
a.Response(d.NotModified)
a.Response(d.BadRequest, JSONAPIErrors)
a.Response(d.InternalServerError, JSONAPIErrors)
a.Response(d.NotFound, JSONAPIErrors)
})
a.Action("list-children", func() {
a.Routing(
a.GET("/:wiID/children"),
)
a.Description("List children associated with the given work item")
a.Params(func() {
a.Param("wiID", d.UUID, "ID of the work item to look-up")
a.Param("page[offset]", d.String, `Paging start position is a string pointing to the beginning of pagination. The value starts from 0 onwards.`)
a.Param("page[limit]", d.Integer, `Paging size is the number of items in a page`)
})
a.UseTrait("conditional")
a.Response(d.OK, workItemList)
a.Response(d.NotModified)
a.Response(d.BadRequest, JSONAPIErrors)
a.Response(d.InternalServerError, JSONAPIErrors)
a.Response(d.NotFound, JSONAPIErrors)
})
a.Action("delete", func() {
a.Security("jwt")
a.Routing(
a.DELETE("/:wiID"),
)
a.Description("Delete work item with given its id.")
a.Params(func() {
a.Param("wiID", d.UUID, "ID of the work item to delete")
})
a.Response(d.MethodNotAllowed)
a.Response(d.OK)
a.Response(d.BadRequest, JSONAPIErrors)
a.Response(d.InternalServerError, JSONAPIErrors)
a.Response(d.NotFound, JSONAPIErrors)
a.Response(d.Unauthorized, JSONAPIErrors)
a.Response(d.Forbidden, JSONAPIErrors)
})
a.Action("update", func() {
a.Security("jwt")
a.Routing(
a.PATCH("/:wiID"),
)
a.Description("update the work item with the given natural id.")
a.Params(func() {
a.Param("wiID", d.UUID, "ID of the work item to update")
})
a.Payload(workItemSingle)
a.Response(d.OK, func() {
a.Media(workItemSingle)
})
a.Response(d.BadRequest, JSONAPIErrors)
a.Response(d.Conflict, JSONAPIErrors)
a.Response(d.InternalServerError, JSONAPIErrors)
a.Response(d.NotFound, JSONAPIErrors)
a.Response(d.Unauthorized, JSONAPIErrors)
a.Response(d.Forbidden, JSONAPIErrors)
})
})
// endpoints that depend on the space id
var _ = a.Resource("workitems", func() {
a.Parent("space")
a.BasePath("/workitems")
a.Action("list", func() {
a.Routing(
a.GET(""),
)
a.Description("List work items.")
a.Params(func() {
a.Param("filter", d.String, "a query language expression restricting the set of found work items")
a.Param("page[offset]", d.String, "Paging start position")
a.Param("page[limit]", d.Integer, "Paging size")
a.Param("filter[assignee]", d.String, "Work Items assigned to the given user")
a.Param("filter[iteration]", d.String, "IterationID to filter work items")
a.Param("filter[workitemtype]", d.UUID, "ID of work item type to filter work items by")
a.Param("filter[area]", d.String, "AreaID to filter work items")
a.Param("filter[workitemstate]", d.String, "work item state to filter work items by")
a.Param("filter[parentexists]", d.Boolean, "if false list work items without any parent")
a.Param("filter[expression]", d.String, "accepts query in JSON format and redirects to /api/search? API", func() {
a.Example(`{$AND: [{"space": "f73988a2-1916-4572-910b-2df23df4dcc3"}, {"state": "NEW"}]}`)
})
})
a.UseTrait("conditional")
a.Response(d.OK, workItemList)
a.Response(d.NotModified)
a.Response(d.BadRequest, JSONAPIErrors)
a.Response(d.InternalServerError, JSONAPIErrors)
a.Response(d.TemporaryRedirect)
})
a.Action("create", func() {
a.Security("jwt")
a.Routing(
a.POST(""),
)
a.Description("create work item with type and id.")
a.Payload(workItemSingle)
a.Response(d.Created, "/workitems/.*", func() {
a.Media(workItemSingle)
})
a.Response(d.BadRequest, JSONAPIErrors)
a.Response(d.InternalServerError, JSONAPIErrors)
a.Response(d.Unauthorized, JSONAPIErrors)
a.Response(d.Forbidden, JSONAPIErrors)
a.Response(d.NotFound, JSONAPIErrors)
})
a.Action("reorder", func() {
a.Security("jwt")
a.Routing(
a.PATCH("/reorder"),
)
a.Description("reorder the work items")
a.Payload(workItemReorder)
a.Response(d.OK, func() {
a.Media(workItemReorder)
})
a.Response(d.BadRequest, JSONAPIErrors)
a.Response(d.Conflict, JSONAPIErrors)
a.Response(d.InternalServerError, JSONAPIErrors)
a.Response(d.NotFound, JSONAPIErrors)
a.Response(d.Unauthorized, JSONAPIErrors)
a.Response(d.Forbidden, JSONAPIErrors)
})
})
var _ = a.Resource("planner_backlog", func() {
a.Parent("space")
a.BasePath("/backlog")
a.Action("list", func() {
a.Routing(
a.GET(""),
)
a.Description("List backlog work items.")
a.Params(func() {
a.Param("filter", d.String, "a query language expression restricting the set of found work items")
a.Param("page[offset]", d.String, "Paging start position")
a.Param("page[limit]", d.Integer, "Paging size")
a.Param("filter[assignee]", d.String, "Work Items assigned to the given user")
a.Param("filter[workitemtype]", d.UUID, "ID of work item type to filter work items by")
a.Param("filter[area]", d.String, "AreaID to filter work items")
})
a.UseTrait("conditional")
a.Response(d.OK, workItemList)
a.Response(d.NotModified)
a.Response(d.BadRequest, JSONAPIErrors)
a.Response(d.NotFound, JSONAPIErrors)
a.Response(d.InternalServerError, JSONAPIErrors)
})
})
var _ = a.Resource("named_work_items", func() {
a.Parent("namedspaces")
a.BasePath("/workitems")
a.Action("show", func() {
a.Routing(
a.GET("/:wiNumber"),
)
a.Description("Retrieve a work item from the given number.")
a.Params(func() {
a.Param("wiNumber", d.Integer, "Number of the work item to show")
})
a.Response(d.TemporaryRedirect)
a.Response(d.InternalServerError, JSONAPIErrors)
a.Response(d.NotFound, JSONAPIErrors)
})
})