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,
|
ImagePath: "/data/" + post.Blob.FilePath,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
tagObjs := services.GetTagFilter(tagStrings)
|
tagObjs := services.GetTagFilterString(tagStrings)
|
||||||
|
|
||||||
c.JSON(http.StatusOK, models.PostPaginationResponse{
|
c.JSON(http.StatusOK, models.PostPaginationResponse{
|
||||||
CurrentPage: page,
|
CurrentPage: page,
|
||||||
@ -90,17 +90,15 @@ func postGetOne(c *gin.Context) {
|
|||||||
Message: err.Error(),
|
Message: err.Error(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
var tagStrings []string
|
|
||||||
for _, tag := range post.Tags {
|
tagObjs := services.GetTagFilter(post.Tags)
|
||||||
tagStrings = append(tagStrings, tag.TagType.Name+":"+tag.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, models.PostReadModel{
|
c.JSON(http.StatusOK, models.PostReadModel{
|
||||||
ID: post.ID,
|
ID: post.ID,
|
||||||
ImagePreviewPath: "/data/" + post.Blob.PreviewFilePath,
|
ImagePreviewPath: "/data/" + post.Blob.PreviewFilePath,
|
||||||
ImagePath: "/data/" + post.Blob.FilePath,
|
ImagePath: "/data/" + post.Blob.FilePath,
|
||||||
SourceURL: post.SourceURL,
|
SourceURL: post.SourceURL,
|
||||||
Tags: tagStrings,
|
Tags: tagObjs,
|
||||||
Width: post.Blob.Width,
|
Width: post.Blob.Width,
|
||||||
Height: post.Blob.Height,
|
Height: post.Blob.Height,
|
||||||
Uploader: post.User.Username,
|
Uploader: post.User.Username,
|
||||||
|
@ -5,7 +5,7 @@ type PostReadModel struct {
|
|||||||
ImagePreviewPath string `json:"preview_path"`
|
ImagePreviewPath string `json:"preview_path"`
|
||||||
ImagePath string `json:"image_path"`
|
ImagePath string `json:"image_path"`
|
||||||
SourceURL string `json:"source_url"`
|
SourceURL string `json:"source_url"`
|
||||||
Tags []string `json:"tags"`
|
Tags []TagListItem `json:"tags"`
|
||||||
Width int `json:"width"`
|
Width int `json:"width"`
|
||||||
Height int `json:"height"`
|
Height int `json:"height"`
|
||||||
Uploader string `json:"uploader"`
|
Uploader string `json:"uploader"`
|
||||||
|
@ -21,8 +21,12 @@ func GetTagAll() []models.TagListItem {
|
|||||||
return tags
|
return tags
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTagFilter(tagString []string) []models.TagListItem {
|
func GetTagFilterString(tagString []string) []models.TagListItem {
|
||||||
tagObjs, _ := ParseReadTags(tagString)
|
tagObjs, _ := ParseReadTags(tagString)
|
||||||
|
return GetTagFilter(tagObjs)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetTagFilter(tagObjs []database.Tag) []models.TagListItem {
|
||||||
var tagIds []string
|
var tagIds []string
|
||||||
for _, val := range tagObjs {
|
for _, val := range tagObjs {
|
||||||
tagIds = append(tagIds, val.ID)
|
tagIds = append(tagIds, val.ID)
|
||||||
@ -38,7 +42,6 @@ func GetTagFilter(tagString []string) []models.TagListItem {
|
|||||||
Find(&tags, tagIds)
|
Find(&tags, tagIds)
|
||||||
return tags
|
return tags
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetTagAutocomplete() []string {
|
func GetTagAutocomplete() []string {
|
||||||
var tags []string
|
var tags []string
|
||||||
result := database.DB.Model(&database.Tag{}).
|
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>
|
<script>
|
||||||
import AuthCheck from "./AuthCheck.svelte";
|
import AuthCheck from "./AuthCheck.svelte";
|
||||||
import TagLink from "./TagLink.svelte";
|
import TagLinkNumbered from "./TagLinkNumbered.svelte";
|
||||||
export let post;
|
export let post;
|
||||||
export let toggleEditMenu;
|
export let toggleEditMenu;
|
||||||
export let toggleDeleteMenu;
|
export let toggleDeleteMenu;
|
||||||
@ -55,7 +55,11 @@
|
|||||||
{#if post.tags}
|
{#if post.tags}
|
||||||
{#each post.tags as tag (tag)}
|
{#each post.tags as tag (tag)}
|
||||||
<li>
|
<li>
|
||||||
<TagLink class="" {tag} />
|
<TagLinkNumbered
|
||||||
|
class=""
|
||||||
|
tag={tag.tagType + ":" + tag.tagName}
|
||||||
|
num={tag.postCount}
|
||||||
|
/>
|
||||||
</li>
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
{/if}
|
{/if}
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
<script>
|
<script>
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import TagLink from "../TagLink.svelte";
|
import { getPost, postDelete } from "../api.js";
|
||||||
import { getPost, postCreate, postDelete } from "../api.js";
|
import { navigate } from "svelte-routing";
|
||||||
import { Link, navigate } from "svelte-routing";
|
|
||||||
import EditPostPanel from "../EditPostPanel.svelte";
|
import EditPostPanel from "../EditPostPanel.svelte";
|
||||||
import ViewPostPanel from "../ViewPostPanel.svelte";
|
import ViewPostPanel from "../ViewPostPanel.svelte";
|
||||||
export let id;
|
export let id;
|
||||||
|
Loading…
Reference in New Issue
Block a user