entity

package
v0.0.0-...-dc32c78 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 4, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExpired         = errors.New("auction expired")
	ErrAuctionNotFound = errors.New("auction not found")
	ErrInvalidAuction  = errors.New("invalid auction")
)
View Source
var (
	ErrInvalidBid  = errors.New("invalid bid")
	ErrBidNotFound = errors.New("bid not found")
)
View Source
var (
	ErrInvalidContract  = errors.New("invalid contract")
	ErrContractNotFound = errors.New("contract not found")
)
View Source
var (
	ErrInvalidOrder  = errors.New("invalid order")
	ErrOrderNotFound = errors.New("order not found")
)
View Source
var (
	ErrInvalidStation  = errors.New("invalid station")
	ErrStationNotFound = errors.New("station not found")
)
View Source
var (
	ErrInvalidUser  = errors.New("invalid user")
	ErrUserNotFound = errors.New("user not found")
)

Functions

This section is empty.

Types

type Auction

type Auction struct {
	Id         uint               `json:"id" gorm:"primaryKey"`
	Credits    custom_type.BigInt `json:"credits,omitempty" gorm:"type:bigint;not null"`
	PriceLimit custom_type.BigInt `json:"price_limit,omitempty" gorm:"type:bigint;not null"`
	State      AuctionState       `json:"state,omitempty" gorm:"type:text;not null"`
	Bids       []*Bid             `json:"bids,omitempty" gorm:"foreignKey:AuctionId;constraint:OnDelete:CASCADE"`
	ExpiresAt  int64              `json:"expires_at,omitempty" gorm:"not null"`
	CreatedAt  int64              `json:"created_at,omitempty" gorm:"not null"`
	UpdatedAt  int64              `json:"updated_at,omitempty" gorm:"default:0"`
}

func NewAuction

func NewAuction(credits custom_type.BigInt, priceLimit custom_type.BigInt, expiresAt int64, createdAt int64) (*Auction, error)

func (*Auction) Validate

func (a *Auction) Validate() error

type AuctionRepository

type AuctionRepository interface {
	DeleteAuction(id uint) error
	FindActiveAuction() (*Auction, error)
	FindAllAuctions() ([]*Auction, error)
	FindAuctionById(id uint) (*Auction, error)
	CreateAuction(auction *Auction) (*Auction, error)
	UpdateAuction(auction *Auction) (*Auction, error)
}

type AuctionState

type AuctionState string
const (
	AuctionOngoing   AuctionState = "ongoing"
	AuctionFinished  AuctionState = "finished"
	AuctionCancelled AuctionState = "cancelled"
)

type Bid

type Bid struct {
	Id        uint                `json:"id" gorm:"primaryKey"`
	AuctionId uint                `json:"auction_id" gorm:"not null;index"`
	Bidder    custom_type.Address `json:"bidder,omitempty" gorm:"not null"`
	Credits   custom_type.BigInt  `json:"credits,omitempty" gorm:"type:bigint;not null"`
	Price     custom_type.BigInt  `json:"price,omitempty" gorm:"type:bigint;not null"`
	State     BidState            `json:"state,omitempty" gorm:"type:text;not null"`
	CreatedAt int64               `json:"created_at,omitempty" gorm:"not null"`
	UpdatedAt int64               `json:"updated_at,omitempty" gorm:"default:0"`
}

func NewBid

func NewBid(auctionId uint, bidder custom_type.Address, credits custom_type.BigInt, price custom_type.BigInt, createdAt int64) (*Bid, error)

func (*Bid) Validate

func (b *Bid) Validate() error

type BidRepository

type BidRepository interface {
	CreateBid(bid *Bid) (*Bid, error)
	FindBidsByState(auctionId uint, state string) ([]*Bid, error)
	FindBidById(id uint) (*Bid, error)
	FindBidsByAuctionId(id uint) ([]*Bid, error)
	FindAllBids() ([]*Bid, error)
	UpdateBid(bid *Bid) (*Bid, error)
	DeleteBid(id uint) error
}

type BidState

type BidState string
const (
	BidStatePending  BidState = "pending"
	BidStateAccepted BidState = "accepted"
	BidStateRejected BidState = "rejected"
	BidStateExpired  BidState = "expired"
)

type Contract

type Contract struct {
	Id        uint                `json:"id" gorm:"primaryKey"`
	Symbol    string              `json:"symbol,omitempty" gorm:"uniqueIndex;not null"`
	Address   custom_type.Address `json:"address,omitempty" gorm:"type:text;not null"`
	CreatedAt int64               `json:"created_at,omitempty" gorm:"not null"`
	UpdatedAt int64               `json:"updated_at,omitempty" gorm:"default:0"`
}

