253 lines
4.7 KiB
Go
253 lines
4.7 KiB
Go
package design
|
||
|
||
import (
|
||
. "goa.design/goa/v3/dsl"
|
||
)
|
||
|
||
var _ = API("api", func() {
|
||
Title("API Service")
|
||
Description("An HTTP/JSON front service which provides an API to manipulate the characters, their inventories, and the items that exist")
|
||
Server("api", func() {
|
||
Host("localhost", func() {
|
||
URI("http://localhost:8000")
|
||
URI("grpc://localhost:8080")
|
||
})
|
||
})
|
||
})
|
||
|
||
var empty = Type("empty")
|
||
|
||
var item = Type("item", func() {
|
||
Field(1, "id", Int)
|
||
Field(2, "name", String)
|
||
Field(3, "description", String)
|
||
Field(4, "multiplier", String)
|
||
Field(5, "type", String)
|
||
Required("name", "description", "multiplier", "type")
|
||
})
|
||
|
||
var character = Type("character", func() {
|
||
Field(1, "id", Int)
|
||
Field(2, "name", String)
|
||
Field(3, "description", String)
|
||
Field(4, "class", String)
|
||
Required("name", "description", "class")
|
||
})
|
||
|
||
var _ = Service("item", func() {
|
||
Description("A GRPC back service that handles CRUD operations for the items that exist and their attributes")
|
||
|
||
Method("getItem", func() {
|
||
Payload(Int)
|
||
Result(item)
|
||
Error("NotFound")
|
||
|
||
HTTP(func() {
|
||
GET("/item/{id}")
|
||
Response(StatusOK)
|
||
Response(StatusBadRequest)
|
||
Response(StatusNotFound)
|
||
})
|
||
|
||
GRPC(func() {
|
||
Response(CodeOK)
|
||
})
|
||
})
|
||
|
||
// Method("listItems", func() {
|
||
// })
|
||
|
||
Method("createItem", func() {
|
||
Payload(item)
|
||
Result(item)
|
||
Error("BadRequest")
|
||
|
||
HTTP(func() {
|
||
POST("/item")
|
||
Body(item)
|
||
Response(StatusOK)
|
||
Response(StatusBadRequest)
|
||
})
|
||
|
||
GRPC(func() {
|
||
Response(CodeOK)
|
||
})
|
||
})
|
||
|
||
Method("updateItem", func() {
|
||
Payload(item)
|
||
Result(item)
|
||
Error("NotFound")
|
||
Error("BadRequest")
|
||
|
||
HTTP(func() {
|
||
PUT("/item/{id}")
|
||
Body(item)
|
||
Response(StatusOK)
|
||
Response(StatusBadRequest)
|
||
Response(StatusNotFound)
|
||
})
|
||
|
||
GRPC(func() {
|
||
Response(CodeOK)
|
||
})
|
||
})
|
||
|
||
Method("deleteItem", func() {
|
||
Payload(Int)
|
||
Result(empty)
|
||
Error("NotFound")
|
||
Error("BadRequest")
|
||
|
||
HTTP(func() {
|
||
POST("/item/{id}")
|
||
Response(StatusOK)
|
||
Response(StatusBadRequest)
|
||
Response(StatusNotFound)
|
||
})
|
||
|
||
GRPC(func() {
|
||
Response(CodeOK)
|
||
Response("NotFound", CodeNotFound)
|
||
Response("BadRequest", CodeInvalidArgument)
|
||
})
|
||
})
|
||
|
||
Files("/openapi.json", "./gen/http/openapi.json")
|
||
})
|
||
|
||
var _ = Service("character", func() {
|
||
Description("A GRPC back service that handles CRUD operations for the characters and their attributes")
|
||
|
||
Method("getCharacter", func() {
|
||
Payload(Int)
|
||
Result(character)
|
||
Error("NotFound")
|
||
Error("BadRequest")
|
||
|
||
HTTP(func() {
|
||
GET("/character/{id}")
|
||
Response(StatusOK)
|
||
Response(StatusBadRequest)
|
||
Response(StatusNotFound)
|
||
})
|
||
|
||
GRPC(func() {
|
||
Response(CodeOK)
|
||
Response("NotFound", CodeNotFound)
|
||
Response("BadRequest", CodeInvalidArgument)
|
||
})
|
||
})
|
||
|
||
// Method("listCharacters", func() {
|
||
// })
|
||
|
||
Method("createCharacter", func() {
|
||
Payload(character)
|
||
Result(character)
|
||
Error("BadRequest")
|
||
Error("NotFound")
|
||
|
||
HTTP(func() {
|
||
POST("/character")
|
||
Body(character)
|
||
Response(StatusBadRequest)
|
||
Response(StatusOK)
|
||
Response(StatusInternalServerError)
|
||
})
|
||
|
||
GRPC(func() {
|
||
Response(CodeOK)
|
||
Response("NotFound", CodeNotFound)
|
||
Response("BadRequest", CodeInvalidArgument)
|
||
})
|
||
})
|
||
|
||
Method("updateCharacter", func() {
|
||
Payload(character)
|
||
Result(character)
|
||
Error("NotFound")
|
||
Error("BadRequest")
|
||
|
||
HTTP(func() {
|
||
PUT("/character/{id}")
|
||
Body(character)
|
||
Response(StatusOK)
|
||
Response(StatusBadRequest)
|
||
Response(StatusNotFound)
|
||
})
|
||
|
||
GRPC(func() {
|
||
Response(CodeOK)
|
||
Response("NotFound", CodeNotFound)
|
||
Response("BadRequest", CodeInvalidArgument)
|
||
})
|
||
})
|
||
|
||
Method("deleteCharacter", func() {
|
||
Payload(Int)
|
||
Result(empty)
|
||
Error("NotFound")
|
||
Error("BadRequest")
|
||
|
||
HTTP(func() {
|
||
POST("/character/{id}")
|
||
Response(StatusOK)
|
||
Response(StatusBadRequest)
|
||
Response(StatusNotFound)
|
||
})
|
||
|
||
GRPC(func() {
|
||
Response(CodeOK)
|
||
Response("NotFound", CodeNotFound)
|
||
Response("BadRequest", CodeInvalidArgument)
|
||
})
|
||
})
|
||
|
||
Files("/openapi.json", "./gen/http/openapi.json")
|
||
})
|
||
|
||
var _ = Service("inventory", func() {
|
||
Description("A GRPC back service that handles CRUD operations for the characters’ inventories")
|
||
|
||
// Method("listItems", func() {
|
||
// })
|
||
|
||
Method("addItem", func() {
|
||
Payload(Int)
|
||
Result(empty)
|
||
Error("NotFound")
|
||
Error("BadRequest")
|
||
|
||
HTTP(func() {
|
||
POST("/inventory/{characterId}")
|
||
Response(StatusOK)
|
||
Response(StatusBadRequest)
|
||
})
|
||
|
||
GRPC(func() {
|
||
Response(CodeOK)
|
||
})
|
||
})
|
||
|
||
Method("removeItem", func() {
|
||
Payload(Int)
|
||
Result(empty)
|
||
Error("NotFound")
|
||
Error("BadRequest")
|
||
|
||
HTTP(func() {
|
||
PUT("/inventory/{characterId}")
|
||
Response(StatusOK)
|
||
Response(StatusBadRequest)
|
||
})
|
||
|
||
GRPC(func() {
|
||
Response(CodeOK)
|
||
Response("NotFound", CodeNotFound)
|
||
Response("BadRequest", CodeInvalidArgument)
|
||
})
|
||
})
|
||
|
||
Files("/openapi.json", "./gen/http/openapi.json")
|
||
}) |