From 228b04e01d67d91a6568209c4fd75fbb7ad6d20b Mon Sep 17 00:00:00 2001 From: DeniskaRediska Date: Fri, 22 Apr 2022 17:07:19 +0400 Subject: [PATCH] MSP-623 add domain structs --- domain/access_list.go | 22 +++++++++++++++++++ domain/application.go | 36 ++++++++++++++++++++++++++++++ domain/common.go | 11 ++++++++++ domain/domain.go | 27 +++++++++++++++++++++++ domain/error.go | 18 +++++++++++++++ domain/request.go | 17 --------------- domain/response.go | 51 ------------------------------------------- domain/service.go | 28 ++++++++++++++++++++++++ domain/system.go | 5 +++++ domain/token.go | 22 +++++++++++++++++++ 10 files changed, 169 insertions(+), 68 deletions(-) create mode 100644 domain/access_list.go create mode 100644 domain/application.go create mode 100644 domain/common.go create mode 100644 domain/domain.go create mode 100644 domain/error.go delete mode 100644 domain/request.go delete mode 100644 domain/response.go create mode 100644 domain/service.go create mode 100644 domain/system.go create mode 100644 domain/token.go diff --git a/domain/access_list.go b/domain/access_list.go new file mode 100644 index 0000000..4d142d4 --- /dev/null +++ b/domain/access_list.go @@ -0,0 +1,22 @@ +package domain + +type AccessListSetOneRequest struct { + AppId int `valid:"required~Required"` + Method string `valid:"required~Required"` + Value bool +} + +type AccessListSetOneResponse struct { + Count int +} + +type AccessListSetListRequest struct { + AppId int `valid:"required~Required"` + RemoveOld bool + Methods []MethodInfo +} + +type MethodInfo struct { + Method string + Value bool +} diff --git a/domain/application.go b/domain/application.go new file mode 100644 index 0000000..2929ac5 --- /dev/null +++ b/domain/application.go @@ -0,0 +1,36 @@ +package domain + +import ( + "time" +) + +type Application struct { + Id int + Name string + Description string + ServiceId int + Type string + CreatedAt time.Time + UpdatedAt time.Time +} + +type ApplicationCreateUpdateRequest struct { + Id int + Name string `valid:"required~Required"` + Description string + ServiceId int `valid:"required~Required"` + Type string `valid:"required~Required,in(SYSTEM|MOBILE)"` +} + +type ApplicationWithTokens struct { + App Application + Tokens []Token +} + +type ApplicationSimple struct { + Id int + Name string + Description string + Type string + Tokens []Token +} diff --git a/domain/common.go b/domain/common.go new file mode 100644 index 0000000..4d068ed --- /dev/null +++ b/domain/common.go @@ -0,0 +1,11 @@ +package domain + +type ( + Identity struct { + Id int `valid:"required~Required"` + } + + DeleteResponse struct { + Deleted int + } +) diff --git a/domain/domain.go b/domain/domain.go new file mode 100644 index 0000000..06bd8e1 --- /dev/null +++ b/domain/domain.go @@ -0,0 +1,27 @@ +package domain + +import ( + "time" +) + +type DomainCreateUpdateRequest struct { + Id int + Name string `valid:"required~Required"` + Description string +} + +type Domain struct { + Id int + Name string + Description string + SystemId int + CreatedAt time.Time + UpdatedAt time.Time +} + +type DomainWithService struct { + Id int + Name string + Description string + Services []*ServiceWithApps +} diff --git a/domain/error.go b/domain/error.go new file mode 100644 index 0000000..f925295 --- /dev/null +++ b/domain/error.go @@ -0,0 +1,18 @@ +package domain + +import ( + "github.com/pkg/errors" +) + +var ( + ErrDomainNotFound = errors.New("domain not found") + ErrDomainDuplicateName = errors.New("domain name already exist") + + ErrServiceNotFound = errors.New("service not found") + ErrServiceDuplicateName = errors.New("service name already exist") + + ErrSystemNotFound = errors.New("system not found") + + ErrApplicationNotFound = errors.New("application not found") + ErrApplicationDuplicateName = errors.New("application name already exist") +) diff --git a/domain/request.go b/domain/request.go deleted file mode 100644 index 43ed38e..0000000 --- a/domain/request.go +++ /dev/null @@ -1,17 +0,0 @@ -package domain - -type ( - Identity struct { - Id int32 `json:"id" valid:"required~Required"` - } - - RevokeTokensRequest struct { - AppId int32 `valid:"required~Required"` - Tokens []string - } - - CreateTokenRequest struct { - AppId int32 `valid:"required~Required"` - ExpireTimeMs int64 - } -) diff --git a/domain/response.go b/domain/response.go deleted file mode 100644 index 6f55d41..0000000 --- a/domain/response.go +++ /dev/null @@ -1,51 +0,0 @@ -package domain - -import "isp-system-service/entity" - -type ( - DeleteResponse struct { - Deleted int - } - - CountResponse struct { - Count int - } - - AppWithToken struct { - App entity.Application - Tokens []entity.Token - } - - DomainWithServices struct { - Id int32 - Name string - Description string - Services []*ServiceWithApps - } - - ServiceWithApps struct { - Id int32 - Name string - Description string - Apps []*SimpleApp - } - - SimpleApp struct { - Id int32 - Name string - Description string - Type string - Tokens []entity.Token - } - - MethodInfo struct { - Method string - Value bool - } - - SetListRequest struct { - AppId int32 - RemoveOld bool - Methods []MethodInfo - } -) diff --git a/domain/service.go b/domain/service.go new file mode 100644 index 0000000..5884c50 --- /dev/null +++ b/domain/service.go @@ -0,0 +1,28 @@ +package domain + +import ( + "time" +) + +type Service struct { + Id int + Name string + Description string + DomainId int + CreatedAt time.Time + UpdatedAt time.Time +} + +type ServiceCreateUpdateRequest struct { + Id int + Name string `valid:"required~Required"` + Description string + DomainId int `valid:"required~Required"` +} + +type ServiceWithApps struct { + Id int + Name string + Description string + Apps []*ApplicationSimple +} diff --git a/domain/system.go b/domain/system.go new file mode 100644 index 0000000..7fa0aea --- /dev/null +++ b/domain/system.go @@ -0,0 +1,5 @@ +package domain + +const ( + DefaultSystemId = 1 +) diff --git a/domain/token.go b/domain/token.go new file mode 100644 index 0000000..f6bf6f1 --- /dev/null +++ b/domain/token.go @@ -0,0 +1,22 @@ +package domain + +import ( + "time" +) + +type Token struct { + Token string + AppId int + ExpireTime int + CreatedAt time.Time +} + +type TokenRevokeRequest struct { + AppId int `valid:"required~Required"` + Tokens []string +} + +type TokenCreateRequest struct { + AppId int `valid:"required~Required"` + ExpireTimeMs int +}