package postgres import ( "context" "database/sql" "git.aiterp.net/rpdata/api/database/postgres/psqlcore" "git.aiterp.net/rpdata/api/models" ) type userRepository struct { db *sql.DB } func (r *userRepository) Find(ctx context.Context, id string) (*models.User, error) { user, err := psqlcore.New(r.db).SelectUser(ctx, id) if err != nil { return nil, err } return &models.User{ ID: user.ID, Nick: user.Nick, Permissions: user.Permissions, }, nil } func (r *userRepository) List(ctx context.Context) ([]*models.User, error) { users, err := psqlcore.New(r.db).SelectUsers(ctx) if err != nil { return nil, err } results := make([]*models.User, 0, len(users)) for _, user := range users { results = append(results, &models.User{ ID: user.ID, Nick: user.Nick, Permissions: user.Permissions, }) } return results, nil } func (r *userRepository) Insert(ctx context.Context, user models.User) (*models.User, error) { err := psqlcore.New(r.db).InsertUser(ctx, psqlcore.InsertUserParams{ ID: user.ID, Nick: user.Nick, Permissions: user.Permissions, }) if err != nil { return nil, err } return &user, nil }