-
Notifications
You must be signed in to change notification settings - Fork 0
/
dia.go
115 lines (96 loc) · 2.4 KB
/
dia.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
package design
import (
. "github.com/goadesign/goa/design"
. "github.com/goadesign/goa/design/apidsl"
)
var _ = Resource("DIA", func() {
BasePath("/dia")
// Seems that goa doesn't like setting DefaultMedia here at the top-level when the MediaType has multiple Views.
// DefaultMedia(DIAMedia)
Description("Describes a DIA code.")
Action("create", func() {
Routing(POST("/"))
Description("Create a new DIA code.")
Payload(DIAPayload)
Response(OK, DIAMedia)
})
Action("update", func() {
Routing(PUT("/:id"))
Payload(DIAPayload)
Params(func() {
Param("id", Integer, "DIA ID")
})
Description("Update a dia code by id.")
Response(OK, DIAMedia)
})
Action("delete", func() {
Routing(DELETE("/:id"))
Params(func() {
Param("id", Integer, "DIA ID")
})
Description("Delete a dia code by id.")
Response(OK, func() {
Status(200)
Media(DIAMedia, "tiny")
})
})
Action("list", func() {
Routing(GET("/list"))
Description("Get all dia codes")
Response(OK, CollectionOf(DIAMedia))
})
Action("page", func() {
Routing(GET("/list/:page"))
Params(func() {
Param("page", Integer, "Given a page number, returns an object consisting of the slice of DIAs and a pager object")
})
Description("Get a page of DIAs")
Response(OK, func() {
Status(200)
Media(DIAMedia, "paging")
})
})
})
var DIAPayload = Type("DIAPayload", func() {
Description("DIA Description.")
Attribute("id", Integer, "ID", func() {
Metadata("struct:tag:datastore", "id,noindex")
Metadata("struct:tag:json", "id")
})
Attribute("name", String, "DIA name", func() {
Metadata("struct:tag:datastore", "name,noindex")
Metadata("struct:tag:json", "name")
})
Required("name")
})
var DIAItem = Type("DIAItem", func() {
Reference(DIAPayload)
Attribute("id")
Attribute("name")
Required("id", "name")
})
var DIAMedia = MediaType("application/diacodeapi.diacodeentity", func() {
Description("DIA response")
TypeName("DIAMedia")
ContentType("application/json")
Reference(DIAPayload)
Attributes(func() {
Attribute("id")
Attribute("name")
Attribute("dias", ArrayOf("DIAItem"))
Attribute("pager", Pager)
Required("id", "name", "dias", "pager")
})
View("default", func() {
Attribute("id")
Attribute("name")
})
View("paging", func() {
Attribute("dias")
Attribute("pager")
})
View("tiny", func() {
Description("`tiny` is the view used to create new dia code.")
Attribute("id")
})
})