style: reformatted all files
This commit is contained in:
@@ -3,8 +3,9 @@ package postgres
|
||||
import (
|
||||
"context"
|
||||
|
||||
"datarush/pkg/api/user"
|
||||
"github.com/jmoiron/sqlx"
|
||||
|
||||
"datarush/pkg/api/user"
|
||||
)
|
||||
|
||||
type UserRepository struct {
|
||||
@@ -17,22 +18,42 @@ func NewUserRepository(db *sqlx.DB) *UserRepository {
|
||||
|
||||
func (r *UserRepository) GetProfile(ctx context.Context, userID string) (*user.User, error) {
|
||||
var u user.User
|
||||
err := r.db.GetContext(ctx, &u, "SELECT id, username, email, full_name, avatar_url FROM users WHERE id = $1", userID)
|
||||
err := r.db.GetContext(
|
||||
ctx,
|
||||
&u,
|
||||
"SELECT id, username, email, full_name, avatar_url FROM users WHERE id = $1",
|
||||
userID,
|
||||
)
|
||||
return &u, err
|
||||
}
|
||||
|
||||
func (r *UserRepository) RegisterForCompetition(ctx context.Context, userID, competitionID string) error {
|
||||
_, err := r.db.ExecContext(ctx, "INSERT INTO user_competitions (user_id, competition_id) VALUES ($1, $2)", userID, competitionID)
|
||||
_, err := r.db.ExecContext(
|
||||
ctx,
|
||||
"INSERT INTO user_competitions (user_id, competition_id) VALUES ($1, $2)",
|
||||
userID,
|
||||
competitionID,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *UserRepository) UnregisterFromCompetition(ctx context.Context, userID, competitionID string) error {
|
||||
_, err := r.db.ExecContext(ctx, "DELETE FROM user_competitions WHERE user_id = $1 AND competition_id = $2", userID, competitionID)
|
||||
_, err := r.db.ExecContext(
|
||||
ctx,
|
||||
"DELETE FROM user_competitions WHERE user_id = $1 AND competition_id = $2",
|
||||
userID,
|
||||
competitionID,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *UserRepository) ListUserCompetitions(ctx context.Context, userID string) ([]string, error) {
|
||||
var competitionIDs []string
|
||||
err := r.db.SelectContext(ctx, &competitionIDs, "SELECT competition_id FROM user_competitions WHERE user_id = $1", userID)
|
||||
err := r.db.SelectContext(
|
||||
ctx,
|
||||
&competitionIDs,
|
||||
"SELECT competition_id FROM user_competitions WHERE user_id = $1",
|
||||
userID,
|
||||
)
|
||||
return competitionIDs, err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user