Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ func main() {

e.GET("/demo/style.css", handler.Stylesheet)

e.GET("/v/:ulid", handler.Configuration)
e.GET("/v/:ulid", handler.GetConfiguration)
e.GET("/v/new", handler.GetConfiguration)

e.POST("/v/:ulid", handler.UpdateConfig)
e.GET("/v/new", handler.Configuration)
e.POST("/v/new", handler.IntroVideoCode)
e.POST("/v/config", handler.CreateConfig)

Expand All @@ -36,4 +37,3 @@ func main() {

e.Logger.Fatal(e.Start(":" + port))
}

1 change: 0 additions & 1 deletion db/migrations/1715450001_video.down.sql

This file was deleted.

9 changes: 0 additions & 9 deletions db/migrations/1715450001_video.up.sql

This file was deleted.

1 change: 0 additions & 1 deletion db/migrations/1715450002_instance.down.sql

This file was deleted.

6 changes: 0 additions & 6 deletions db/migrations/1715450002_instance.up.sql

This file was deleted.

27 changes: 0 additions & 27 deletions db/migrations/1722361838_configuration.down.sql

This file was deleted.

13 changes: 0 additions & 13 deletions db/migrations/1722361838_configuration.up.sql

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
CREATE TABLE `configurations` (
`id` INTEGER PRIMARY KEY NOT NULL,
`id` BLOB UNIQUE NOT NULL,
`theme` TEXT DEFAULT 'default',
`bubble_enabled` BOOLEAN DEFAULT false,
`bubble_text_content` TEXT,
`cta_enabled` BOOLEAN DEFAULT false,
`cta_text_content` TEXT
`cta_text_content` TEXT,
`video_url` TEXT
);

35 changes: 14 additions & 21 deletions db/migrations/schema.sql
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
CREATE TABLE schema_migrations (id VARCHAR(255) NOT NULL PRIMARY KEY);

--
-- LibSQL SQL Schema dump automatic generated by geni
--

CREATE TABLE schema_migrations (id VARCHAR(255) NOT NULL PRIMARY KEY)
CREATE TABLE `configurations` (
\t`id` integer PRIMARY KEY NOT NULL,
`bubble_enabled` boolean DEFAULT false,
`bubble_text_content` text,
`bubble_type` text DEFAULT 'default',
`cta_enabled` boolean DEFAULT false,
`cta_text_content` text,
`cta_type` text DEFAULT 'default'
);
CREATE TABLE `videos` (
\t`id` integer PRIMARY KEY NOT NULL,
`url` text NOT NULL,
`weight` integer DEFAULT 1,
`configuration_id` integer NOT NULL,
`instance_id` integer NOT NULL,
FOREIGN KEY(`configuration_id`) REFERENCES `configurations`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION,
FOREIGN KEY(`instance_id`) REFERENCES `instances`(`id`) ON UPDATE NO ACTION ON DELETE NO ACTION
);
CREATE TABLE `instances` (
\t`id` integer PRIMARY KEY NOT NULL
);
`id` BLOB UNIQUE NOT NULL,
`theme` TEXT DEFAULT 'default',
`bubble_enabled` BOOLEAN DEFAULT false,
`bubble_text_content` TEXT,
`cta_enabled` BOOLEAN DEFAULT false,
`cta_text_content` TEXT,
`video_url` TEXT
)
61 changes: 17 additions & 44 deletions internal/data/instance.go → internal/data/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,20 @@ package data

import (
"database/sql"
"os"
"fmt"
"os"

"github.com/crocoder-dev/intro-video/internal/config"
"github.com/joho/godotenv"
"github.com/oklog/ulid/v2"
_ "github.com/tursodatabase/libsql-client-go/libsql"
)

type Instance struct {
Id int32
ExternalId []byte
Videos map[int32]Video
Configurations map[int32]Configuration
}

type NewVideo struct {
Weight int32
URL string
}

type Video struct {
Id int32
Weight int32
ConfigurationId int32
URL string
}

type NewConfiguration struct {
VideoUrl string
Theme config.Theme
Bubble config.Bubble
Cta config.Cta
}

type Configuration struct {
Id []byte
Theme config.Theme
Bubble config.Bubble
Cta config.Cta
Id []byte
Theme config.Theme
Bubble config.Bubble
Cta config.Cta
VideoUrl string
}

Expand All @@ -61,7 +35,7 @@ func NewStore() (Store, error) {

}

