Add executions service with CRUD operations

This commit is contained in:
Luis Eduardo Jeréz Girón
2024-07-20 18:42:20 -06:00
parent e3b99eeda1
commit ad613fbe4e
11 changed files with 101 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
package executions
import (
"context"
"github.com/eduardolat/pgbackweb/internal/database/dbgen"
)
func (s *Service) CreateExecution(
ctx context.Context, params dbgen.ExecutionsServiceCreateExecutionParams,
) (dbgen.Execution, error) {
return s.dbgen.ExecutionsServiceCreateExecution(ctx, params)
}

View File

@@ -0,0 +1,4 @@
-- name: ExecutionsServiceCreateExecution :one
INSERT INTO executions (status, message, path)
VALUES (@status, @message, @path)
RETURNING *;

View File

@@ -0,0 +1,13 @@
package executions
import (
"context"
"github.com/google/uuid"
)
func (s *Service) DeleteExecution(
ctx context.Context, id uuid.UUID,
) error {
return s.dbgen.ExecutionsServiceDeleteExecution(ctx, id)
}

View File

@@ -0,0 +1,3 @@
-- name: ExecutionsServiceDeleteExecution :exec
DELETE FROM executions
WHERE id = @id;

View File

@@ -0,0 +1,13 @@
package executions
import "github.com/eduardolat/pgbackweb/internal/database/dbgen"
type Service struct {
dbgen *dbgen.Queries
}
func New(dbgen *dbgen.Queries) *Service {
return &Service{
dbgen: dbgen,
}
}

View File

@@ -0,0 +1,14 @@
package executions
import (
"context"
"github.com/eduardolat/pgbackweb/internal/database/dbgen"
"github.com/google/uuid"
)
func (s *Service) GetExecution(
ctx context.Context, id uuid.UUID,
) (dbgen.Execution, error) {
return s.dbgen.ExecutionsServiceGetExecution(ctx, id)
}

View File

@@ -0,0 +1,3 @@
-- name: ExecutionsServiceGetExecution :one
SELECT * FROM executions
WHERE id = @id;

View File

@@ -0,0 +1,13 @@
package executions
import (
"context"
"github.com/eduardolat/pgbackweb/internal/database/dbgen"
)
func (s *Service) ListExecutions(
ctx context.Context,
) ([]dbgen.Execution, error) {
return s.dbgen.ExecutionsServiceListExecutions(ctx)
}

View File

@@ -0,0 +1,2 @@
-- name: ExecutionsServiceListExecutions :many
SELECT * FROM executions;

View File

@@ -0,0 +1,13 @@
package executions
import (
"context"
"github.com/eduardolat/pgbackweb/internal/database/dbgen"
)
func (s *Service) UpdateExecution(
ctx context.Context, params dbgen.ExecutionsServiceUpdateExecutionParams,
) (dbgen.Execution, error) {
return s.dbgen.ExecutionsServiceUpdateExecution(ctx, params)
}

View File

@@ -0,0 +1,10 @@
-- name: ExecutionsServiceUpdateExecution :one
UPDATE executions
SET
status = @status,
message = @message,
path = @path,
finished_at = @finished_at,
deleted_at = @deleted_at
WHERE id = @id
RETURNING *;