123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- package JeopardyManager
- import (
- "context"
- "errors"
- gljeopardypb "git.alfi.li/gamelang/protobuf/gamelang-jeopardy"
- )
- type JeopardyServer struct {
- gljeopardypb.UnimplementedJeopardyServiceServer
- JeopardyManager *JeopardyManager
- }
- func NewJeopardyServer(um *JeopardyManager) *JeopardyServer {
- return &JeopardyServer{JeopardyManager: um}
- }
- func (bs JeopardyServer) CreateJeopardy(ctx context.Context, jeopardy *gljeopardypb.Jeopardy) (*gljeopardypb.Jeopardy, error) {
- err := bs.JeopardyManager.Create(*jeopardy)
- if err != nil {
- return &gljeopardypb.Jeopardy{}, err
- }
- return jeopardy, nil
- }
- func (bs JeopardyServer) DeleteJeopardy(ctx context.Context, jeopardy *gljeopardypb.Jeopardy) (*gljeopardypb.Jeopardy, error) {
- bs.JeopardyManager.Remove(jeopardy.GetName())
- return jeopardy, nil
- }
- func (bs JeopardyServer) GetJeopardy(ctx context.Context, jeopardy *gljeopardypb.Jeopardy) (*gljeopardypb.Jeopardy, error) {
- retJeopardy := bs.JeopardyManager.Get(*jeopardy)
- if jeopardy.GetName() == retJeopardy.GetName() {
- return &retJeopardy, nil
- }
- return &gljeopardypb.Jeopardy{}, errors.New("Jeopardy not found")
- }
- func (bs JeopardyServer) ListJeopardy(jeopardy *gljeopardypb.Jeopardy, stream gljeopardypb.JeopardyService_ListJeopardyServer) error {
- jeopardys := bs.JeopardyManager.List()
- for _, jeopardy := range jeopardys {
- stream.Send(&jeopardy)
- }
- return nil
- }
- func (bs JeopardyServer) ModifyJeopardy(ctx context.Context, jeopardy *gljeopardypb.Jeopardy) (*gljeopardypb.Jeopardy, error) {
- return &gljeopardypb.Jeopardy{}, errors.New("jeopardy not found or password missmatch")
- }
|