diff --git a/domain/auth.go b/domain/auth.go new file mode 100644 index 0000000..8db055a --- /dev/null +++ b/domain/auth.go @@ -0,0 +1,18 @@ +package domain + +const AdminAuthHeaderName = "x-auth-admin" + +type Auth struct { + Token string + Expired string `json:",omitempty"` + HeaderName string +} + +type AuthRequest struct { + Email string `valid:"required"` + Password string ` valid:"required"` +} + +type SudirAuthRequest struct { + AuthCode string `valid:"required"` +} diff --git a/domain/errors.go b/domain/errors.go new file mode 100644 index 0000000..9a326a2 --- /dev/null +++ b/domain/errors.go @@ -0,0 +1,14 @@ +package domain + +import ( + "github.com/pkg/errors" +) + +var ( + ErrNotFound = errors.New("not found") + ErrUnauthenticated = errors.New("authentication failure") + ErrSudirAuthorization = errors.New("User is authorized only with SUDIR") + ErrSudirAuthIsMissed = errors.New("SUDIR authorization is not configured on the server") + ErrInvalid = errors.New("entity is invalid") + ErrAlreadyExists = errors.New("already exists") +) diff --git a/domain/grpc_error.go b/domain/grpc_error.go new file mode 100644 index 0000000..7bb2cfa --- /dev/null +++ b/domain/grpc_error.go @@ -0,0 +1,7 @@ +package domain + +type GrpcError struct { + ErrorMessage string `json:"errorMessage"` + ErrorCode string `json:"errorCode"` + Details []interface{} `json:"details"` +} diff --git a/domain/user.go b/domain/user.go new file mode 100644 index 0000000..7937a33 --- /dev/null +++ b/domain/user.go @@ -0,0 +1,60 @@ +package domain + +import ( + "time" +) + +type User struct { + SudirUserId *string `json:",omitempty"` + Id int64 + RoleId int + FirstName string + LastName string + Email string + Password string `json:",omitempty"` + UpdatedAt time.Time + CreatedAt time.Time +} + +type UsersResponse struct { + Items []User +} + +type UsersRequest struct { + Ids []int64 + Offset int + Limit int + Email string +} + +type AdminUserShort struct { + FirstName string + LastName string + Email string `valid:"required"` + Role string +} + +type CreateUserRequest struct { + RoleId int + FirstName string + LastName string + Email string `valid:"required"` + Password string `valid:"required"` +} + +type UpdateUserRequest struct { + Id int64 `valid:"required"` + RoleId int + FirstName string + LastName string + Email string + Password string +} + +type DeleteResponse struct { + Deleted int +} + +type IdentitiesRequest struct { + Ids []int64 `valid:"required"` +} diff --git a/structure/auth.go b/structure/auth.go deleted file mode 100644 index a3ff4fd..0000000 --- a/structure/auth.go +++ /dev/null @@ -1,16 +0,0 @@ -package structure - -type Auth struct { - Token string `json:"token"` - Expired string `json:"expired,omitempty"` - HeaderName string `json:"headerName"` -} - -type AuthRequest struct { - Email string `json:"email" valid:"required~Required"` - Password string `json:"password" valid:"required~Required"` -} - -type SudirAuthRequest struct { - AuthCode string `json:"authCode" valid:"required~Required"` -} diff --git a/structure/request.go b/structure/request.go deleted file mode 100644 index d494902..0000000 --- a/structure/request.go +++ /dev/null @@ -1,5 +0,0 @@ -package structure - -type IdentitiesRequest struct { - Ids []int64 `json:"ids"` -} diff --git a/structure/response.go b/structure/response.go deleted file mode 100644 index 99bba1c..0000000 --- a/structure/response.go +++ /dev/null @@ -1,5 +0,0 @@ -package structure - -type DeleteResponse struct { - Deleted int -} diff --git a/structure/user.go b/structure/user.go deleted file mode 100644 index cb55668..0000000 --- a/structure/user.go +++ /dev/null @@ -1,26 +0,0 @@ -package structure - -import ( - "msp-admin-service/entity" -) - -type UsersResponse struct { - Items *[]entity.AdminUser `json:"items,omitempty"` -} - -type UsersRequest struct { - Ids []int64 `json:"ids"` - Offset int `json:"offset"` - Limit int `json:"limit"` - Email string `json:"email"` - Phone string `json:"phone"` -} - -type AdminUserShort struct { - Image string `json:"image"` - FirstName string `json:"firstName"` - LastName string `json:"lastName"` - Email string `json:"email" valid:"required~Required"` - Phone string `json:"phone"` - Role string `json:"role"` -}