MSP-1388 [+] тесты
This commit is contained in:
1 parent
9bd31bf6c9
commit
42d2dd18ac
22 files changed
+160
-700
No files matched your search
@@ -9,8 +9,8 @@ import (
|
||||
)
|
||||
|
||||
type LockerService interface {
|
||||
Lock(ctx context.Context, req domain.Request) (*domain.LockResponse, error)
|
||||
UnLock(ctx context.Context, req domain.Request) (*domain.LockResponse, error)
|
||||
Lock(ctx context.Context, req domain.LockRequest) (*domain.LockResponse, error)
|
||||
UnLock(ctx context.Context, req domain.UnLockRequest) (*domain.LockResponse, error)
|
||||
}
|
||||
|
||||
type Locker struct {
|
||||
@@ -22,13 +22,13 @@ type Locker struct {
|
||||
// @Tags locker
|
||||
// @Summary выставляем лок на строку
|
||||
// @Description `key` - строка для лока
|
||||
// @Description `ttl` - число секунд после которых блокировка снимется автоматически
|
||||
// @Description Возвращаем ключ для разблокировки
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} domain.LockResponse
|
||||
// @Failure 500 {object}
|
||||
// @Router /api/isp-lock-service/lock [POST]
|
||||
func (l Locker) Lock(ctx context.Context, req domain.Request) (*domain.LockResponse, error) {
|
||||
func (l Locker) Lock(ctx context.Context, req domain.LockRequest) (*domain.LockResponse, error) {
|
||||
l.logger.Debug(ctx, "call ctrl.Lock")
|
||||
return l.s.Lock(ctx, req)
|
||||
}
|
||||
@@ -40,10 +40,9 @@ func (l Locker) Lock(ctx context.Context, req domain.Request) (*domain.LockRespo
|
||||
// @Description `locKKey` - ключ для разблокировки, полученный из Lock
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} domain.LockResponse
|
||||
// @Failure 500 {object} {}
|
||||
// @Router /api/isp-lock-service/lock [POST]
|
||||
func (l Locker) UnLock(ctx context.Context, req domain.Request) (*domain.LockResponse, error) {
|
||||
// @Success 200
|
||||
// @Router /api/isp-lock-service/unlock [POST]
|
||||
func (l Locker) UnLock(ctx context.Context, req domain.UnLockRequest) (*domain.LockResponse, error) {
|
||||
l.logger.Debug(ctx, "call ctrl.UnLock")
|
||||
return l.s.UnLock(ctx, req)
|
||||
}
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
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