mirror of
https://github.com/emo2007/block-accounting.git
synced 2025-04-12 08:56:28 +00:00
76 lines
1.7 KiB
Go
76 lines
1.7 KiB
Go
package domain
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
// Generic
|
|
|
|
type Collection[T any] struct {
|
|
Items []T `json:"items,omitempty"`
|
|
Pagination Pagination `json:"pagination,omitempty"`
|
|
}
|
|
|
|
type Pagination struct {
|
|
NextCursor string `json:"next_cursor,omitempty"`
|
|
TotalItems uint32 `json:"total_items,omitempty"`
|
|
}
|
|
|
|
// Auth related DTO's
|
|
|
|
type JoinRequest struct {
|
|
Name string `json:"name,omitempty"`
|
|
Credentals struct {
|
|
Email string `json:"email,omitempty"`
|
|
Phone string `json:"phone,omitempty"`
|
|
Telegram string `json:"telegram,omitempty"`
|
|
} `json:"credentals,omitempty"`
|
|
|
|
Mnemonic string `json:"mnemonic"`
|
|
}
|
|
|
|
type JoinResponse struct {
|
|
Token string `json:"token"`
|
|
}
|
|
|
|
type LoginRequest struct {
|
|
Mnemonic string `json:"mnemonic"`
|
|
}
|
|
|
|
type RefreshRequest struct {
|
|
Token string `json:"token"`
|
|
RefreshToken string `json:"refresh_token"`
|
|
}
|
|
|
|
type LoginResponse struct {
|
|
Token string `json:"token"`
|
|
ExpiredAt int64 `json:"token_expired_at"`
|
|
RefreshToken string `json:"refresh_token"`
|
|
RTExpiredAt int64 `json:"refresh_token_expired_at"`
|
|
}
|
|
|
|
// Organizations
|
|
|
|
type NewOrganizationRequest struct {
|
|
Name string `json:"name"`
|
|
Address string `json:"address"`
|
|
WalletMnemonic string `json:"wallet_mnemonic,omitempty"`
|
|
}
|
|
|
|
type ListOrganizationsRequest struct {
|
|
Cursor string `json:"cursor,omitempty"`
|
|
Limit uint8 `json:"limit,omitempty"` // Default: 50, Max: 50
|
|
OffsetDate int64 `json:"offset_date,omitempty"` // List organizations, updated since the date
|
|
}
|
|
|
|
func BuildRequest[T any](data []byte) (*T, error) {
|
|
var req T
|
|
|
|
if err := json.Unmarshal(data, &req); err != nil {
|
|
return nil, fmt.Errorf("error unmarshal request. %w", err)
|
|
}
|
|
|
|
return &req, nil
|
|
}
|