Splitting design into separate services
This commit is contained in:
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