some fixes
This commit is contained in:
@@ -2,8 +2,8 @@ package mdb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"kurumibot/database"
|
||||
"kurumibot/laniakea"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -19,7 +19,7 @@ type ConsoleLogEntry struct {
|
||||
func WriteConsoleLog(db *laniakea.DatabaseContext, e *ConsoleLogEntry) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
col := db.MongoDB.Database(os.Getenv("MONGO_NAME")).Collection("logs")
|
||||
col := database.GetMongoCollection(db, "logs")
|
||||
_, err := col.InsertOne(ctx, e)
|
||||
return err
|
||||
}
|
||||
@@ -35,7 +35,7 @@ type MessageLogEntry struct {
|
||||
func WriteMessageLog(db *laniakea.DatabaseContext, e *MessageLogEntry) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
collection := db.MongoDB.Database(os.Getenv("MONGO_NAME")).Collection("msg_logs")
|
||||
_, err := collection.InsertOne(ctx, e)
|
||||
col := database.GetMongoCollection(db, "msg_logs")
|
||||
_, err := col.InsertOne(ctx, e)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -22,12 +22,12 @@ func NewFractionRepository(db *sqlx.DB) *FractionRepository {
|
||||
return &FractionRepository{db: db}
|
||||
}
|
||||
|
||||
func (rep *FractionRepository) GetAllFractions() ([]*Fraction, error) {
|
||||
func (rep *FractionRepository) GetAll() ([]*Fraction, error) {
|
||||
fractions := make([]*Fraction, 0)
|
||||
err := rep.db.Select(&fractions, "SELECT * FROM fractions ORDER BY id DESC;")
|
||||
return fractions, err
|
||||
}
|
||||
func (rep *FractionRepository) GetFraction(id int32) (*Fraction, error) {
|
||||
func (rep *FractionRepository) GetById(id int32) (*Fraction, error) {
|
||||
fraction := new(Fraction)
|
||||
err := rep.db.Get(fraction, "SELECT * FROM fractions WHERE id = $1", id)
|
||||
return fraction, err
|
||||
|
||||
@@ -119,7 +119,7 @@ func GetUser(telegramId int) (*User, error) {
|
||||
}
|
||||
if user.FractionID.Valid {
|
||||
fractionRep := NewFractionRepository(database.PostgresDatabase)
|
||||
user.Fraction, err = fractionRep.GetFraction(user.FractionID.Int32)
|
||||
user.Fraction, err = fractionRep.GetById(user.FractionID.Int32)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user