add(document generation)
This commit is contained in:
1 parent
ff84d68b72
commit
9f76e76e55
9 files changed
+279
-20
No files matched your search
@@ -5,12 +5,23 @@ import (
|
||||
"isp-system-service/model"
|
||||
|
||||
"github.com/integration-system/isp-lib/database"
|
||||
_ "github.com/integration-system/isp-lib/structure"
|
||||
"github.com/integration-system/isp-lib/utils"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// GetApplications godoc
|
||||
// @Tags application
|
||||
// @Summary Получить список приложений
|
||||
// @Description Возвращает массив приложений с токенами по их идентификаторам
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body []integer false "Массив идентификаторов приложений"
|
||||
// @Success 200 {array} controller.AppWithToken
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /application/get_applications [POST]
|
||||
func GetApplications(list []int32) ([]*AppWithToken, error) {
|
||||
res, err := model.AppRep.GetApplications(list)
|
||||
if err != nil {
|
||||
@@ -19,6 +30,16 @@ func GetApplications(list []int32) ([]*AppWithToken, error) {
|
||||
return enrichWithTokens(res...)
|
||||
}
|
||||
|
||||
// GetApplicationsByServiceId godoc
|
||||
// @Tags application
|
||||
// @Summary Получить список приложений по идентификатору сервиса
|
||||
// @Description Возвращает список приложений по запрошенныму идентификатору сервиса
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body controller.Identity true "Идентификатор серсиса"
|
||||
// @Success 200 {array} controller.AppWithToken
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /application/get_applications_by_service_id [POST]
|
||||
func GetApplicationsByServiceId(identity Identity) ([]*AppWithToken, error) {
|
||||
arr, err := model.AppRep.GetApplicationsByServiceId(identity.Id)
|
||||
if err != nil {
|
||||
@@ -27,6 +48,19 @@ func GetApplicationsByServiceId(identity Identity) ([]*AppWithToken, error) {
|
||||
return enrichWithTokens(arr...)
|
||||
}
|
||||
|
||||
// CreateUpdateApplication godoc
|
||||
// @Tags application
|
||||
// @Summary Создать/обновить приложение
|
||||
// @Description Если приложение с такими идентификатором существует, то обновляет данные, если нет, то добавляет данные в базу
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body entity.Application true "Объект приложения"
|
||||
// @Success 200 {object} controller.AppWithToken
|
||||
// @Failure 400 {object} structure.GrpcError
|
||||
// @Failure 404 {object} structure.GrpcError
|
||||
// @Failure 409 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /application/create_update_application [POST]
|
||||
func CreateUpdateApplication(app entity.Application) (*AppWithToken, error) {
|
||||
existed, err := model.AppRep.GetApplicationByNameAndServiceId(app.Name, app.ServiceId)
|
||||
if err != nil {
|
||||
@@ -69,6 +103,18 @@ func CreateUpdateApplication(app entity.Application) (*AppWithToken, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// GetApplicationById godoc
|
||||
// @Tags application
|
||||
// @Summary Получить приложение по идентификатору
|
||||
// @Description Возвращает описание приложения по его идентификатору
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body controller.Identity true "Идентификатор приложения"
|
||||
// @Success 200 {object} controller.AppWithToken
|
||||
// @Failure 400 {object} structure.GrpcError
|
||||
// @Failure 404 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /application/get_application_by_id [POST]
|
||||
func GetApplicationById(identity Identity) (*AppWithToken, error) {
|
||||
application, err := model.AppRep.GetApplicationById(identity.Id)
|
||||
if err != nil {
|
||||
@@ -84,6 +130,17 @@ func GetApplicationById(identity Identity) (*AppWithToken, error) {
|
||||
return arr[0], nil
|
||||
}
|
||||
|
||||
// DeleteApplications godoc
|
||||
// @Tags application
|
||||
// @Summary Удалить приложения
|
||||
// @Description Удаляет приложения по списку их идентификаторов, возвращает количество удаленных приложений
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body []integer false "Массив идентификаторов приложений"
|
||||
// @Success 200 {object} controller.AppWithToken
|
||||
// @Failure 400 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /application/delete_applications [POST]
|
||||
func DeleteApplications(list []int32) (DeleteResponse, error) {
|
||||
if len(list) == 0 {
|
||||
return DeleteResponse{}, status.Errorf(codes.InvalidArgument, "At least one id are required")
|
||||
@@ -109,6 +166,15 @@ func DeleteApplications(list []int32) (DeleteResponse, error) {
|
||||
return DeleteResponse{Deleted: count}, nil
|
||||
}
|
||||
|
||||
// GetSystemTree godoc
|
||||
// @Tags application
|
||||
// @Summary Метод получения системного дерева
|
||||
// @Description Возвращает описание взаимосвязей сервисов и приложений
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {array} controller.DomainWithServices
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /application/get_system_tree [POST]
|
||||
func GetSystemTree(md metadata.MD) ([]*DomainWithServices, error) {
|
||||
sysId, err := utils.ResolveMetadataIdentity(utils.SystemIdHeader, md)
|
||||
if err != nil {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"isp-system-service/entity"
|
||||
"isp-system-service/model"
|
||||
|
||||
_ "github.com/integration-system/isp-lib/structure"
|
||||
"github.com/integration-system/isp-lib/utils"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/metadata"
|
||||
@@ -18,6 +19,16 @@ import (
|
||||
return res, nil
|
||||
}*/
|
||||
|
||||
// GetDomainsBySystemId godoc
|
||||
// @Tags domain
|
||||
// @Summary Получить домены по идентификатору системы
|
||||
// @Description Возвращает список доменов по системному идентификатору
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body integer false "Идентификатор системы"
|
||||
// @Success 200 {array} entity.Domain
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /domain/get_domains_by_system_id [POST]
|
||||
func GetDomainsBySystemId(md metadata.MD) ([]entity.Domain, error) {
|
||||
sysId, err := utils.ResolveMetadataIdentity(utils.SystemIdHeader, md)
|
||||
if err != nil {
|
||||
@@ -26,6 +37,16 @@ func GetDomainsBySystemId(md metadata.MD) ([]entity.Domain, error) {
|
||||
return model.DomainRep.GetDomainsBySystemId(int32(sysId))
|
||||
}
|
||||
|
||||
// CreateUpdateDomain godoc
|
||||
// @Tags domain
|
||||
// @Summary Создать/обновить домен
|
||||
// @Description Если домен с такими идентификатором существует, то обновляет данные, если нет, то добавляет данные в базу
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body entity.Domain true "Объект домена"
|
||||
// @Success 200 {object} entity.Domain
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /domain/create_update_domain [POST]
|
||||
func CreateUpdateDomain(domain entity.Domain, md metadata.MD) (*entity.Domain, error) {
|
||||
existed, err := model.DomainRep.GetDomainByNameAndSystemId(domain.Name, domain.SystemId)
|
||||
if err != nil {
|
||||
@@ -67,6 +88,17 @@ func CreateUpdateDomain(domain entity.Domain, md metadata.MD) (*entity.Domain, e
|
||||
}
|
||||
}
|
||||
|
||||
// GetDomainById godoc
|
||||
// @Tags domain
|
||||
// @Summary Получить домен по идентификатору
|
||||
// @Description Возвращает описание домена по его идентификатору
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body controller.Identity true "Идентификатор домена"
|
||||
// @Success 200 {object} entity.Domain
|
||||
// @Failure 404 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /domain/get_domain_by_id [POST]
|
||||
func GetDomainById(identity Identity) (*entity.Domain, error) {
|
||||
domain, err := model.DomainRep.GetDomainById(identity.Id)
|
||||
if err != nil {
|
||||
@@ -78,6 +110,17 @@ func GetDomainById(identity Identity) (*entity.Domain, error) {
|
||||
return domain, err
|
||||
}
|
||||
|
||||
// DeleteDomains godoc
|
||||
// @Tags domain
|
||||
// @Summary Удаление доменов
|
||||
// @Description Удаляет домены по списку их идентификаторов, возвращает количество удаленных доменов
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body []integer false "Массив идентификаторов доменов"
|
||||
// @Success 200 {object} controller.DeleteResponse
|
||||
// @Failure 400 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /domain/delete_domains [POST]
|
||||
func DeleteDomains(list []int32) (DeleteResponse, error) {
|
||||
if len(list) == 0 {
|
||||
return DeleteResponse{Deleted: 0}, status.Errorf(codes.InvalidArgument, "At least one id are required")
|
||||
|
||||
@@ -8,6 +8,16 @@ import (
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// GetService godoc
|
||||
// @Tags service
|
||||
// @Summary Получить список сервисов
|
||||
// @Description Возвращает список сервисов по их идентификаторам
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body []integer false "Массив идентификаторов сервисов"
|
||||
// @Success 200 {array} entity.Service
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /service/get_service [POST]
|
||||
func GetService(list []int32) ([]entity.Service, error) {
|
||||
res, err := model.ServiceRep.GetServices(list)
|
||||
if err != nil {
|
||||
@@ -16,10 +26,33 @@ func GetService(list []int32) ([]entity.Service, error) {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// GetServicesByDomainId godoc
|
||||
// @Tags service
|
||||
// @Summary Получить список сервисов по идентификатору домена
|
||||
// @Description Возвращает список сервисов по идентификатору домена
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body controller.Identity true "Идентификатор домена"
|
||||
// @Success 200 {array} entity.Service
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /service/get_services_by_domain_id [POST]
|
||||
func GetServicesByDomainId(identity Identity) ([]entity.Service, error) {
|
||||
return model.ServiceRep.GetServicesByDomainId(identity.Id)
|
||||
}
|
||||
|
||||
// CreateUpdateService godoc
|
||||
// @Tags service
|
||||
// @Summary Создать/обновить сервис
|
||||
// @Description Если сервис с такими идентификатором существует, то обновляет данные, если нет, то добавляет данные в базу
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body entity.Service true "Объект сервиса"
|
||||
// @Success 200 {object} entity.Service
|
||||
// @Failure 400 {object} structure.GrpcError
|
||||
// @Failure 404 {object} structure.GrpcError
|
||||
// @Failure 409 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /service/create_update_service [POST]
|
||||
func CreateUpdateService(service entity.Service) (*entity.Service, error) {
|
||||
existed, err := model.ServiceRep.GetServiceByNameAndDomainId(service.Name, service.DomainId)
|
||||
if err != nil {
|
||||
@@ -54,6 +87,17 @@ func CreateUpdateService(service entity.Service) (*entity.Service, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// GetServiceById godoc
|
||||
// @Tags service
|
||||
// @Summary Получить сервис по идентификатору
|
||||
// @Description Возвращает описание сервиса по его идентификатору
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body controller.Identity true "Идентификатор сервиса"
|
||||
// @Success 200 {object} entity.Service
|
||||
// @Failure 404 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /service/get_service_by_id [POST]
|
||||
func GetServiceById(identity Identity) (*entity.Service, error) {
|
||||
service, err := model.ServiceRep.GetServiceById(identity.Id)
|
||||
if err != nil {
|
||||
@@ -65,6 +109,17 @@ func GetServiceById(identity Identity) (*entity.Service, error) {
|
||||
return service, err
|
||||
}
|
||||
|
||||
// DeleteService godoc
|
||||
// @Tags service
|
||||
// @Summary Удалить сервисы
|
||||
// @Description Удаляет сервисов по списку их идентификаторов, возвращает количество удаленных сервисов
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body []integer true "Массив идентификаторов сервисов"
|
||||
// @Success 200 {object} controller.DeleteResponse
|
||||
// @Failure 400 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /service/delete_service [POST]
|
||||
func DeleteService(list []int32) (DeleteResponse, error) {
|
||||
if len(list) == 0 {
|
||||
return DeleteResponse{Deleted: 0}, status.Error(codes.InvalidArgument, "At least one id are required")
|
||||
|
||||
@@ -3,6 +3,7 @@ package controller
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
_ "github.com/integration-system/isp-lib/structure"
|
||||
"isp-system-service/entity"
|
||||
"isp-system-service/model"
|
||||
|
||||
@@ -10,6 +11,16 @@ import (
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// GetSystems godoc
|
||||
// @Tags system
|
||||
// @Summary Получить список систем
|
||||
// @Description Возвращает список систем по их идентификаторам
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body []integer false "Массив идентификаторов систем"
|
||||
// @Success 200 {array} entity.System
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /system/get_systems [POST]
|
||||
func GetSystems(list []int32) ([]entity.System, error) {
|
||||
res, err := model.SystemRep.GetSystems(list)
|
||||
if err != nil {
|
||||
@@ -18,6 +29,18 @@ func GetSystems(list []int32) ([]entity.System, error) {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
// CreateUpdateSystem godoc
|
||||
// @Tags system
|
||||
// @Summary Создать/обновить систему
|
||||
// @Description Если система с такими идентификатором существует, то обновляет данные, если нет, то добавляет данные в базу
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body entity.System true "Объект системы"
|
||||
// @Success 200 {object} entity.System
|
||||
// @Failure 404 {object} structure.GrpcError
|
||||
// @Failure 409 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /system/create_update_system [POST]
|
||||
func CreateUpdateSystem(system entity.System) (*entity.System, error) {
|
||||
existed, err := model.SystemRep.GetSystemByName(system.Name)
|
||||
if err != nil {
|
||||
@@ -45,6 +68,17 @@ func CreateUpdateSystem(system entity.System) (*entity.System, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// GetSystemById godoc
|
||||
// @Tags system
|
||||
// @Summary Получить систему по идентификатору
|
||||
// @Description Возвращает описание системы по ее идентификатору
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body controller.Identity true "Идентификатор системы"
|
||||
// @Success 200 {object} entity.System
|
||||
// @Failure 404 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /system/get_system_by_id [POST]
|
||||
func GetSystemById(identity Identity) (*entity.System, error) {
|
||||
sys, err := model.SystemRep.GetSystemById(identity.Id)
|
||||
if err != nil {
|
||||
@@ -56,6 +90,17 @@ func GetSystemById(identity Identity) (*entity.System, error) {
|
||||
return sys, err
|
||||
}
|
||||
|
||||
// DeleteSystems godoc
|
||||
// @Tags system
|
||||
// @Summary Удалить системы
|
||||
// @Description Удаляет системы по списку их идентификаторов, возвращает количество удаленных систем
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body []integer false "Массив идентификаторов систем"
|
||||
// @Success 200 {object} controller.DeleteResponse
|
||||
// @Failure 400 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /system/delete_systems [POST]
|
||||
func DeleteSystems(list []int32) (DeleteResponse, error) {
|
||||
if len(list) == 0 {
|
||||
return DeleteResponse{}, status.Error(codes.InvalidArgument, "At least one id are required")
|
||||
|
||||
@@ -31,6 +31,16 @@ type BoolResponse struct {
|
||||
Ok bool
|
||||
}
|
||||
|
||||
// CreateToken godoc
|
||||
// @Tags token
|
||||
// @Summary Создать токен
|
||||
// @Description Созддает токен и привязывает его к приложению
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body controller.CreateTokenRequest true "Объект создания токена"
|
||||
// @Success 200 {object} controller.AppWithToken
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /token/create_token [POST]
|
||||
func CreateToken(req CreateTokenRequest) (*AppWithToken, error) {
|
||||
m, err, app := GetIdMap(req.AppId)
|
||||
if err != nil {
|
||||
@@ -81,6 +91,16 @@ func CreateToken(req CreateTokenRequest) (*AppWithToken, error) {
|
||||
return arr[0], nil
|
||||
}
|
||||
|
||||
// RevokeTokens godoc
|
||||
// @Tags token
|
||||
// @Summary Отозвать токены
|
||||
// @Description Отвязывает токены от приложений и удялет их
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body controller.RevokeTokensRequest true "Объект отзыва токенов"
|
||||
// @Success 200 {object} controller.AppWithToken
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /token/revoke_tokens [POST]
|
||||
func RevokeTokens(req RevokeTokensRequest) (*AppWithToken, error) {
|
||||
app, err := model.AppRep.GetApplicationById(req.AppId)
|
||||
if err != nil {
|
||||
@@ -97,10 +117,30 @@ func RevokeTokens(req RevokeTokensRequest) (*AppWithToken, error) {
|
||||
return res[0], nil
|
||||
}
|
||||
|
||||
// RevokeTokensForApp godoc
|
||||
// @Tags token
|
||||
// @Summary Отозвать токены для приложения
|
||||
// @Description Отвязывает токены от приложений и удаляет их по идентификатору приложения
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body controller.Identity true "Идентификатор приложения"
|
||||
// @Success 200 {object} controller.DeleteResponse
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /token/revoke_tokens_for_app [POST]
|
||||
func RevokeTokensForApp(identity Identity) (*DeleteResponse, error) {
|
||||
return revokeTokensForApp(identity, &model.TokenRep)
|
||||
}
|
||||
|
||||
// GetTokensByAppId godoc
|
||||
// @Tags token
|
||||
// @Summary Получить токены по идентификаотру приложения
|
||||
// @Description Возвращает список токенов, привязанных к приложению
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body controller.Identity true "Идентификатор приложения"
|
||||
// @Success 200 {array} entity.Token
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /token/get_tokens_by_app_id [POST]
|
||||
func GetTokensByAppId(identity Identity) ([]entity.Token, error) {
|
||||
return model.TokenRep.GetTokensByAppId(identity.Id)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user