Skip to content

Commit

Permalink
feat(forum): Add last post to forum item
Browse files Browse the repository at this point in the history
  • Loading branch information
aXenDeveloper committed Mar 2, 2024
1 parent 7187c1a commit 1c6c473
Show file tree
Hide file tree
Showing 19 changed files with 293 additions and 56 deletions.
1 change: 0 additions & 1 deletion backend/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ type LastChildShowForumForums {
}

type LastPostsShowForumForums {
content: [TextLanguage!]!
created: Int!
id: Int!
topic: TopicLastPostsShowForumForums!
Expand Down
11 changes: 11 additions & 0 deletions backend/src/apps/admin/forum/forums/create/create.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ export class CreateForumForumsService {
total_posts: 0,
total_topics: 0
},
last_posts: {
edges: [],
pageInfo: {
count: 0,
totalCount: 0,
hasNextPage: false,
hasPreviousPage: false,
startCursor: null,
endCursor: null
}
},
children: []
};
}
Expand Down
29 changes: 26 additions & 3 deletions backend/src/apps/admin/forum/forums/edit/edit.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import {
} from "../../database/schema/forums";
import { TextLanguageInput } from "@/types/database/text-language.type";
import { StatsShowForumForumsService } from "@/apps/forum/forums/show/stats.service";
import { LastPostsForumForumsService } from "@/apps/forum/forums/show/last_posts/last_posts.service";

