init
This commit is contained in:
32
internal/storage/user-to-project.go
Normal file
32
internal/storage/user-to-project.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"madsky.ru/go-tracker/internal/database"
|
||||
)
|
||||
|
||||
type UserToProjectRepository interface {
|
||||
Create(ctx context.Context, userId uint32, projectId uint32) error
|
||||
}
|
||||
|
||||
type UserToProjectStore struct {
|
||||
client database.Client
|
||||
}
|
||||
|
||||
func (up *UserToProjectStore) Create(ctx context.Context, userId uint32, projectId uint32) error {
|
||||
query := `insert into user_to_project (user_id, project_id) values (@userId, @projectId)`
|
||||
|
||||
args := pgx.NamedArgs{
|
||||
"userId": userId,
|
||||
"projectId": projectId,
|
||||
}
|
||||
|
||||
_, err := up.client.Exec(ctx, query, args)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to insert row: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user