feat: default tag

This commit is contained in:
Damillora 2021-05-11 18:00:05 +07:00
parent ee9d2c80bf
commit 44eebcedfb
5 changed files with 25 additions and 11 deletions

View File

@ -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())
}

View File

@ -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"`
}

View File

@ -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)

View File

@ -62,8 +62,6 @@
{#each post.tags as tag (tag)}
<TagLink {tag} />
{/each}
{:else}
None
{/if}
</p>
</div>

View File

@ -121,7 +121,7 @@
<TagLink {tag} />
{/each}
{:else}
None
<TagLink tag="tagme" />
{/if}
</div>
</div>