commit
This commit is contained in:
33
database/mdb/code.go
Normal file
33
database/mdb/code.go
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package mdb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"kurumibot/database"
|
||||||
|
"kurumibot/laniakea"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"go.mongodb.org/mongo-driver/v2/bson"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CodeEntry struct {
|
||||||
|
Code string `bson:"code"`
|
||||||
|
Money uint64 `bson:"money"`
|
||||||
|
Exp uint64 `bson:"exp"`
|
||||||
|
AutoId uint16 `bson:"autoId"`
|
||||||
|
MaidId uint16 `bson:"maidId"`
|
||||||
|
MinerId uint16 `bson:"minerId"`
|
||||||
|
BusinessId uint16 `bson:"businessId"`
|
||||||
|
ValidUntil time.Time `bson:"validUntil"`
|
||||||
|
UsageCount int `bson:"usageCount"`
|
||||||
|
TotalUsages uint `bson:"totalUsages"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func FindCode(db *laniakea.DatabaseContext, code string) (*CodeEntry, error) {
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
collection := database.GetMongoCollection(db, "codes")
|
||||||
|
res := collection.FindOne(ctx, bson.M{"code": code})
|
||||||
|
entry := new(CodeEntry)
|
||||||
|
err := res.Decode(entry)
|
||||||
|
return entry, err
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package database
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"kurumibot/laniakea"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
@@ -25,3 +26,7 @@ func ConnectMongo() {
|
|||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetMongoCollection(db *laniakea.DatabaseContext, name string) *mongo.Collection {
|
||||||
|
return db.MongoDB.Database(os.Getenv("MONGO_NAME")).Collection(name)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package psql
|
package psql
|
||||||
|
|
||||||
import "github.com/shopspring/decimal"
|
import (
|
||||||
|
"kurumibot/database"
|
||||||
|
|
||||||
|
"github.com/shopspring/decimal"
|
||||||
|
)
|
||||||
|
|
||||||
type Group struct {
|
type Group struct {
|
||||||
ID int
|
ID int
|
||||||
@@ -13,8 +17,8 @@ type Group struct {
|
|||||||
MaxWaifus int
|
MaxWaifus int
|
||||||
}
|
}
|
||||||
|
|
||||||
// func GetGroupById(id int) (*Group, error) {
|
func GetGroupById(id int) (*Group, error) {
|
||||||
// group := new(Group)
|
group := new(Group)
|
||||||
// // err := Database.Get(group, "select * from groups where id=$1;", id)
|
tx := database.PostgresDatabase.First(group, "id = ?", id)
|
||||||
// return group, err
|
return group, tx.Error
|
||||||
// }
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ type User struct {
|
|||||||
WorkID int `gorm:"default:1"`
|
WorkID int `gorm:"default:1"`
|
||||||
Work *Work
|
Work *Work
|
||||||
WorkTime time.Time
|
WorkTime time.Time
|
||||||
|
|
||||||
AutoID sql.NullInt64
|
AutoID sql.NullInt64
|
||||||
Auto *ShopAuto
|
Auto *ShopAuto
|
||||||
BusinessID sql.NullInt64
|
BusinessID sql.NullInt64
|
||||||
@@ -32,6 +33,7 @@ type User struct {
|
|||||||
Maid *ShopMaid
|
Maid *ShopMaid
|
||||||
MinerID sql.NullInt64
|
MinerID sql.NullInt64
|
||||||
Miner *ShopMiner
|
Miner *ShopMiner
|
||||||
|
|
||||||
IncomeTime time.Time
|
IncomeTime time.Time
|
||||||
BTC decimal.Decimal
|
BTC decimal.Decimal
|
||||||
Invested decimal.Decimal
|
Invested decimal.Decimal
|
||||||
|
|||||||
Reference in New Issue
Block a user