Splitting design into separate services
This commit is contained in:
45
services/character/character.go
Normal file
45
services/character/character.go
Normal file
@ -0,0 +1,45 @@
|
||||
package characterapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
character "crossnokaye-interview-assignment/services/character/gen/character"
|
||||
"log"
|
||||
)
|
||||
|
||||
// character service example implementation.
|
||||
// The example methods log the requests and return zero values.
|
||||
type charactersrvc struct {
|
||||
logger *log.Logger
|
||||
}
|
||||
|
||||
// NewCharacter returns the character service implementation.
|
||||
func NewCharacter(logger *log.Logger) character.Service {
|
||||
return &charactersrvc{logger}
|
||||
}
|
||||
|
||||
// GetCharacter implements getCharacter.
|
||||
func (s *charactersrvc) GetCharacter(ctx context.Context, p int) (res *character.Character, err error) {
|
||||
res = &character.Character{}
|
||||
s.logger.Print("character.getCharacter")
|
||||
return
|
||||
}
|
||||
|
||||
// CreateCharacter implements createCharacter.
|
||||
func (s *charactersrvc) CreateCharacter(ctx context.Context, p *character.Character) (res *character.Character, err error) {
|
||||
res = &character.Character{}
|
||||
s.logger.Print("character.createCharacter")
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateCharacter implements updateCharacter.
|
||||
func (s *charactersrvc) UpdateCharacter(ctx context.Context, p *character.Character) (res *character.Character, err error) {
|
||||
res = &character.Character{}
|
||||
s.logger.Print("character.updateCharacter")
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteCharacter implements deleteCharacter.
|
||||
func (s *charactersrvc) DeleteCharacter(ctx context.Context, p int) (err error) {
|
||||
s.logger.Print("character.deleteCharacter")
|
||||
return
|
||||
}
|
75
services/character/design/design.go
Normal file
75
services/character/design/design.go
Normal file
@ -0,0 +1,75 @@
|
||||
package design
|
||||
|
||||
import (
|
||||
. "crossnokaye-interview-assignment/design"
|
||||
|
||||
. "goa.design/goa/v3/dsl"
|
||||
)
|
||||
|
||||
var _ = API("character", func() {
|
||||
Title("Character Srvice")
|
||||
Server("character", func() {
|
||||
Host("localhost", func() {
|
||||
URI("grpc://localhost:8083")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
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")
|
||||
|
||||
GRPC(func() {
|
||||
Response(CodeOK)
|
||||
Response("NotFound", CodeNotFound)
|
||||
Response("BadRequest", CodeInvalidArgument)
|
||||
})
|
||||
})
|
||||
|
||||
// Method("listCharacters", func() {
|
||||
// })
|
||||
|
||||
Method("createCharacter", func() {
|
||||
Payload(Character)
|
||||
Result(Character)
|
||||
Error("BadRequest")
|
||||
Error("NotFound")
|
||||
|
||||
GRPC(func() {
|
||||
Response(CodeOK)
|
||||
Response("NotFound", CodeNotFound)
|
||||
Response("BadRequest", CodeInvalidArgument)
|
||||
})
|
||||
})
|
||||
|
||||
Method("updateCharacter", func() {
|
||||
Payload(Character)
|
||||
Result(Character)
|
||||
Error("NotFound")
|
||||
Error("BadRequest")
|
||||
|
||||
GRPC(func() {
|
||||
Response(CodeOK)
|
||||
Response("NotFound", CodeNotFound)
|
||||
Response("BadRequest", CodeInvalidArgument)
|
||||
})
|
||||
})
|
||||
|
||||
Method("deleteCharacter", func() {
|
||||
Payload(Int)
|
||||
Result(Empty)
|
||||
Error("NotFound")
|
||||
Error("BadRequest")
|
||||
|
||||
GRPC(func() {
|
||||
Response(CodeOK)
|
||||
Response("NotFound", CodeNotFound)
|
||||
Response("BadRequest", CodeInvalidArgument)
|
||||
})
|
||||
})
|
||||
})
|
220
services/front/design/design.go
Normal file
220
services/front/design/design.go
Normal file
@ -0,0 +1,220 @@
|
||||
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(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)
|
||||
})
|
||||
})
|
||||
|
||||
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)
|
||||
})
|
||||
})
|
||||
|
||||
Method("addItemToInventory", func() {
|
||||
Payload(Int)
|
||||
Result(Empty)
|
||||
Error("NotFound")
|
||||
Error("BadRequest")
|
||||
|
||||
HTTP(func() {
|
||||
POST("/inventory/{CharacterId}")
|
||||
Response(StatusOK)
|
||||
Response(StatusBadRequest)
|
||||
})
|
||||
|
||||
GRPC(func() {
|
||||
Response(CodeOK)
|
||||
})
|
||||
})
|
||||
|
||||
Method("removeItemFromInventory", 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")
|
||||
})
|
84
services/front/front.go
Normal file
84
services/front/front.go
Normal file
@ -0,0 +1,84 @@
|
||||
package frontapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
front "crossnokaye-interview-assignment/services/front/gen/front"
|
||||
"log"
|
||||
)
|
||||
|
||||
// front service example implementation.
|
||||
// The example methods log the requests and return zero values.
|
||||
type frontsrvc struct {
|
||||
logger *log.Logger
|
||||
}
|
||||
|
||||
// NewFront returns the front service implementation.
|
||||
func NewFront(logger *log.Logger) front.Service {
|
||||
return &frontsrvc{logger}
|
||||
}
|
||||
|
||||
// GetItem implements getItem.
|
||||
func (s *frontsrvc) GetItem(ctx context.Context, p int) (res *front.Item, err error) {
|
||||
res = &front.Item{}
|
||||
s.logger.Print("front.getItem")
|
||||
return
|
||||
}
|
||||
|
||||
// CreateItem implements createItem.
|
||||
func (s *frontsrvc) CreateItem(ctx context.Context, p *front.Item) (res *front.Item, err error) {
|
||||
res = &front.Item{}
|
||||
s.logger.Print("front.createItem")
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateItem implements updateItem.
|
||||
func (s *frontsrvc) UpdateItem(ctx context.Context, p *front.Item) (res *front.Item, err error) {
|
||||
res = &front.Item{}
|
||||
s.logger.Print("front.updateItem")
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteItem implements deleteItem.
|
||||
func (s *frontsrvc) DeleteItem(ctx context.Context, p int) (err error) {
|
||||
s.logger.Print("front.deleteItem")
|
||||
return
|
||||
}
|
||||
|
||||
// GetCharacter implements getCharacter.
|
||||
func (s *frontsrvc) GetCharacter(ctx context.Context, p int) (res *front.Character, err error) {
|
||||
res = &front.Character{}
|
||||
s.logger.Print("front.getCharacter")
|
||||
return
|
||||
}
|
||||
|
||||
// CreateCharacter implements createCharacter.
|
||||
func (s *frontsrvc) CreateCharacter(ctx context.Context, p *front.Character) (res *front.Character, err error) {
|
||||
res = &front.Character{}
|
||||
s.logger.Print("front.createCharacter")
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateCharacter implements updateCharacter.
|
||||
func (s *frontsrvc) UpdateCharacter(ctx context.Context, p *front.Character) (res *front.Character, err error) {
|
||||
res = &front.Character{}
|
||||
s.logger.Print("front.updateCharacter")
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteCharacter implements deleteCharacter.
|
||||
func (s *frontsrvc) DeleteCharacter(ctx context.Context, p int) (err error) {
|
||||
s.logger.Print("front.deleteCharacter")
|
||||
return
|
||||
}
|
||||
|
||||
// AddItemToInventory implements addItemToInventory.
|
||||
func (s *frontsrvc) AddItemToInventory(ctx context.Context, p int) (err error) {
|
||||
s.logger.Print("front.addItemToInventory")
|
||||
return
|
||||
}
|
||||
|
||||
// RemoveItemFromInventory implements removeItemFromInventory.
|
||||
func (s *frontsrvc) RemoveItemFromInventory(ctx context.Context, p int) (err error) {
|
||||
s.logger.Print("front.removeItemFromInventory")
|
||||
return
|
||||
}
|
44
services/inventory/design/design.go
Normal file
44
services/inventory/design/design.go
Normal file
@ -0,0 +1,44 @@
|
||||
package design
|
||||
|
||||
import (
|
||||
. "goa.design/goa/v3/dsl"
|
||||
)
|
||||
|
||||
var _ = API("inventory", func() {
|
||||
Title("Inventory Service")
|
||||
Server("inventory", func() {
|
||||
Host("localhost", func() {
|
||||
URI("grpc://localhost:8081")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
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")
|
||||
|
||||
GRPC(func() {
|
||||
Response(CodeOK)
|
||||
})
|
||||
})
|
||||
|
||||
Method("removeItem", func() {
|
||||
Payload(Int)
|
||||
Result(Empty)
|
||||
Error("NotFound")
|
||||
Error("BadRequest")
|
||||
|
||||
GRPC(func() {
|
||||
Response(CodeOK)
|
||||
Response("NotFound", CodeNotFound)
|
||||
Response("BadRequest", CodeInvalidArgument)
|
||||
})
|
||||
})
|
||||
})
|
30
services/inventory/inventory.go
Normal file
30
services/inventory/inventory.go
Normal file
@ -0,0 +1,30 @@
|
||||
package inventoryapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
inventory "crossnokaye-interview-assignment/services/inventory/gen/inventory"
|
||||
"log"
|
||||
)
|
||||
|
||||
// inventory service example implementation.
|
||||
// The example methods log the requests and return zero values.
|
||||
type inventorysrvc struct {
|
||||
logger *log.Logger
|
||||
}
|
||||
|
||||
// NewInventory returns the inventory service implementation.
|
||||
func NewInventory(logger *log.Logger) inventory.Service {
|
||||
return &inventorysrvc{logger}
|
||||
}
|
||||
|
||||
// AddItem implements addItem.
|
||||
func (s *inventorysrvc) AddItem(ctx context.Context, p int) (err error) {
|
||||
s.logger.Print("inventory.addItem")
|
||||
return
|
||||
}
|
||||
|
||||
// RemoveItem implements removeItem.
|
||||
func (s *inventorysrvc) RemoveItem(ctx context.Context, p int) (err error) {
|
||||
s.logger.Print("inventory.removeItem")
|
||||
return
|
||||
}
|
67
services/item/design/design.go
Normal file
67
services/item/design/design.go
Normal file
@ -0,0 +1,67 @@
|
||||
package design
|
||||
|
||||
import (
|
||||
. "crossnokaye-interview-assignment/design"
|
||||
|
||||
. "goa.design/goa/v3/dsl"
|
||||
)
|
||||
|
||||
var _ = API("item", func() {
|
||||
Title("Item Service")
|
||||
Server("item", func() {
|
||||
Host("localhost", func() {
|
||||
URI("grpc://localhost:8082")
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
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")
|
||||
|
||||
GRPC(func() {
|
||||
Response(CodeOK)
|
||||
})
|
||||
})
|
||||
|
||||
// Method("listItems", func() {
|
||||
// })
|
||||
|
||||
Method("createItem", func() {
|
||||
Payload(Item)
|
||||
Result(Item)
|
||||
Error("BadRequest")
|
||||
|
||||
GRPC(func() {
|
||||
Response(CodeOK)
|
||||
})
|
||||
})
|
||||
|
||||
Method("updateItem", func() {
|
||||
Payload(Item)
|
||||
Result(Item)
|
||||
Error("NotFound")
|
||||
Error("BadRequest")
|
||||
|
||||
GRPC(func() {
|
||||
Response(CodeOK)
|
||||
})
|
||||
})
|
||||
|
||||
Method("deleteItem", func() {
|
||||
Payload(Int)
|
||||
Result(Empty)
|
||||
Error("NotFound")
|
||||
Error("BadRequest")
|
||||
|
||||
GRPC(func() {
|
||||
Response(CodeOK)
|
||||
Response("NotFound", CodeNotFound)
|
||||
Response("BadRequest", CodeInvalidArgument)
|
||||
})
|
||||
})
|
||||
})
|
45
services/item/item.go
Normal file
45
services/item/item.go
Normal file
@ -0,0 +1,45 @@
|
||||
package itemapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
item "crossnokaye-interview-assignment/services/item/gen/item"
|
||||
"log"
|
||||
)
|
||||
|
||||
// item service example implementation.
|
||||
// The example methods log the requests and return zero values.
|
||||
type itemsrvc struct {
|
||||
logger *log.Logger
|
||||
}
|
||||
|
||||
// NewItem returns the item service implementation.
|
||||
func NewItem(logger *log.Logger) item.Service {
|
||||
return &itemsrvc{logger}
|
||||
}
|
||||
|
||||
// GetItem implements getItem.
|
||||
func (s *itemsrvc) GetItem(ctx context.Context, p int) (res *item.Item, err error) {
|
||||
res = &item.Item{}
|
||||
s.logger.Print("item.getItem")
|
||||
return
|
||||
}
|
||||
|
||||
// CreateItem implements createItem.
|
||||
func (s *itemsrvc) CreateItem(ctx context.Context, p *item.Item) (res *item.Item, err error) {
|
||||
res = &item.Item{}
|
||||
s.logger.Print("item.createItem")
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateItem implements updateItem.
|
||||
func (s *itemsrvc) UpdateItem(ctx context.Context, p *item.Item) (res *item.Item, err error) {
|
||||
res = &item.Item{}
|
||||
s.logger.Print("item.updateItem")
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteItem implements deleteItem.
|
||||
func (s *itemsrvc) DeleteItem(ctx context.Context, p int) (err error) {
|
||||
s.logger.Print("item.deleteItem")
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user