Skip to content

Commit 272f23b

Browse files
committed
feat: โœจ follow list pagination ๊ตฌํ˜„
- #406 revert: ๐Ÿ”ฅ ์ž„์‹œ ํ•จ์ˆ˜ ์‚ญ์ œ ๋ฐ ์ฃผ์„ ์‚ญ์ œ - #406
1 parent 9c2d09f commit 272f23b

File tree

7 files changed

+282
-87
lines changed

7 files changed

+282
-87
lines changed

โ€Žapp/src/follow/db/follow.database.schema.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ import { HydratedDocument } from 'mongoose';
33

44
export type UserDocument = HydratedDocument<follow>;
55

6-
@Schema()
6+
@Schema({ collection: 'follows' })
77
export class follow {
88
@Prop({ required: true })
99
userId: number;
1010

1111
@Prop({ required: true })
1212
followId: number;
13+
14+
@Prop({ required: true })
15+
followAt: Date;
1316
}
1417

1518
export const FollowSchema = SchemaFactory.createForClass(follow);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { ArgsType, Field, registerEnumType } from '@nestjs/graphql';
2+
import { PaginationCursorArgs } from 'src/pagination/cursor/dtos/pagination.cursor.dto';
3+
4+
export enum FollowSortOrder {
5+
FOLLOW_AT_ASC,
6+
FOLLOW_AT_DESC,
7+
}
8+
9+
registerEnumType(FollowSortOrder, { name: 'FollowSortOrder' });
10+
11+
@ArgsType()
12+
export class FollowListPaginatedArgs extends PaginationCursorArgs {
13+
@Field()
14+
target: string;
15+
16+
@Field((_type) => FollowSortOrder, {
17+
defaultValue: FollowSortOrder.FOLLOW_AT_DESC,
18+
})
19+
sortOrder: FollowSortOrder;
20+
}

โ€Žapp/src/follow/follow.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Module } from '@nestjs/common';
22
import { MongooseModule } from '@nestjs/mongoose';
33
import { CursusUserModule } from 'src/api/cursusUser/cursusUser.module';
4+
import { PaginationCursorModule } from 'src/pagination/cursor/pagination.cursor.module';
45
import { FollowSchema, follow } from './db/follow.database.schema';
56
import { FollowResolver } from './follow.resolve';
67
import { FollowService } from './follow.service';
@@ -9,6 +10,7 @@ import { FollowService } from './follow.service';
910
imports: [
1011
MongooseModule.forFeature([{ name: follow.name, schema: FollowSchema }]),
1112
CursusUserModule,
13+
PaginationCursorModule,
1214
],
1315
providers: [FollowResolver, FollowService],
1416
})

โ€Žapp/src/follow/follow.resolve.ts

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@ import { PubSub } from 'graphql-subscriptions';
44
import { MyUserId } from 'src/auth/myContext';
55
import { StatAuthGuard } from 'src/auth/statAuthGuard';
66
import { HttpExceptionFilter } from 'src/http-exception.filter';
7+
import {
8+
FollowListPaginatedArgs,
9+
FollowSortOrder,
10+
} from './dto/follow.dto.getFollowList';
711
import { FollowService } from './follow.service';
8-
import { FollowListWithCount, FollowResult } from './model/follow.model';
12+
import {
13+
FollowListPaginated,
14+
FollowListWithCount,
15+
FollowResult,
16+
} from './model/follow.model';
917

1018
const pubSub = new PubSub();
1119

@@ -24,17 +32,6 @@ export class FollowResolver {
2432
return pubSub.asyncIterator('followUpdated');
2533
}
2634

27-
@Mutation((_returns) => FollowResult, {
28-
description: 'ํ”„๋ก ํŠธ ํ…Œ์ŠคํŠธ์šฉ ์ž„์‹œ ํ•จ์ˆ˜',
29-
})
30-
async MakeFollow(
31-
@Args('to') to: string,
32-
@Args('from') from: string,
33-
@Args('type') type: 'follow' | 'unfollow',
34-
): Promise<typeof FollowResult> {
35-
return await this.followService.MakeFollowUser(to, from, type);
36-
}
37-
3835
@UseGuards(StatAuthGuard)
3936
@Mutation((_returns) => FollowResult)
4037
async followUser(
@@ -71,37 +68,65 @@ export class FollowResolver {
7168
@MyUserId() userId: number,
7269
@Args('target') target: string,
7370
@Args('limit', { defaultValue: 3 }) limit: number,
71+
@Args('sortOrder', { type: () => FollowSortOrder })
72+
sortOrder: FollowSortOrder,
7473
): Promise<FollowListWithCount> {
75-
const followerList = await this.followService.getFollowerList(
74+
const targetId = await this.followService.userIdByLogin(target);
75+
const count = await this.followService.followerCount(targetId);
76+
77+
const followerList = await this.followService.followerList(
7678
userId,
7779
target,
7880
limit,
81+
sortOrder,
7982
);
80-
const count = await this.followService.getFollowerCount(target);
8183

8284
return {
8385
count,
8486
followList: followerList,
8587
};
8688
}
8789

90+
@UseGuards(StatAuthGuard)
91+
@Query((_returns) => FollowListPaginated)
92+
async getFollowerPaginated(
93+
@MyUserId() userId: number,
94+
@Args() args: FollowListPaginatedArgs,
95+
): Promise<FollowListPaginated> {
96+
return await this.followService.followerPaginated(userId, args);
97+
}
98+
8899
@UseGuards(StatAuthGuard)
89100
@Query((_returns) => FollowListWithCount)
90101
async getFollowingList(
91102
@MyUserId() userId: number,
92103
@Args('target') target: string,
93104
@Args('limit', { defaultValue: 3 }) limit: number,
105+
@Args('sortOrder', { type: () => FollowSortOrder })
106+
sortOrder: FollowSortOrder,
94107
): Promise<FollowListWithCount> {
95-
const followingList = await this.followService.getFollowingList(
108+
const targetId = await this.followService.userIdByLogin(target);
109+
const count = await this.followService.followingCount(targetId);
110+
111+
const followingList = await this.followService.followingList(
96112
userId,
97113
target,
98114
limit,
115+
sortOrder,
99116
);
100-
const count = await this.followService.getFollowingCount(target);
101117

102118
return {
103119
count,
104120
followList: followingList,
105121
};
106122
}
123+
124+
@UseGuards(StatAuthGuard)
125+
@Query((_returns) => FollowListPaginated)
126+
async getFollowingPaginated(
127+
@MyUserId() userId: number,
128+
@Args() args: FollowListPaginatedArgs,
129+
): Promise<FollowListPaginated> {
130+
return await this.followService.followingPaginated(userId, args);
131+
}
107132
}

0 commit comments

Comments
ย (0)