mirror of
https://github.com/Damillora/Shioriko.git
synced 2024-11-22 04:17:33 +00:00
feat: add tag count to post detail as well
This commit is contained in:
parent
e73d3d0dda
commit
36db313d33
@ -70,7 +70,7 @@ func postGet(c *gin.Context) {
|
||||
ImagePath: "/data/" + post.Blob.FilePath,
|
||||
})
|
||||
}
|
||||
tagObjs := services.GetTagFilter(tagStrings)
|
||||
tagObjs := services.GetTagFilterString(tagStrings)
|
||||
|
||||
c.JSON(http.StatusOK, models.PostPaginationResponse{
|
||||
CurrentPage: page,
|
||||
@ -90,17 +90,15 @@ func postGetOne(c *gin.Context) {
|
||||
Message: err.Error(),
|
||||
})
|
||||
}
|
||||
var tagStrings []string
|
||||
for _, tag := range post.Tags {
|
||||
tagStrings = append(tagStrings, tag.TagType.Name+":"+tag.Name)
|
||||
}
|
||||
|
||||
tagObjs := services.GetTagFilter(post.Tags)
|
||||
|
||||
c.JSON(http.StatusOK, models.PostReadModel{
|
||||
ID: post.ID,
|
||||
ImagePreviewPath: "/data/" + post.Blob.PreviewFilePath,
|
||||
ImagePath: "/data/" + post.Blob.FilePath,
|
||||
SourceURL: post.SourceURL,
|
||||
Tags: tagStrings,
|
||||
Tags: tagObjs,
|
||||
Width: post.Blob.Width,
|
||||
Height: post.Blob.Height,
|
||||
Uploader: post.User.Username,
|
||||
|
@ -5,7 +5,7 @@ type PostReadModel struct {
|
||||
ImagePreviewPath string `json:"preview_path"`
|
||||
ImagePath string `json:"image_path"`
|
||||
SourceURL string `json:"source_url"`
|
||||
Tags []string `json:"tags"`
|
||||
Tags []TagListItem `json:"tags"`
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
Uploader string `json:"uploader"`
|
||||
|
@ -21,8 +21,12 @@ func GetTagAll() []models.TagListItem {
|
||||
return tags
|
||||
}
|
||||
|
||||
func GetTagFilter(tagString []string) []models.TagListItem {
|
||||
func GetTagFilterString(tagString []string) []models.TagListItem {
|
||||
tagObjs, _ := ParseReadTags(tagString)
|
||||
return GetTagFilter(tagObjs)
|
||||
}
|
||||
|
||||
func GetTagFilter(tagObjs []database.Tag) []models.TagListItem {
|
||||
var tagIds []string
|
||||
for _, val := range tagObjs {
|
||||
tagIds = append(tagIds, val.ID)
|
||||
@ -38,7 +42,6 @@ func GetTagFilter(tagString []string) []models.TagListItem {
|
||||
Find(&tags, tagIds)
|
||||
return tags
|
||||
}
|
||||
|
||||
func GetTagAutocomplete() []string {
|
||||
var tags []string
|
||||
result := database.DB.Model(&database.Tag{}).
|
||||
|
@ -1,11 +0,0 @@
|
||||
<script>
|
||||
import { Link } from "svelte-routing";
|
||||
|
||||
export let tag;
|
||||
|
||||
let tagType = tag.split(":")[0] ?? "";
|
||||
let tagName = tag.split(":")[1] ?? "";
|
||||
let tagDisplay = tagName.split("_").join(" ");
|
||||
</script>
|
||||
|
||||
<Link to="/posts?tags={tagName}">{tagDisplay}</Link>
|
@ -1,6 +1,6 @@
|
||||
<script>
|
||||
import AuthCheck from "./AuthCheck.svelte";
|
||||
import TagLink from "./TagLink.svelte";
|
||||
import TagLinkNumbered from "./TagLinkNumbered.svelte";
|
||||
export let post;
|
||||
export let toggleEditMenu;
|
||||
export let toggleDeleteMenu;
|
||||
@ -55,7 +55,11 @@
|
||||
{#if post.tags}
|
||||
{#each post.tags as tag (tag)}
|
||||
<li>
|
||||
<TagLink class="" {tag} />
|
||||
<TagLinkNumbered
|
||||
class=""
|
||||
tag={tag.tagType + ":" + tag.tagName}
|
||||
num={tag.postCount}
|
||||
/>
|
||||
</li>
|
||||
{/each}
|
||||
{/if}
|
||||
|
@ -1,8 +1,7 @@
|
||||
<script>
|
||||
import { onMount } from "svelte";
|
||||
import TagLink from "../TagLink.svelte";
|
||||
import { getPost, postCreate, postDelete } from "../api.js";
|
||||
import { Link, navigate } from "svelte-routing";
|
||||
import { getPost, postDelete } from "../api.js";
|
||||
import { navigate } from "svelte-routing";
|
||||
import EditPostPanel from "../EditPostPanel.svelte";
|
||||
import ViewPostPanel from "../ViewPostPanel.svelte";
|
||||
export let id;
|
||||
|
Loading…
Reference in New Issue
Block a user