Skip to content

Commit

Permalink
feat: Create audio/video profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricioabreu committed Apr 13, 2024
1 parent 68262c5 commit 076b7bd
Show file tree
Hide file tree
Showing 8 changed files with 265 additions and 6 deletions.
19 changes: 19 additions & 0 deletions internal/db/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

125 changes: 125 additions & 0 deletions internal/db/query.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions internal/db/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ type InputStore interface {
CreateInput(context.Context, CreateInputParams) (Input, error)
GetInput(context.Context, uuid.UUID) (Input, error)
DeleteInput(context.Context, uuid.UUID) error
CreateAudioProfile(context.Context, CreateAudioProfileParams) error
CreateVideoProfile(context.Context, CreateVideoProfileParams) error
}
28 changes: 28 additions & 0 deletions internal/mocks/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 19 additions & 3 deletions internal/model/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,23 @@ package model
import "github.com/google/uuid"

type Input struct {
ID uuid.UUID `json:"id"`
Name string `json:"name" validate:"required"`
Format string `json:"format" validate:"required"`
ID uuid.UUID `json:"id"`
Name string `json:"name" validate:"required"`
Format string `json:"format" validate:"required"`
Audio []AudioProfile `json:"audio"`
Video []VideoProfile `json:"video"`
}

type AudioProfile struct {
Rate int `json:"rate"`
Codec string `json:"codec"`
}

type VideoProfile struct {
Codec string `json:"codec"`
Bitrate int `json:"bitrate"`
MaxKeyInterval int `json:"max_key_interval"`
Framerate int `json:"framerate"`
Width int `json:"width"`
Height int `json:"height"`
}
29 changes: 29 additions & 0 deletions internal/service/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
"github.com/learn-video/dionysia/internal/db"
"github.com/learn-video/dionysia/internal/model"
)
Expand Down Expand Up @@ -35,6 +36,34 @@ func (handler *inputHandler) CreateInput(ctx context.Context, in *model.Input) (
return model.Input{}, err
}

for _, a := range in.Audio {
err := handler.store.CreateAudioProfile(ctx, db.CreateAudioProfileParams{
InputID: input.ID,
Rate: pgtype.Int4{Int32: int32(a.Rate), Valid: true},
Codec: a.Codec,
})

if err != nil {
return model.Input{}, err
}
}

for _, v := range in.Video {
err := handler.store.CreateVideoProfile(ctx, db.CreateVideoProfileParams{
InputID: input.ID,
Width: pgtype.Int4{Int32: int32(v.Width), Valid: true},
Height: pgtype.Int4{Int32: int32(v.Height), Valid: true},
Codec: v.Codec,
MaxKeyInterval: pgtype.Int4{Int32: int32(v.MaxKeyInterval), Valid: true},
Framerate: pgtype.Int4{Int32: int32(v.Framerate), Valid: true},
Bitrate: pgtype.Int4{Int32: int32(v.Bitrate), Valid: true},
})

if err != nil {
return model.Input{}, err
}
}

return model.Input{
ID: input.ID,
Name: input.Name,
Expand Down
20 changes: 20 additions & 0 deletions query.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,23 @@ SELECT * FROM inputs WHERE id = $1;

-- name: DeleteInput :exec
DELETE FROM inputs WHERE id = $1;

-- name: CreateVideoProfile :exec
INSERT INTO video_profiles (input_id, codec, bitrate, max_key_interval, framerate, width, height)
VALUES ($1, $2, $3, $4, $5, $6, $7);

-- name: GetVideoProfiles :many
SELECT * FROM video_profiles WHERE input_id = $1;

-- name: DeleteVideoProfiles :exec
DELETE FROM video_profiles WHERE input_id = $1;

-- name: CreateAudioProfile :exec
INSERT INTO audio_profiles (input_id, rate, codec)
VALUES ($1, $2, $3);

-- name: GetAudioProfiles :many
SELECT * FROM audio_profiles WHERE input_id = $1;

-- name: DeleteAudioProfiles :exec
DELETE FROM audio_profiles WHERE input_id = $1;
26 changes: 23 additions & 3 deletions schema.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
CREATE TABLE inputs (
id uuid PRIMARY KEY,
name text NOT NULL,
format text NOT NULL
id UUID PRIMARY KEY,
name TEXT NOT NULL,
format TEXT NOT NULL
);

CREATE TABLE audio_profiles (
id SERIAL PRIMARY KEY,
input_id UUID NOT NULL,
rate INT,
codec TEXT NOT NULL,
FOREIGN KEY (input_id) REFERENCES inputs(id)
);

CREATE TABLE video_profiles (
id SERIAL PRIMARY KEY,
input_id UUID NOT NULL,
codec TEXT NOT NULL,
bitrate INT,
max_key_interval INT,
framerate INT,
width INT,
height INT,
FOREIGN KEY (input_id) REFERENCES inputs(id)
);

0 comments on commit 076b7bd

Please sign in to comment.