From 89f4eea28058de2d72776c04a400210a0096b89b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B8=D0=BD=D0=B5=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA=20?= =?UTF-8?q?=D0=A2=D0=B8=D0=BC=D1=83=D1=80=20=D0=A0=D0=BE=D0=BC=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=B8=D1=87?= Date: Tue, 1 Apr 2025 19:39:14 +0300 Subject: [PATCH] MSP-5186 Implement application next id endpoint --- controller/application.go | 14 ++++++++++++++ docs/swagger.yaml | 19 +++++++++++++++++++ routes/routes.go | 5 +++++ service/application.go | 8 ++++++++ 4 files changed, 46 insertions(+) diff --git a/controller/application.go b/controller/application.go index b3f28a3..c2defca 100644 --- a/controller/application.go +++ b/controller/application.go @@ -17,6 +17,7 @@ type ApplicationService interface { SystemTree(ctx context.Context, systemId int) ([]*domain.DomainWithService, error) CreateUpdate(ctx context.Context, req domain.ApplicationCreateUpdateRequest) (*domain.ApplicationWithTokens, error) Delete(ctx context.Context, idList []int) (int, error) + NextId(ctx context.Context) (int, error) } type Application struct { @@ -148,3 +149,16 @@ func (c Application) Delete(ctx context.Context, req []int) (*domain.DeleteRespo Deleted: result, }, nil } + +// NextId godoc +// @Tags application +// @Summary Получить следующий идентификатор приложения +// @Description Возвращает следующий идентификатор приложения +// @Accept json +// @Produce json +// @Success 200 {object} integer +// @Failure 500 {object} domain.GrpcError +// @Router /application/next_id [POST] +func (c Application) NextId(ctx context.Context) (int, error) { + return c.service.NextId(ctx) +} diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 82295fe..db4b8c9 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -571,6 +571,25 @@ paths: summary: Метод получения системного дерева tags: - application + /application/next_id: + post: + consumes: + - application/json + description: Возвращает следующий идентификатор приложения + produces: + - application/json + responses: + "200": + description: OK + schema: + type: integer + "500": + description: Internal Server Error + schema: + $ref: '#/definitions/domain.GrpcError' + summary: Получить следующий идентификатор приложения + tags: + - application /domain/create_update_domain: post: consumes: diff --git a/routes/routes.go b/routes/routes.go index ec6b2ae..9c886ef 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -161,6 +161,11 @@ func applicationCluster(c Controllers) []cluster.EndpointDescriptor { Inner: true, Handler: c.Application.GetSystemTree, }, + { + Path: "system/application/next_id", + Inner: true, + Handler: c.Application.NextId, + }, } } diff --git a/service/application.go b/service/application.go index 4e3abdb..ed2e31f 100644 --- a/service/application.go +++ b/service/application.go @@ -256,6 +256,14 @@ func (s Application) EnrichWithTokens(ctx context.Context, apps []entity.Applica return result, nil } +func (s Application) NextId(ctx context.Context) (int, error) { + nextId, err := s.appRepo.NextApplicationId(ctx) + if err != nil { + return 0, errors.WithMessage(err, "get next application id") + } + return nextId, nil +} + func (s Application) convertApplication(req entity.Application) domain.Application { desc := "" if req.Description != nil {