2021-09-28 23:57:59 +07:00
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hhhapz/hackathon/models"
|
|
|
|
)
|
|
|
|
|
2021-09-30 10:32:18 +07:00
|
|
|
func (db *DB) Users(ctx context.Context) ([]*models.User, error) {
|
|
|
|
return models.Users(ctx, db.DB)
|
|
|
|
}
|
2021-09-28 23:57:59 +07:00
|
|
|
|
2021-09-30 10:32:18 +07:00
|
|
|
func (db *DB) User(ctx context.Context, email string) (*models.User, error) {
|
|
|
|
return models.UserByEmail(ctx, db.DB, email)
|
|
|
|
}
|
2021-09-28 23:57:59 +07:00
|
|
|
|
2021-09-30 10:32:18 +07:00
|
|
|
func (db *DB) UpdateUser(ctx context.Context, user *models.User) error {
|
|
|
|
if err := user.Upsert(ctx, db.DB); err != nil {
|
|
|
|
return fmt.Errorf("could not upsert user: %w", err)
|
2021-09-28 23:57:59 +07:00
|
|
|
}
|
2021-09-30 10:32:18 +07:00
|
|
|
return nil
|
2021-09-28 23:57:59 +07:00
|
|
|
}
|