Init Eslogad
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package contract
|
||||
|
||||
import "time"
|
||||
|
||||
type ErrorResponse struct {
|
||||
Error string `json:"error"`
|
||||
Message string `json:"message"`
|
||||
Details map[string]interface{} `json:"details,omitempty"`
|
||||
Code int `json:"code"`
|
||||
}
|
||||
|
||||
type ValidationErrorResponse struct {
|
||||
Error string `json:"error"`
|
||||
Message string `json:"message"`
|
||||
Details map[string]string `json:"details"`
|
||||
Code int `json:"code"`
|
||||
}
|
||||
|
||||
type SuccessResponse struct {
|
||||
Message string `json:"message"`
|
||||
Data interface{} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type PaginationRequest struct {
|
||||
Page int `json:"page" validate:"min=1"`
|
||||
Limit int `json:"limit" validate:"min=1,max=100"`
|
||||
}
|
||||
|
||||
type PaginationResponse struct {
|
||||
TotalCount int `json:"total_count"`
|
||||
Page int `json:"page"`
|
||||
Limit int `json:"limit"`
|
||||
TotalPages int `json:"total_pages"`
|
||||
}
|
||||
|
||||
type SearchRequest struct {
|
||||
Query string `json:"query,omitempty"`
|
||||
}
|
||||
|
||||
type DateRangeRequest struct {
|
||||
From *time.Time `json:"from,omitempty"`
|
||||
To *time.Time `json:"to,omitempty"`
|
||||
}
|
||||
|
||||
type HealthResponse struct {
|
||||
Status string `json:"status"`
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package contract
|
||||
|
||||
type Response struct {
|
||||
Success bool `json:"success"`
|
||||
Data interface{} `json:"data"`
|
||||
Errors []*ResponseError `json:"errors"`
|
||||
}
|
||||
|
||||
func (r *Response) GetSuccess() bool {
|
||||
return r.Success
|
||||
}
|
||||
|
||||
func (r *Response) GetData() interface{} {
|
||||
return r.Data
|
||||
}
|
||||
|
||||
func (r *Response) GetErrors() []*ResponseError {
|
||||
return r.Errors
|
||||
}
|
||||
|
||||
func BuildSuccessResponse(data interface{}) *Response {
|
||||
return &Response{
|
||||
Success: true,
|
||||
Data: data,
|
||||
Errors: []*ResponseError(nil),
|
||||
}
|
||||
}
|
||||
|
||||
func BuildErrorResponse(errorList []*ResponseError) *Response {
|
||||
return &Response{
|
||||
Success: false,
|
||||
Data: nil,
|
||||
Errors: errorList,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Response) HasErrors() bool {
|
||||
return r.GetErrors() != nil && len(r.GetErrors()) > 0
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package contract
|
||||
|
||||
import "fmt"
|
||||
|
||||
type ResponseError struct {
|
||||
Code string `json:"code"`
|
||||
Entity string `json:"entity"`
|
||||
Cause string `json:"cause"`
|
||||
}
|
||||
|
||||
func NewResponseError(code, entity, cause string) *ResponseError {
|
||||
return &ResponseError{
|
||||
Code: code,
|
||||
Cause: cause,
|
||||
Entity: entity,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *ResponseError) GetCode() string {
|
||||
return e.Code
|
||||
}
|
||||
|
||||
func (e *ResponseError) GetEntity() string {
|
||||
return e.Entity
|
||||
}
|
||||
|
||||
func (e *ResponseError) GetCause() string {
|
||||
return e.Cause
|
||||
}
|
||||
|
||||
func (e *ResponseError) Error() string {
|
||||
return fmt.Sprintf("%s: %s: %s", e.GetCode(), e.GetEntity(), e.GetCause())
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package contract
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type CreateUserRequest struct {
|
||||
OrganizationID uuid.UUID `json:"organization_id" validate:"required"`
|
||||
OutletID *uuid.UUID `json:"outlet_id,omitempty"`
|
||||
Name string `json:"name" validate:"required,min=1,max=255"`
|
||||
Email string `json:"email" validate:"required,email"`
|
||||
Password string `json:"password" validate:"required,min=6"`
|
||||
Role string `json:"role" validate:"required,oneof=admin manager cashier waiter"`
|
||||
Permissions map[string]interface{} `json:"permissions,omitempty"`
|
||||
}
|
||||
|
||||
type UpdateUserRequest struct {
|
||||
Name *string `json:"name,omitempty" validate:"omitempty,min=1,max=255"`
|
||||
Email *string `json:"email,omitempty" validate:"omitempty,email"`
|
||||
Role *string `json:"role,omitempty" validate:"omitempty,oneof=admin manager cashier waiter"`
|
||||
IsActive *bool `json:"is_active,omitempty"`
|
||||
Permissions *map[string]interface{} `json:"permissions,omitempty"`
|
||||
}
|
||||
|
||||
type ChangePasswordRequest struct {
|
||||
CurrentPassword string `json:"current_password" validate:"required"`
|
||||
NewPassword string `json:"new_password" validate:"required,min=6"`
|
||||
}
|
||||
|
||||
type UpdateUserOutletRequest struct {
|
||||
OutletID uuid.UUID `json:"outlet_id" validate:"required"`
|
||||
}
|
||||
|
||||
type LoginRequest struct {
|
||||
Email string `json:"email" validate:"required,email"`
|
||||
Password string `json:"password" validate:"required"`
|
||||
}
|
||||
|
||||
type LoginResponse struct {
|
||||
Token string `json:"token"`
|
||||
ExpiresAt time.Time `json:"expires_at"`
|
||||
User UserResponse `json:"user"`
|
||||
Roles []RoleResponse `json:"roles"`
|
||||
Permissions []string `json:"permissions"`
|
||||
Positions []PositionResponse `json:"positions"`
|
||||
}
|
||||
|
||||
type UserResponse struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
IsActive bool `json:"is_active"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type ListUsersRequest struct {
|
||||
Page int `json:"page" validate:"min=1"`
|
||||
Limit int `json:"limit" validate:"min=1,max=100"`
|
||||
Role *string `json:"role,omitempty"`
|
||||
IsActive *bool `json:"is_active,omitempty"`
|
||||
}
|
||||
|
||||
type ListUsersResponse struct {
|
||||
Users []UserResponse `json:"users"`
|
||||
Pagination PaginationResponse `json:"pagination"`
|
||||
}
|
||||
|
||||
type RoleResponse struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
type PositionResponse struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Code string `json:"code"`
|
||||
Path string `json:"path"`
|
||||
}
|
||||
|
||||
type UserProfileResponse struct {
|
||||
UserID uuid.UUID `json:"user_id"`
|
||||
FullName string `json:"full_name"`
|
||||
DisplayName *string `json:"display_name,omitempty"`
|
||||
Phone *string `json:"phone,omitempty"`
|
||||
AvatarURL *string `json:"avatar_url,omitempty"`
|
||||
JobTitle *string `json:"job_title,omitempty"`
|
||||
EmployeeNo *string `json:"employee_no,omitempty"`
|
||||
Bio *string `json:"bio,omitempty"`
|
||||
Timezone string `json:"timezone"`
|
||||
Locale string `json:"locale"`
|
||||
Preferences map[string]interface{} `json:"preferences"`
|
||||
NotificationPrefs map[string]interface{} `json:"notification_prefs"`
|
||||
LastSeenAt *time.Time `json:"last_seen_at,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
type UpdateUserProfileRequest struct {
|
||||
FullName *string `json:"full_name,omitempty"`
|
||||
DisplayName *string `json:"display_name,omitempty"`
|
||||
Phone *string `json:"phone,omitempty"`
|
||||
AvatarURL *string `json:"avatar_url,omitempty"`
|
||||
JobTitle *string `json:"job_title,omitempty"`
|
||||
EmployeeNo *string `json:"employee_no,omitempty"`
|
||||
Bio *string `json:"bio,omitempty"`
|
||||
Timezone *string `json:"timezone,omitempty"`
|
||||
Locale *string `json:"locale,omitempty"`
|
||||
Preferences *map[string]interface{} `json:"preferences,omitempty"`
|
||||
NotificationPrefs *map[string]interface{} `json:"notification_prefs,omitempty"`
|
||||
}
|
||||
|
||||
type TitleResponse struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Code *string `json:"code,omitempty"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
}
|
||||
|
||||
type ListTitlesResponse struct {
|
||||
Titles []TitleResponse `json:"titles"`
|
||||
}
|
||||
Reference in New Issue
Block a user