func (s *Store) LoadConfig(id []byte) (Configuration, error) {
func (s *Store) LoadConfiguration(id []byte) (Configuration, error) {
db, err := sql.Open(s.DriverName, s.DatabaseUrl)
if err != nil {
return Configuration{}, err
Expand Down Expand Up @@ -113,7 +87,7 @@ func (s *Store) LoadConfig(id []byte) (Configuration, error) {
}

return Configuration{
Id: configId,
Id: configId,
Theme: config.Theme(theme),
Bubble: config.Bubble{
Enabled: bubbleEnabled,
Expand All @@ -127,7 +101,7 @@ func (s *Store) LoadConfig(id []byte) (Configuration, error) {
}, nil
}

func (s *Store) CreateConfiguration(configuration NewConfiguration) (Configuration, error) {
func (s *Store) CreateConfiguration(configuration Configuration) (Configuration, error) {
db, err := sql.Open(s.DriverName, s.DatabaseUrl)
if err != nil {
return Configuration{}, err
Expand Down Expand Up @@ -179,17 +153,17 @@ func (s *Store) CreateConfiguration(configuration NewConfiguration) (Configurati
}

newConfiguration := Configuration{
Id: configurationId,
Theme: configuration.Theme,
Bubble: config.Bubble{Enabled: configuration.Bubble.Enabled, TextContent: configuration.Bubble.TextContent},
Cta: config.Cta{Enabled: configuration.Cta.Enabled, TextContent: configuration.Cta.TextContent},
Id: configurationId,
Theme: configuration.Theme,
Bubble: config.Bubble{Enabled: configuration.Bubble.Enabled, TextContent: configuration.Bubble.TextContent},
Cta: config.Cta{Enabled: configuration.Cta.Enabled, TextContent: configuration.Cta.TextContent},
VideoUrl: configuration.VideoUrl,
}

return newConfiguration, nil
}

func (s *Store) UpdateConfiguration(id []byte, configuration NewConfiguration) (Configuration, error) {
func (s *Store) UpdateConfiguration(id []byte, configuration Configuration) (Configuration, error) {
db, err := sql.Open(s.DriverName, s.DatabaseUrl)
if err != nil {
return Configuration{}, err
Expand Down Expand Up @@ -232,13 +206,12 @@ func (s *Store) UpdateConfiguration(id []byte, configuration NewConfiguration) (
}

updatedConfiguration := Configuration{
Id: id,
Theme: configuration.Theme,
Bubble: config.Bubble{Enabled: configuration.Bubble.Enabled, TextContent: configuration.Bubble.TextContent},
Cta: config.Cta{Enabled: configuration.Cta.Enabled, TextContent: configuration.Cta.TextContent},
Id: id,
Theme: configuration.Theme,
Bubble: config.Bubble{Enabled: configuration.Bubble.Enabled, TextContent: configuration.Bubble.TextContent},
Cta: config.Cta{Enabled: configuration.Cta.Enabled, TextContent: configuration.Cta.TextContent},
VideoUrl: configuration.VideoUrl,
}

return updatedConfiguration, nil
}

Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestCreateConfiguration(t *testing.T) {

store := data.Store{DatabaseUrl: dbName, DriverName: "sqlite3"}

newConfiguration := data.NewConfiguration{
newConfiguration := data.Configuration{
Theme: config.DefaultTheme,
Bubble: config.Bubble{
Enabled: true,
Expand Down Expand Up @@ -153,7 +153,7 @@ func TestLoadConfiguration(t *testing.T) {

store := data.Store{DatabaseUrl: dbName, DriverName: "sqlite3"}

configuration, err := store.LoadConfig(binUlid)
configuration, err := store.LoadConfiguration(binUlid)
if err != nil {
t.Fatalf("failed to load instance: %v", err)
}
Expand Down Expand Up @@ -196,7 +196,7 @@ func TestUpdateConfiguration(t *testing.T) {

store := data.Store{DatabaseUrl: dbName, DriverName: "sqlite3"}

newConfiguration := data.NewConfiguration{
newConfiguration := data.Configuration{
Theme: config.DefaultTheme,
Bubble: config.Bubble{
Enabled: true,
Expand All @@ -214,7 +214,7 @@ func TestUpdateConfiguration(t *testing.T) {
t.Fatalf("failed to create instance: %v", err)
}

updatedConfiguration := data.NewConfiguration{
updatedConfiguration := data.Configuration{
Theme: config.ShadcnThemeDark,
Bubble: config.Bubble{
Enabled: false,
Expand All @@ -224,7 +224,7 @@ func TestUpdateConfiguration(t *testing.T) {
Enabled: false,
TextContent: "updated cta text",
},
VideoUrl: "updated url",
VideoUrl: "updated url",
}

expected := data.Configuration{
Expand All @@ -241,7 +241,6 @@ func TestUpdateConfiguration(t *testing.T) {
VideoUrl: "updated url",
}


newConfig, err := store.UpdateConfiguration(configuration.Id, updatedConfiguration)
if err != nil {
t.Fatalf("failed to update instance: %v", err)
Expand All @@ -250,4 +249,3 @@ func TestUpdateConfiguration(t *testing.T) {
t.Fatalf("Expected updated configuration %+v, got %+v", newConfig, expected)
}
}

Loading