Implement api
This commit is contained in:
1 parent
c6148a1c1c
commit
cddd3383e8
10 files changed
+334
-24
No files matched your search
@@ -3,7 +3,10 @@ package api
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/txix-open/isp-kit/grpc/apierrors"
|
||||
"isp-config-service/domain"
|
||||
"isp-config-service/entity"
|
||||
)
|
||||
|
||||
type ConfigSchemaService interface {
|
||||
@@ -28,9 +31,21 @@ func NewConfigSchema(service ConfigSchemaService) ConfigSchema {
|
||||
// @Produce json
|
||||
// @Param body body domain.GetByModuleIdRequest true "идентификатор модуля"
|
||||
// @Success 200 {object} domain.ConfigSchema
|
||||
// @Failure 404 {object} apierrors.Error "если схема для модуля не найдена"
|
||||
// @Failure 400 {object} apierrors.Error "`errorCode: 2005` - схема для модуля не найдена"
|
||||
// @Failure 500 {object} apierrors.Error
|
||||
// @Router /schema/get_by_module_id [POST]
|
||||
func (c ConfigSchema) SchemaByModuleId(ctx context.Context, request domain.GetByModuleIdRequest) (*domain.ConfigSchema, error) {
|
||||
|
||||
schema, err := c.service.SchemaByModuleId(ctx, request.ModuleId)
|
||||
switch {
|
||||
case errors.Is(err, entity.ErrSchemaNotFound):
|
||||
return nil, apierrors.NewBusinessError(
|
||||
domain.ErrorCodeSchemaNotFound,
|
||||
"config schema not found",
|
||||
err,
|
||||
)
|
||||
case err != nil:
|
||||
return nil, apierrors.NewInternalServiceError(err)
|
||||
default:
|
||||
return schema, nil
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user