mirror of
https://github.com/Damillora/Shioriko.git
synced 2024-11-22 04:17:33 +00:00
feat: default tag
This commit is contained in:
parent
ee9d2c80bf
commit
44eebcedfb
@ -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())
|
||||
}
|
||||
|
@ -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"`
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -62,8 +62,6 @@
|
||||
{#each post.tags as tag (tag)}
|
||||
<TagLink {tag} />
|
||||
{/each}
|
||||
{:else}
|
||||
None
|
||||
{/if}
|
||||
</p>
|
||||
</div>
|
||||
|
@ -121,7 +121,7 @@
|
||||
<TagLink {tag} />
|
||||
{/each}
|
||||
{:else}
|
||||
None
|
||||
<TagLink tag="tagme" />
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user