Documentation
¶
Index ¶
- Constants
- Variables
- func Connect(ctx context.Context) *sqlx.DB
- func DeleteUser(ctx context.Context, charID int32) error
- func GetCharStandingISK(ctx context.Context, charID int32) (float64, error)
- func GetContractItems(ctx context.Context, contracts Contracts) error
- func GetName(ctx context.Context, id int32) (string, error)
- func GetNames(ctx context.Context, ids ...int32) (map[int32]string, error)
- func GetOutstandingContracts(ctx context.Context, c int32) ([]int32, error)
- func GetStatements(ctx context.Context) map[cx.Key]*sqlx.NamedStmt
- func NewCharacter(ctx context.Context, char *CharacterRow) error
- func PruneContract(ctx context.Context, c *Contract) error
- func PruneDonation(ctx context.Context, donation *Donation) error
- func SaveCharacter(ctx context.Context, char *Character) error
- func SaveCharacterContracts(ctx context.Context, donations Contracts, affiliations []*Affiliation, ...) error
- func SaveCharacterDonations(ctx context.Context, donations []*Donation, affiliations []*Affiliation, ...) error
- func SaveContract(ctx context.Context, contract *Contract) error
- func SaveDonation(ctx context.Context, donation *Donation) error
- func SaveNames(ctx context.Context, affiliations []*Affiliation) error
- func SaveUser(ctx context.Context, user *User) error
- func SetPreferences(ctx context.Context, charID int32, p *Preferences) error
- func UpdateContracts(ctx context.Context, contracts []*Contract, aff []*Affiliation) error
- type Affiliation
- type CharDetails
- type Character
- type CharacterRow
- type Contract
- type Contracts
- type Donation
- type Donations
- type Item
- type Name
- type Preferences
- type Prefs
- type Profile
- type User
- type UserError
Constants ¶
const ( // DefaultDonationRow is used if the user has not set a donation row pattern DefaultDonationRow = "%CHARACTER% just donated %AMOUNT% ISK!" // DefaultContractRow is used if the user has not set a contract row pattern DefaultContractRow = "%CHARACTER% just contracted %ITEMS% items worth" + " %AMOUNT% ISK!" )
Variables ¶
var ( // RePreferences ensures the row pattern has at least some content RePreferences = regexp.MustCompile(`[^( \t)]+`) )
Functions ¶
func DeleteUser ¶
DeleteUser removes a user (auth/tracked character)
func GetCharStandingISK ¶
GetCharStandingISK returns the amount donated towards improving standing
func GetContractItems ¶
GetContractItems fills in the Items of each Contract passed
func GetOutstandingContracts ¶
GetOutstandingContracts returns a list of outstanding contract IDs
func GetStatements ¶
GetStatements prepares all queries for the global context
func NewCharacter ¶
func NewCharacter(ctx context.Context, char *CharacterRow) error
NewCharacter adds a new character to the characters table
func PruneContract ¶
PruneContract removes a contract and deducts from the 30d totals
func PruneDonation ¶
PruneDonation removes a donation by ID
func SaveCharacter ¶
SaveCharacter saves a single character
func SaveCharacterContracts ¶
func SaveCharacterContracts( ctx context.Context, donations Contracts, affiliations []*Affiliation, addition bool, ) error
SaveCharacterContracts updates all totals in the characters table
func SaveCharacterDonations ¶
func SaveCharacterDonations( ctx context.Context, donations []*Donation, affiliations []*Affiliation, addition bool, ) error
SaveCharacterDonations updates all totals in the characters table
func SaveContract ¶
SaveContract saves the contract and associated items in the db
func SaveDonation ¶
SaveDonation stores a donation in the database
func SaveNames ¶
func SaveNames(ctx context.Context, affiliations []*Affiliation) error
SaveNames stores the map of ids:names in the db
func SetPreferences ¶
func SetPreferences(ctx context.Context, charID int32, p *Preferences) error
SetPreferences sets the Preferences for the logged in user
func UpdateContracts ¶
func UpdateContracts( ctx context.Context, contracts []*Contract, aff []*Affiliation, ) error
UpdateContracts sets the contract as accepted in the db, if it has been
Types ¶
type Affiliation ¶
Affiliation links a character with a corporation and maybe alliance
type CharDetails ¶
type CharDetails struct { Character *Character `json:"character"` // ISK IN Donations Donations `json:"donations,omitempty"` Contracts Contracts `json:"contracts,omitempty"` // ISK OUT Donated Donations `json:"donated,omitempty"` Contracted Contracts `json:"contracted,omitempty"` }
CharDetails is the api return for a character
func GetCharDetails ¶
func GetCharDetails(ctx context.Context, charID int32) (*CharDetails, error)
GetCharDetails returns details for the character from pg
type Character ¶
type Character struct { // ID is the characterID of this donator/recipient ID int32 `json:"id"` // Name is the last checked name of the character Name string `json:"name,omitempty"` // CorporationID is the last checked corporation ID of the character CorporationID int32 `json:"corporation,omitempty"` // CorporationName is the last checked name of the corporation CorporationName string `json:"corporation_name,omitempty"` // AllianceID is the last checked alliance ID of the character AllianceID int32 `json:"alliance,omitempty"` // AllianceName is the last checked name of the alliance AllianceName string `json:"alliance_name,omitempty"` // Received donations and/or contracts Received int64 `json:"received,omitempty"` // ReceivedISK value of all donations plus contracts ReceivedISK float64 `json:"received_isk,omitempty"` // Received donations and/or contracts in the last 30 days Received30 int64 `json:"received_30,omitempty"` // ReceivedISK30 value of all donations plus contracts in the last 30 days ReceivedISK30 float64 `json:"received_isk_30,omitempty"` // Donated is the number of times this character has donated to someone else Donated int64 `json:"donated,omitempty"` // DonatedISK is the value of all ISK donated DonatedISK float64 `json:"donated_isk,omitempty"` // Donated30 is the number of donations in the last 30 days Donated30 int64 `json:"donated_30,omitempty"` // DonatedISK30 is the value of all ISK donated in the last 30 days DonatedISK30 float64 `json:"donated_isk_30,omitempty"` // LastDonated timestamp LastDonated time.Time `json:"last_donated,omitempty"` // LastReceived timestamp LastReceived time.Time `json:"last_received,omitempty"` // GoodStanding boolean GoodStanding bool `json:"good_standing"` }
Character describes the output format of known characters
func GetCharacter ¶
GetCharacter pulls a single character from the db
func GetTopDonators ¶
GetTopDonators returns the top character IDs and isk values
func GetTopRecipients ¶
GetTopRecipients returns the top character IDs and isk values
func (*Character) MarshalJSON ¶
MarshalJSON implementation to omit our null timestamps
type CharacterRow ¶
type CharacterRow struct { // ID is the characterID of this donator/recipient ID int32 `db:"character_id"` // CorporationID is the last checked corporation ID of the character CorporationID int32 `db:"corporation_id"` // AllianceID is the last checked alliance ID of the character AllianceID int32 `db:"alliance_id"` // Received donations and/or contracts Received int64 `db:"received"` // ReceivedISK value of all donations plus contracts ReceivedISK float64 `db:"received_isk"` // Received donations and/or contracts in the last 30 days Received30 int64 `db:"received_30"` // ReceivedISK30 value of all donations plus contracts in the last 30 days ReceivedISK30 float64 `db:"received_isk_30"` // Donated is the number of times this character has donated to someone else Donated int64 `db:"donated"` // DonatedISK is the value of all ISK donated DonatedISK float64 `db:"donated_isk"` // Donated30 is the number of donations in the last 30 days Donated30 int64 `db:"donated_30"` // DonatedISK30 is the value of all ISK donated in the last 30 days DonatedISK30 float64 `db:"donated_isk_30"` // LastDonated timestamp LastDonated pq.NullTime `db:"last_donated"` // LastReceived timestamp LastReceived pq.NullTime `db:"last_received"` // GoodStanding boolean GoodStanding bool `db:"good_standing"` }
CharacterRow describes Character as stored in the characters table
type Contract ¶
type Contract struct { // ID is the contract ID ID int32 `db:"contract_id" json:"id"` // Donator who sent the recipient the contract Donator int32 `db:"donator" json:"donator"` // Receiver is who received the contract Receiver int32 `db:"receiver" json:"receiver"` // Location is the station or structure ID Location int64 `db:"location" json:"location"` // Issued timestamp Issued time.Time `db:"issued" json:"issued"` // Expires timestamp Expires time.Time `db:"expires" json:"expires"` // Accepted boolean Accepted bool `db:"accepted" json:"accepted"` // Value is an estimated value of the contract items Value float64 `db:"value" json:"value"` // Note is the title of the contract Note string `db:"note" json:"note"` // Items is an array of items in the contract Items []*Item `json:"items"` }
Contract describes zero ISK donation contracts
type Contracts ¶
type Contracts []*Contract
Contracts are time sorted
func GetStaleContracts ¶
GetStaleContracts returns contracts issued more than 30 days ago
type Donation ¶
type Donation struct { // ID is the transaction ID ID int64 `db:"transaction_id" json:"id"` // Donator who sent the recipient this isk Donator int32 `db:"donator" json:"donator"` // Recipient is who received the donation Recipient int32 `db:"receiver" json:"receiver"` // Timestamp of when this tranfer occurred Timestamp time.Time `db:"timestamp" json:"timestamp"` // Note or memo that came with the transfer Note string `db:"note" json:"note,omitempty"` // Amount of ISK transferred Amount float64 `db:"amount" json:"amount"` }
Donation describes a one time ISK transfer
type Donations ¶
type Donations []*Donation
Donations are time sorted
func GetCharDonated ¶
GetCharDonated returns donations FROM the character
func GetCharDonations ¶
GetCharDonations returns donations FOR the character
func GetStaleDonations ¶
GetStaleDonations returns donations from more than 30 days ago
type Item ¶
type Item struct { // ID is a record ID ID int64 `db:"id" json:"-"` // ContractID links this item to a contract ContractID int32 `db:"contract_id" json:"-"` // TypeID of the item in the contract TypeID int32 `db:"type_id" json:"type_id"` // Quantity of items given Quantity int32 `db:"quantity" json:"quantity"` // ItemID of the item in the contract (if possible to determine) ItemID int64 `db:"item_id" json:"item_id,omitempty"` }
Item are sourced from the contractItems table by id
type Preferences ¶
Preferences exports Prefs for donations, contracts, or both NB: the JSON form of this is only used for the combined view
func GetPreferences ¶
GetPreferences returns the Preferences for the logged in user
type Prefs ¶
type Prefs struct { Header string `json:"header,omitempty"` Pattern string `json:"pattern"` Passphrase string `json:"passphrase,omitempty"` Rows int `json:"rows"` MaxAge int `json:"max_age,omitempty"` // seconds Minimum float64 `json:"minimum"` }
Prefs exports preferences for either donations or contracts
type Profile ¶
type Profile struct { // CharacterID recipient CharacterID int32 // Private is if we should hide this profile for everyone else Private bool // Passphrase can be set by the profile owner for minimal security Passphrase string }
Profile describes someone setup to receive ISK
type User ¶
type User struct { RefreshToken string `db:"refresh_token"` AccessToken string `db:"access_token"` OwnerHash string `db:"owner_hash"` CharacterID int32 `db:"character_id"` LastJournalID sql.NullInt64 `db:"last_journal_id"` LastContractID sql.NullInt64 `db:"last_contract_id"` AccessExpires time.Time `db:"access_expires"` LastProcessed *time.Time `db:"last_processed"` }
User describes a mapping between a user and a character