@Injectable()
export class EditForumForumsService {
constructor(
private databaseService: DatabaseService,
private statsService: StatsShowForumForumsService
private statsService: StatsShowForumForumsService,
private lastPostsService: LastPostsForumForumsService
) {}

protected updateName = async ({
Expand Down Expand Up @@ -244,19 +246,40 @@ export class EditForumForumsService {
}
});

const stats = await this.statsService.stats({ forumId: id });
const { stats, topic_ids } = await this.statsService.topicsPosts({
forumId: id
});
const last_posts = await this.lastPostsService.lastPosts({
topicIds: topic_ids,
first: null,
cursor: null,
last: null,
sortBy: null
});

return {
...dataUpdate,
last_posts,
_count: {
...stats
},
children: await Promise.all(
children.map(async item => {
const stats = await this.statsService.stats({ forumId: item.id });
const { stats, topic_ids } = await this.statsService.topicsPosts({
forumId: item.id
});

const last_posts = await this.lastPostsService.lastPosts({
topicIds: topic_ids,
first: null,
cursor: null,
last: null,
sortBy: null
});

return {
...item,
last_posts,
children: [],
_count: {
...stats
Expand Down
6 changes: 5 additions & 1 deletion backend/src/apps/forum/forums/forums.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import { LastPostsForumForumsService } from "./show/last_posts/last_posts.servic
StatsShowForumForumsService,
LastPostsForumForumsService
],
exports: [ShowForumForumsService, StatsShowForumForumsService]
exports: [
ShowForumForumsService,
StatsShowForumForumsService,
LastPostsForumForumsService
]
})
export class ForumsForumModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ export class LastPostsShowForumForums {
@Field(() => User)
user: User;

@Field(() => [TextLanguage])
content: TextLanguage[];

@Field(() => TopicLastPostsShowForumForums)
topic: TopicLastPostsShowForumForums;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export class LastPostsForumForumsService {
title: true
}
},
content: true,
user: {
with: {
group: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ const getData = async ({ id }: { id: string }) => {
query: Forum_Forums__Show_Item,
variables: {
forumId: getIdFormString(id),
first: 25
first: 25,
lastPostsArgs: {
first: 1
}
},
cache: "force-cache",
next: {
Expand Down
5 changes: 5 additions & 0 deletions frontend/app/[locale]/(apps)/(main)/(container)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ const getData = async () => {
Forum_Forums__ShowQueryVariables
>({
query: Forum_Forums__Show,
variables: {
lastPostsArgs: {
first: 1
}
},
cache: "force-cache",
next: {
tags: ["Forum_Forums__Show"]
Expand Down
2 changes: 0 additions & 2 deletions frontend/app/[locale]/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

a {
@apply text-primary;
@apply underline;
@apply hover:no-underline;
@apply cursor-pointer;
}
}
Expand Down
92 changes: 72 additions & 20 deletions frontend/graphql/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ export type LastChildShowForumForums = {

export type LastPostsShowForumForums = {
__typename?: 'LastPostsShowForumForums';
content: Array<TextLanguage>;
created: Scalars['Int']['output'];
id: Scalars['Int']['output'];
topic: TopicLastPostsShowForumForums;
Expand Down Expand Up @@ -1528,20 +1527,23 @@ export type Admin__Forum_Forums__ShowQueryVariables = Exact<{

export type Admin__Forum_Forums__ShowQuery = { __typename?: 'Query', admin__forum_forums__show: { __typename?: 'ShowForumForumsAdminObj', edges: Array<{ __typename?: 'ShowForumForumsAdmin', id: number, position: number, created: number, description: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, name: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, children: Array<{ __typename?: 'ChildrenShowForumForums', created: number, id: number, position: number, description: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, name: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, _count: { __typename?: 'ShowForumForumsCounts', posts: number, topics: number, total_posts: number, total_topics: number } }>, permissions: { __typename?: 'PermissionsForumForumsAdmin', can_all_create: boolean, can_all_read: boolean, can_all_reply: boolean, can_all_view: boolean, groups: Array<{ __typename?: 'GroupsPermissionsForumForums', can_create: boolean, can_read: boolean, can_reply: boolean, can_view: boolean, id: number }> }, _count: { __typename?: 'ShowForumForumsCounts', posts: number, topics: number, total_posts: number, total_topics: number } }>, pageInfo: { __typename?: 'PageInfo', count: number, endCursor?: number | null, hasNextPage: boolean, hasPreviousPage: boolean, startCursor?: number | null, totalCount: number } } };

export type Forum_Forums__ShowQueryVariables = Exact<{ [key: string]: never; }>;
export type Forum_Forums__ShowQueryVariables = Exact<{
lastPostsArgs?: InputMaybe<LastPostsShowForumForumsArgs>;
}>;


export type Forum_Forums__ShowQuery = { __typename?: 'Query', forum_forums__show: { __typename?: 'ShowForumForumsObj', edges: Array<{ __typename?: 'ShowForumForumsWithChildren', id: number, description: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, name: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, children: Array<{ __typename?: 'ChildrenShowForumForums', id: number, name: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, children: Array<{ __typename?: 'LastChildShowForumForums', id: number, name: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }> }>, description: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, _count: { __typename?: 'ShowForumForumsCounts', total_posts: number, total_topics: number, topics: number, posts: number } }>, _count: { __typename?: 'ShowForumForumsCounts', total_posts: number, total_topics: number, topics: number, posts: number } }> } };
export type Forum_Forums__ShowQuery = { __typename?: 'Query', forum_forums__show: { __typename?: 'ShowForumForumsObj', edges: Array<{ __typename?: 'ShowForumForumsWithChildren', id: number, description: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, name: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, children: Array<{ __typename?: 'ChildrenShowForumForums', id: number, name: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, children: Array<{ __typename?: 'LastChildShowForumForums', id: number, name: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }> }>, description: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, _count: { __typename?: 'ShowForumForumsCounts', total_posts: number, total_topics: number, topics: number, posts: number }, last_posts: { __typename?: 'LastPostsShowForumForumsObj', edges: Array<{ __typename?: 'LastPostsShowForumForums', id: number, created: number, user: { __typename?: 'User', avatar_color: string, id: number, name: string, name_seo: string, avatar?: { __typename?: 'AvatarUser', dir_folder: string, id: number, name: string } | null, group: { __typename?: 'GroupUser', id: number, name: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }> } }, topic: { __typename?: 'TopicLastPostsShowForumForums', id: number, title: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }> } }> } }> }> } };

export type Forum_Forums__Show_ItemQueryVariables = Exact<{
cursor?: InputMaybe<Scalars['Int']['input']>;
first?: InputMaybe<Scalars['Int']['input']>;
last?: InputMaybe<Scalars['Int']['input']>;
forumId: Scalars['Int']['input'];
lastPostsArgs?: InputMaybe<LastPostsShowForumForumsArgs>;
}>;


export type Forum_Forums__Show_ItemQuery = { __typename?: 'Query', forum_forums__show: { __typename?: 'ShowForumForumsObj', edges: Array<{ __typename?: 'ShowForumForumsWithChildren', id: number, description: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, name: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, children: Array<{ __typename?: 'ChildrenShowForumForums', id: number, name: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, children: Array<{ __typename?: 'LastChildShowForumForums', id: number, name: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }> }>, description: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, _count: { __typename?: 'ShowForumForumsCounts', total_posts: number, total_topics: number, topics: number, posts: number } }>, permissions: { __typename?: 'PermissionsForumForums', can_create: boolean }, _count: { __typename?: 'ShowForumForumsCounts', total_posts: number, total_topics: number, topics: number, posts: number } }> }, forum_topics__show: { __typename?: 'ShowTopicsForumsObj', edges: Array<{ __typename?: 'ShowTopicsForums', created: number, id: number, locked: boolean, title: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, user: { __typename?: 'User', id: number, name_seo: string, name: string, avatar_color: string, avatar?: { __typename?: 'AvatarUser', id: number, dir_folder: string, name: string } | null, group: { __typename?: 'GroupUser', id: number, name: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }> } }, content: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, forum: { __typename?: 'ForumTopicsForums', id: number, name: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }> } }>, pageInfo: { __typename?: 'PageInfo', count: number, endCursor?: number | null, hasNextPage: boolean, hasPreviousPage: boolean, startCursor?: number | null, totalCount: number } } };
export type Forum_Forums__Show_ItemQuery = { __typename?: 'Query', forum_forums__show: { __typename?: 'ShowForumForumsObj', edges: Array<{ __typename?: 'ShowForumForumsWithChildren', id: number, description: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, name: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, children: Array<{ __typename?: 'ChildrenShowForumForums', id: number, name: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, children: Array<{ __typename?: 'LastChildShowForumForums', id: number, name: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }> }>, description: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, _count: { __typename?: 'ShowForumForumsCounts', total_posts: number, total_topics: number, topics: number, posts: number }, last_posts: { __typename?: 'LastPostsShowForumForumsObj', edges: Array<{ __typename?: 'LastPostsShowForumForums', created: number, id: number, user: { __typename?: 'User', avatar_color: string, id: number, name: string, name_seo: string, avatar?: { __typename?: 'AvatarUser', dir_folder: string, id: number, name: string } | null, group: { __typename?: 'GroupUser', id: number, name: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }> } }, topic: { __typename?: 'TopicLastPostsShowForumForums', id: number, title: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }> } }> } }>, permissions: { __typename?: 'PermissionsForumForums', can_create: boolean } }> }, forum_topics__show: { __typename?: 'ShowTopicsForumsObj', edges: Array<{ __typename?: 'ShowTopicsForums', created: number, id: number, locked: boolean, title: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, user: { __typename?: 'User', id: number, name_seo: string, name: string, avatar_color: string, avatar?: { __typename?: 'AvatarUser', id: number, dir_folder: string, name: string } | null, group: { __typename?: 'GroupUser', id: number, name: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }> } }, content: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }>, forum: { __typename?: 'ForumTopicsForums', id: number, name: Array<{ __typename?: 'TextLanguage', language_code: string, value: string }> } }>, pageInfo: { __typename?: 'PageInfo', count: number, endCursor?: number | null, hasNextPage: boolean, hasPreviousPage: boolean, startCursor?: number | null, totalCount: number } } };

export type Forum_Forums__Show_Item_MoreQueryVariables = Exact<{
cursor?: InputMaybe<Scalars['Int']['input']>;
Expand Down Expand Up @@ -2561,8 +2563,8 @@ export const Admin__Forum_Forums__Show = gql`
}
`;
export const Forum_Forums__Show = gql`
query Forum_forums__show {
forum_forums__show {
query Forum_forums__show($lastPostsArgs: LastPostsShowForumForumsArgs) {
forum_forums__show(last_posts_args: $lastPostsArgs) {
edges {
id
description {
Expand Down Expand Up @@ -2596,20 +2598,45 @@ export const Forum_Forums__Show = gql`
topics
posts
}
}
_count {
total_posts
total_topics
topics
posts
last_posts {
edges {
id
user {
avatar {
dir_folder
id
name
}
avatar_color
group {
id
name {
language_code
value
}
}
id
name
name_seo
}
topic {
id
title {
language_code
value
}
}
created
}
}
}
}
}
}
`;
export const Forum_Forums__Show_Item = gql`
query Forum_forums__show_item($cursor: Int, $first: Int, $last: Int, $forumId: Int!) {
forum_forums__show(ids: [$forumId]) {
query Forum_forums__show_item($cursor: Int, $first: Int, $last: Int, $forumId: Int!, $lastPostsArgs: LastPostsShowForumForumsArgs) {
forum_forums__show(ids: [$forumId], last_posts_args: $lastPostsArgs) {
edges {
id
description {
Expand Down Expand Up @@ -2643,16 +2670,41 @@ export const Forum_Forums__Show_Item = gql`
topics
posts
}
last_posts {
edges {
created
id
user {
avatar {
dir_folder
id
name
}
avatar_color
group {
id
name {
language_code
value
}
}
id
name
name_seo
}
topic {
id
title {
language_code
value
}
}
}
}
}
permissions {
can_create
}
_count {
total_posts
total_topics
topics
posts
}
}
}
forum_topics__show(
Expand Down
41 changes: 33 additions & 8 deletions frontend/graphql/queries/forum/forum_forums__show.gql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query Forum_forums__show {
forum_forums__show {
query Forum_forums__show($lastPostsArgs: LastPostsShowForumForumsArgs) {
forum_forums__show(last_posts_args: $lastPostsArgs) {
edges {
id
description {
Expand Down Expand Up @@ -33,12 +33,37 @@ query Forum_forums__show {
topics
posts
}
}
_count {
total_posts
total_topics
topics
posts
last_posts {
edges {
id
user {
avatar {
dir_folder
id
name
}
avatar_color
group {
id
name {
language_code
value
}
}
id
name
name_seo
}
topic {
id
title {
language_code
value
}
}
created
}
}
}
}
}
Expand Down
Loading

0 comments on commit 1c6c473

Please sign in to comment.