func NewContract

func NewContract(symbol string, address custom_type.Address, createdAt int64) (*Contract, error)

func (*Contract) Validate

func (c *Contract) Validate() error

type ContractRepository

type ContractRepository interface {
	CreateContract(contract *Contract) (*Contract, error)
	FindAllContracts() ([]*Contract, error)
	FindContractBySymbol(symbol string) (*Contract, error)
	UpdateContract(contract *Contract) (*Contract, error)
	DeleteContract(symbol string) error
}

type Order

type Order struct {
	Id             uint                `json:"id" gorm:"primaryKey"`
	Buyer          custom_type.Address `json:"buyer,omitempty" gorm:"type:text;not null"`
	Credits        custom_type.BigInt  `json:"credits,omitempty" gorm:"type:bigint;not null"`
	StationId      string              `json:"station_id,omitempty" gorm:"not null"`
	PricePerCredit custom_type.BigInt  `json:"price_per_credit,omitempty" gorm:"type:bigint;not null"`
	CreatedAt      int64               `json:"created_at,omitempty" gorm:"not null"`
	UpdatedAt      int64               `json:"updated_at,omitempty" gorm:"default:0"`
}

func NewOrder

func NewOrder(buyer custom_type.Address, credits custom_type.BigInt, stationId string, pricePerCredit *big.Int, createdAt int64) (*Order, error)

func (*Order) Validate

func (o *Order) Validate() error

type OrderRepository

type OrderRepository interface {
	CreateOrder(order *Order) (*Order, error)
	FindOrderById(id uint) (*Order, error)
	FindOrdersByUser(buyer custom_type.Address) ([]*Order, error)
	FindAllOrders() ([]*Order, error)
	UpdateOrder(order *Order) (*Order, error)
	DeleteOrder(id uint) error
}

type Station

type Station struct {
	Id             string              `json:"id" gorm:"primaryKey"`
	Consumption    custom_type.BigInt  `json:"consumption,omitempty" gorm:"type:bigint;not null"`
	Owner          custom_type.Address `json:"owner,omitempty" gorm:"not null"`
	State          StationState        `json:"state,omitempty" gorm:"type:text;not null"`
	Orders         []*Order            `json:"orders,omitempty" gorm:"foreignKey:StationId;constraint:OnDelete:CASCADE"`
	PricePerCredit custom_type.BigInt  `json:"price_per_credit,omitempty" gorm:"type:bigint;not null"`
	Latitude       float64             `json:"latitude,omitempty" gorm:"not null"`
	Longitude      float64             `json:"longitude,omitempty" gorm:"not null"`
	CreatedAt      int64               `json:"created_at,omitempty" gorm:"not null"`
	UpdatedAt      int64               `json:"updated_at,omitempty" gorm:"default:0"`
}

func NewStation

func NewStation(id string, owner custom_type.Address, consumption custom_type.BigInt, pricePerCredit custom_type.BigInt, latitude float64, longitude float64, createdAt int64) (*Station, error)

func (*Station) Validate

func (s *Station) Validate() error

type StationRepository

type StationRepository interface {
	CreateStation(station *Station) (*Station, error)
	FindStationById(id string) (*Station, error)
	FindAllStations() ([]*Station, error)
	UpdateStation(station *Station) (*Station, error)
	DeleteStation(id string) error
}

type StationState

type StationState string
const (
	StationStateActive   StationState = "active"
	StationStateInactive StationState = "inactive"
)

type User

type User struct {
	Id        uint                `json:"id" gorm:"primaryKey"`
	Role      string              `json:"role,omitempty" gorm:"not null"`
	Address   custom_type.Address `json:"address,omitempty" gorm:"type:text;uniqueIndex;not null"`
	CreatedAt int64               `json:"created_at,omitempty" gorm:"not null"`
	UpdatedAt int64               `json:"updated_at,omitempty" gorm:"default:0"`
}

func NewUser

func NewUser(role string, address custom_type.Address, created_at int64) (*User, error)

func (*User) Validate

func (u *User) Validate() error

type UserRepository

type UserRepository interface {
	CreateUser(User *User) (*User, error)
	FindUserByRole(role string) (*User, error)
	FindUserByAddress(address custom_type.Address) (*User, error)
	UpdateUser(User *User) (*User, error)
	FindAllUsers() ([]*User, error)
	DeleteUserByAddress(address custom_type.Address) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL