-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from Dobefu/feature/sync-assets
Feature/sync assets
- Loading branch information
Showing
4 changed files
with
145 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package assets | ||
|
||
import ( | ||
"github.com/Dobefu/csb/cmd/cs_sdk/structs" | ||
"github.com/Dobefu/csb/cmd/cs_sdk/utils" | ||
"github.com/Dobefu/csb/cmd/database/query" | ||
db_structs "github.com/Dobefu/csb/cmd/database/structs" | ||
) | ||
|
||
func SetAsset( | ||
route structs.Route, | ||
) error { | ||
err := query.Upsert("assets", getAssetValues(route)) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func getAssetValues(route structs.Route) []db_structs.QueryValue { | ||
return []db_structs.QueryValue{ | ||
{ | ||
Name: "id", | ||
Value: utils.GenerateId(route), | ||
}, | ||
{ | ||
Name: "uid", | ||
Value: route.Uid, | ||
}, | ||
{ | ||
Name: "title", | ||
Value: route.Title, | ||
}, | ||
{ | ||
Name: "content_type", | ||
Value: route.ContentType, | ||
}, | ||
{ | ||
Name: "locale", | ||
Value: route.Locale, | ||
}, | ||
{ | ||
Name: "slug", | ||
Value: route.Slug, | ||
}, | ||
{ | ||
Name: "url", | ||
Value: route.Url, | ||
}, | ||
{ | ||
Name: "parent", | ||
Value: route.Parent, | ||
}, | ||
{ | ||
Name: "updated_at", | ||
Value: route.UpdatedAt, | ||
}, | ||
{ | ||
Name: "published", | ||
Value: route.Published, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE IF EXISTS assets; |
12 changes: 12 additions & 0 deletions
12
cmd/migrate_db/migrations/000004_create_assets_table.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CREATE TABLE IF NOT EXISTS assets( | ||
id varchar(48) NOT NULL PRIMARY KEY UNIQUE, | ||
uid varchar(32) NOT NULL, | ||
title varchar(255) NOT NULL, | ||
content_type varchar(255) NOT NULL, | ||
locale varchar(16) NOT NULL, | ||
slug varchar(255) NOT NULL, | ||
url varchar(255) NOT NULL, | ||
parent varchar(64), | ||
updated_at timestamp NOT NULL, | ||
published boolean NOT NULL DEFAULT false | ||
); |