update
1. add cron module 2. add pool module 3. add tcgplayer background job 4. add card price model
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// CardPrice -
|
||||
type CardPrice struct {
|
||||
Card string `db:"card" cc:"card"`
|
||||
PriceN float32 `db:"price_n" cc:"price_n"`
|
||||
PriceF float32 `db:"price_f" cc:"price_f"`
|
||||
Ctime time.Time `db:"ctime" cc:"ctime"`
|
||||
}
|
||||
|
||||
type InsertCardPriceOpts struct {
|
||||
Data []CardPrice
|
||||
}
|
||||
|
||||
// InsertCardPrice -
|
||||
func InsertCardPrice(arg InsertCardPriceOpts) (err error) {
|
||||
if len(arg.Data) == 0 {
|
||||
return errors.New("data list is empty")
|
||||
}
|
||||
|
||||
tmp := make([]CardPrice, 0, len(arg.Data))
|
||||
|
||||
for _, v := range arg.Data {
|
||||
if len(v.Card) > 0 {
|
||||
tmp = append(tmp, v)
|
||||
}
|
||||
}
|
||||
|
||||
query := `insert into "public"."card_price" ("card", "price_n", "price_f", "ctime") values `
|
||||
insStr := ""
|
||||
|
||||
for i := 0; i < len(tmp); i++ {
|
||||
if len(insStr) > 0 {
|
||||
insStr += ","
|
||||
}
|
||||
|
||||
insStr += " (:card, :price_n, :price_f, now()) "
|
||||
}
|
||||
|
||||
_, err = x.NamedExec(query+insStr, tmp)
|
||||
|
||||
return
|
||||
}
|
||||
+18
-1
@@ -1,6 +1,7 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@@ -28,6 +29,7 @@ type Cards struct {
|
||||
Types []string `db:"types" cc:"types"`
|
||||
Subtypes []string `db:"subtypes" cc:"subtypes"`
|
||||
Supertypes []string `db:"supertypes" cc:"supertypes"`
|
||||
TCGPlayerID int `db:"tcgplayerid" cc:"tcgplayerid"`
|
||||
}
|
||||
|
||||
// order opts
|
||||
@@ -104,7 +106,7 @@ func ListCards(arg ListCardsOpts) (cards []*Cards, err error) {
|
||||
arg.Offset = 0
|
||||
}
|
||||
query := `select c.id, c.name, c.cmc, c.mana_cost, c.text, c.layout, c.image_url, c.loyalty,
|
||||
c.type, c.number, c.power, c.toughness, c.set from "public"."cards" c`
|
||||
c.type, c.number, c.power, c.toughness, c.set, c.tcgplayerid from "public"."cards" c`
|
||||
where := struct {
|
||||
Name string `db:"name"`
|
||||
CMC float32 `db:"cmc"`
|
||||
@@ -144,3 +146,18 @@ func ListCards(arg ListCardsOpts) (cards []*Cards, err error) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetCardByTCGPlayerIDs -
|
||||
func GetCardByTCGPlayerIDs(ids []int) (cards []*Cards, err error) {
|
||||
if len(ids) == 0 {
|
||||
return nil, errors.New("ids list is empty")
|
||||
}
|
||||
|
||||
query := `select c.id, c.name, c.cmc, c.mana_cost, c.text, c.layout, c.image_url, c.loyalty,
|
||||
c.type, c.number, c.power, c.toughness, c.set, c.tcgplayerid from "public"."cards" c where c.tcgplayerid in (?)`
|
||||
err = x.Select(&cards, query, ids)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ type Sets struct {
|
||||
Code string `db:"code" cc:"code"`
|
||||
Name string `db:"name" cc:"name"`
|
||||
ReleaseDate time.Time `db:"release_date" cc:"release_date"`
|
||||
TCGPlayerID int `db:"tcgplayerid" cc:"tcgplayerid"`
|
||||
}
|
||||
|
||||
// ListSetsOpts -
|
||||
|
||||
Reference in New Issue
Block a user