180 lines
3.3 KiB
Go
180 lines
3.3 KiB
Go
package design
|
|
|
|
import (
|
|
. "crossnokaye-interview-assignment/design"
|
|
|
|
. "goa.design/goa/v3/dsl"
|
|
)
|
|
|
|
var _ = API("front", func() {
|
|
Title("API Front Service")
|
|
Description("An HTTP/JSON front service which provides an API to manipulate the Characters, their inventories, and the Items that exist")
|
|
Server("front", func() {
|
|
Host("localhost", func() {
|
|
URI("http://localhost:8000")
|
|
})
|
|
})
|
|
})
|
|
|
|
var _ = Service("front", func() {
|
|
Description("A GRPC back service that handles CRUD operations for the Items that exist and their attributes")
|
|
|
|
Method("getItem", func() {
|
|
Payload(String)
|
|
Result(Item)
|
|
Error("NotFound")
|
|
|
|
HTTP(func() {
|
|
GET("/item/{name}")
|
|
Response(StatusOK)
|
|
Response("NotFound", StatusNotFound)
|
|
})
|
|
})
|
|
|
|
Method("listItems", func() {
|
|
Payload(Empty)
|
|
Result(ArrayOf(Item))
|
|
|
|
HTTP(func() {
|
|
GET("/item")
|
|
Response(StatusOK)
|
|
})
|
|
})
|
|
|
|
Method("createItem", func() {
|
|
Payload(Item)
|
|
Result(Item)
|
|
Error("AlreadyExists")
|
|
|
|
HTTP(func() {
|
|
POST("/item")
|
|
Response(StatusOK)
|
|
Response("AlreadyExists", StatusConflict)
|
|
})
|
|
})
|
|
|
|
Method("updateItem", func() {
|
|
Payload(Item)
|
|
Result(Item)
|
|
Error("NotFound")
|
|
|
|
HTTP(func() {
|
|
PUT("/item/{name}")
|
|
Response(StatusOK)
|
|
Response("NotFound", StatusNotFound)
|
|
})
|
|
})
|
|
|
|
Method("deleteItem", func() {
|
|
Payload(String)
|
|
Result(Empty)
|
|
Error("NotFound")
|
|
Error("BadRequest")
|
|
|
|
HTTP(func() {
|
|
DELETE("/item/{name}")
|
|
Response(StatusOK)
|
|
Response("NotFound", StatusNotFound)
|
|
Response("BadRequest", StatusBadRequest)
|
|
})
|
|
})
|
|
|
|
Method("getCharacter", func() {
|
|
Payload(String)
|
|
Result(Character)
|
|
Error("NotFound")
|
|
|
|
HTTP(func() {
|
|
GET("/character/{name}")
|
|
Response(StatusOK)
|
|
Response("NotFound", StatusNotFound)
|
|
})
|
|
})
|
|
|
|
Method("listCharacters", func() {
|
|
Payload(Empty)
|
|
Result(ArrayOf(Character))
|
|
|
|
HTTP(func() {
|
|
GET("/character")
|
|
Response(StatusOK)
|
|
})
|
|
})
|
|
|
|
Method("createCharacter", func() {
|
|
Payload(Character)
|
|
Result(Character)
|
|
Error("NotFound")
|
|
|
|
HTTP(func() {
|
|
POST("/character")
|
|
Response(StatusOK)
|
|
Response("NotFound", StatusNotFound)
|
|
})
|
|
})
|
|
|
|
Method("updateCharacter", func() {
|
|
Payload(Character)
|
|
Result(Character)
|
|
Error("NotFound")
|
|
|
|
HTTP(func() {
|
|
PUT("/character/{name}")
|
|
Response(StatusOK)
|
|
Response("NotFound", StatusNotFound)
|
|
})
|
|
})
|
|
|
|
Method("deleteCharacter", func() {
|
|
Payload(String)
|
|
Result(Empty)
|
|
Error("NotFound")
|
|
|
|
HTTP(func() {
|
|
DELETE("/character/{name}")
|
|
Response(StatusOK)
|
|
Response("NotFound", StatusNotFound)
|
|
})
|
|
})
|
|
|
|
Method("addItemToInventory", func() {
|
|
Payload(InventoryRecord)
|
|
Result(Empty)
|
|
Error("NotFound")
|
|
|
|
HTTP(func() {
|
|
POST("/character/{characterName}/item")
|
|
Response(StatusOK)
|
|
Response("NotFound", StatusNotFound)
|
|
})
|
|
})
|
|
|
|
Method("removeItemFromInventory", func() {
|
|
Payload(InventoryRecord)
|
|
Result(Empty)
|
|
Error("NotFound")
|
|
|
|
HTTP(func() {
|
|
DELETE("/character/{characterName}/item/{itemName}")
|
|
Response(StatusOK)
|
|
Response("NotFound", StatusNotFound)
|
|
})
|
|
})
|
|
|
|
Method("listInventoryItems", func() {
|
|
Payload(func() {
|
|
Field(1, "characterName", String)
|
|
})
|
|
Result(ArrayOf(Item))
|
|
Error("NotFound")
|
|
|
|
HTTP(func() {
|
|
GET("/character/{characterName}/item")
|
|
Response(StatusOK)
|
|
Response("NotFound", StatusNotFound)
|
|
})
|
|
})
|
|
|
|
Files("/openapi.json", "./gen/http/openapi.json")
|
|
})
|