[init]
This commit is contained in:
1 parent
0a91198eb6
commit
02f37d7426
31 files changed
+1995
No files matched your search
@@ -0,0 +1,29 @@
|
||||
package controller
|
||||
|
||||
type LockerService interface {
|
||||
// All(ctx context.Context) ([]domain.Locker, error)
|
||||
// Get(ctx context.Context, id int) (*domain.Locker, error)
|
||||
}
|
||||
|
||||
type Locker struct {
|
||||
s LockerService
|
||||
}
|
||||
|
||||
func NewLocker(s LockerService) Locker {
|
||||
return Locker{
|
||||
s: s,
|
||||
}
|
||||
}
|
||||
|
||||
// All
|
||||
// @Tags object
|
||||
// @Summary Получить все объекты
|
||||
// @Description Возвращает список объектов
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {array} domain.Locker
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /object/all [POST]
|
||||
// func (c Locker) All(ctx context.Context) ([]domain.Locker, error) {
|
||||
// return c.s.All(ctx)
|
||||
// }
|
||||
@@ -0,0 +1,61 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"isp-lock-service/domain"
|
||||
"isp-lock-service/entity"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
type ObjectService interface {
|
||||
All(ctx context.Context) ([]domain.Object, error)
|
||||
Get(ctx context.Context, id int) (*domain.Object, error)
|
||||
}
|
||||
|
||||
type Object struct {
|
||||
s ObjectService
|
||||
}
|
||||
|
||||
func NewObject(s ObjectService) Object {
|
||||
return Object{
|
||||
s: s,
|
||||
}
|
||||
}
|
||||
|
||||
// All
|
||||
// @Tags object
|
||||
// @Summary Получить все объекты
|
||||
// @Description Возвращает список объектов
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {array} domain.Object
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /object/all [POST]
|
||||
func (c Object) All(ctx context.Context) ([]domain.Object, error) {
|
||||
return c.s.All(ctx)
|
||||
}
|
||||
|
||||
// GetById
|
||||
// @Tags object
|
||||
// @Summary Получить объект по его идентификатору
|
||||
// @Description Возвращает объект
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.ByIdRequest true "Идентификатор объекта"
|
||||
// @Success 200 {object} domain.Object
|
||||
// @Failure 404 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /object/get_by_id [POST]
|
||||
func (c Object) GetById(ctx context.Context, req domain.ByIdRequest) (*domain.Object, error) {
|
||||
d, err := c.s.Get(ctx, req.Id)
|
||||
switch {
|
||||
case errors.Is(err, entity.ErrObjectNotFound):
|
||||
return nil, status.Errorf(codes.NotFound, "object by id '%d' not found", req.Id)
|
||||
default:
|
||||
return d, err
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user