diff --git a/pkg/database/main.go b/pkg/database/main.go index 624ebe3..cf9c790 100644 --- a/pkg/database/main.go +++ b/pkg/database/main.go @@ -4,6 +4,7 @@ import ( "log" "github.com/Damillora/Shioriko/pkg/config" + "github.com/google/uuid" "gorm.io/gorm" "gorm.io/driver/postgres" @@ -29,6 +30,16 @@ func Initialize() { }) } + var tagme Tag + result = db.Where("name = ?", "tagme").First(&tagme) + if result.Error != nil { + db.Create(&Tag{ + ID: uuid.NewString(), + Name: "tagme", + TagType: general, + }) + } + if err != nil { log.Fatal("Unable to connect to database" + err.Error()) } diff --git a/pkg/models/create_update.go b/pkg/models/create_update.go index 177bdc5..f289685 100644 --- a/pkg/models/create_update.go +++ b/pkg/models/create_update.go @@ -29,10 +29,10 @@ type TagUpdateModel struct { type PostCreateModel struct { BlobID string `json:"blob_id" validate:"required"` SourceURL string `json:"source_url"` - Tags []string `json:"tags" validate:"required"` + Tags []string `json:"tags"` } type PostUpdateModel struct { SourceURL string `json:"source_url"` - Tags []string `json:"tags" validate:"required"` + Tags []string `json:"tags"` } diff --git a/pkg/services/post.go b/pkg/services/post.go index 88a268a..9e89445 100644 --- a/pkg/services/post.go +++ b/pkg/services/post.go @@ -41,7 +41,9 @@ func CreatePost(userID string, model models.PostCreateModel) (*database.Post, er if err != nil { return nil, err } - + if len(tags) == 0 { + database.DB.Where("name = ?", "tagme").Find(&tags) + } post := database.Post{ ID: uuid.NewString(), UserID: userID, @@ -61,6 +63,9 @@ func UpdatePost(id string, model models.PostUpdateModel) (*database.Post, error) if err != nil { return nil, err } + if len(tags) == 0 { + database.DB.Where("name = ?", "tagme").Find(&tags) + } var post database.Post result := database.DB.Preload("Tags").Where("id = ?", id).First(&post) diff --git a/web/app/src/routes/Post.svelte b/web/app/src/routes/Post.svelte index 500f14f..43f7d75 100644 --- a/web/app/src/routes/Post.svelte +++ b/web/app/src/routes/Post.svelte @@ -62,8 +62,6 @@ {#each post.tags as tag (tag)} {/each} - {:else} - None {/if}

diff --git a/web/app/src/routes/Posts.svelte b/web/app/src/routes/Posts.svelte index 16fcb67..e5171e4 100644 --- a/web/app/src/routes/Posts.svelte +++ b/web/app/src/routes/Posts.svelte @@ -115,15 +115,15 @@ -
- {#if post.tags} +
+ {#if post.tags} {#each post.tags as tag (tag)} {/each} - {:else} - None - {/if} -
+ {:else} + + {/if} +
{/each}