Web users may only CRUD their own records, operators stay in assigned branches, and admin/manager/superadmin keep full access. Co-authored-by: Cursor <cursoragent@cursor.com>
89 lines
2.1 KiB
Go
89 lines
2.1 KiB
Go
package currency
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type RateValue string
|
|
|
|
func (v RateValue) String() string { return string(v) }
|
|
|
|
func (v RateValue) MarshalJSON() ([]byte, error) {
|
|
s := strings.TrimSpace(string(v))
|
|
if s == "" {
|
|
return []byte("0"), nil
|
|
}
|
|
return []byte(s), nil
|
|
}
|
|
|
|
func (v *RateValue) UnmarshalJSON(b []byte) error {
|
|
raw := strings.TrimSpace(string(b))
|
|
if raw == "" || raw == "null" {
|
|
*v = ""
|
|
return nil
|
|
}
|
|
|
|
var n json.Number
|
|
if err := json.Unmarshal(b, &n); err == nil {
|
|
*v = RateValue(n.String())
|
|
return nil
|
|
}
|
|
|
|
var s string
|
|
if err := json.Unmarshal(b, &s); err != nil {
|
|
return err
|
|
}
|
|
*v = RateValue(strings.TrimSpace(s))
|
|
return nil
|
|
}
|
|
|
|
type CurrencyDTO struct {
|
|
Id int64 `json:"id"`
|
|
CurrencyFrom string `json:"currencyFrom"`
|
|
CurrencyTo string `json:"currencyTo"`
|
|
Value RateValue `json:"value" swaggertype:"number"`
|
|
CreatedById *int64 `json:"-"`
|
|
CreatedBy *UserInfo `json:"createdBy,omitempty"`
|
|
UpdatedById *int64 `json:"-"`
|
|
UpdatedBy *UserInfo `json:"updatedBy,omitempty"`
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
UpdatedAt time.Time `json:"updatedAt"`
|
|
}
|
|
|
|
type UserInfo struct {
|
|
Id int64 `json:"id"`
|
|
Name string `json:"name"`
|
|
Username string `json:"username"`
|
|
Phone string `json:"phone"`
|
|
Email string `json:"email"`
|
|
}
|
|
|
|
type CreateCurrencyDTO struct {
|
|
CurrencyFrom string `json:"currencyFrom" binding:"required"`
|
|
CurrencyTo string `json:"currencyTo" binding:"required"`
|
|
Value RateValue `json:"value" binding:"required" swaggertype:"number"`
|
|
CreatedBy *int64 `json:"-"`
|
|
}
|
|
|
|
type UpdateCurrencyDTO struct {
|
|
CurrencyFrom string `json:"currencyFrom" binding:"required"`
|
|
CurrencyTo string `json:"currencyTo" binding:"required"`
|
|
Value RateValue `json:"value" binding:"required" swaggertype:"number"`
|
|
UpdatedBy *int64 `json:"-"`
|
|
}
|
|
|
|
type ListFilter struct {
|
|
Search string
|
|
CurrencyFrom string
|
|
CurrencyTo string
|
|
Page int
|
|
Limit int
|
|
}
|
|
|
|
type ListCurrencyDTO struct {
|
|
Count int64 `json:"count"`
|
|
Currencies []CurrencyDTO `json:"currencies"`
|
|
}
|