Skip to content

Commit

Permalink
feat: ✨ follow list pagination 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
niamu01 committed Dec 29, 2023
1 parent 7ceb414 commit 638c1cd
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 81 deletions.
5 changes: 4 additions & 1 deletion app/src/follow/db/follow.database.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import { HydratedDocument } from 'mongoose';

export type UserDocument = HydratedDocument<follow>;

@Schema()
@Schema({ collection: 'follows' })
export class follow {
@Prop({ required: true })
userId: number;

@Prop({ required: true })
followId: number;

@Prop({ required: true })
followAt: Date;
}

export const FollowSchema = SchemaFactory.createForClass(follow);
20 changes: 20 additions & 0 deletions app/src/follow/dto/follow.dto.getFollowList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ArgsType, Field, registerEnumType } from '@nestjs/graphql';
import { PaginationCursorArgs } from 'src/pagination/cursor/dtos/pagination.cursor.dto';

export enum FollowSortOrder {
FOLLOW_AT_ASC,
FOLLOW_AT_DESC,
}

registerEnumType(FollowSortOrder, { name: 'FollowSortOrder' });

@ArgsType()
export class FollowListPaginatedArgs extends PaginationCursorArgs {
@Field()
target: string;

@Field((_type) => FollowSortOrder, {
defaultValue: FollowSortOrder.FOLLOW_AT_DESC,
})
sortOrder: FollowSortOrder;
}
2 changes: 2 additions & 0 deletions app/src/follow/follow.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { CursusUserModule } from 'src/api/cursusUser/cursusUser.module';
import { PaginationCursorModule } from 'src/pagination/cursor/pagination.cursor.module';
import { FollowSchema, follow } from './db/follow.database.schema';
import { FollowResolver } from './follow.resolve';
import { FollowService } from './follow.service';
Expand All @@ -9,6 +10,7 @@ import { FollowService } from './follow.service';
imports: [
MongooseModule.forFeature([{ name: follow.name, schema: FollowSchema }]),
CursusUserModule,
PaginationCursorModule,
],
providers: [FollowResolver, FollowService],
})
Expand Down
52 changes: 35 additions & 17 deletions app/src/follow/follow.resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@ import { PubSub } from 'graphql-subscriptions';
import { MyUserId } from 'src/auth/myContext';
import { StatAuthGuard } from 'src/auth/statAuthGuard';
import { HttpExceptionFilter } from 'src/http-exception.filter';
import {
FollowListPaginatedArgs,
FollowSortOrder,
} from './dto/follow.dto.getFollowList';
import { FollowService } from './follow.service';
import { FollowListWithCount, FollowResult } from './model/follow.model';
import {
FollowList,
FollowListPaginated,
FollowResult,
} from './model/follow.model';

const pubSub = new PubSub();

Expand Down Expand Up @@ -66,42 +74,52 @@ export class FollowResolver {
}

@UseGuards(StatAuthGuard)
@Query((_returns) => FollowListWithCount)
@Query((_returns) => [FollowList])
async getFollowerList(
@MyUserId() userId: number,
@Args('target') target: string,
@Args('limit', { defaultValue: 3 }) limit: number,
): Promise<FollowListWithCount> {
const followerList = await this.followService.getFollowerList(
@Args('sortOrder') sortOrder: FollowSortOrder,
): Promise<FollowList[]> {
return await this.followService.followerList(
userId,
target,
limit,
sortOrder,
);
const count = await this.followService.getFollowerCount(target);
}

return {
count,
followList: followerList,
};
@UseGuards(StatAuthGuard)
@Query((_returns) => FollowListPaginated)
async getFollowerPaginated(
@MyUserId() userId: number,
@Args() args: FollowListPaginatedArgs,
): Promise<FollowListPaginated> {
return await this.followService.followerPaginated(userId, args);
}

@UseGuards(StatAuthGuard)
@Query((_returns) => FollowListWithCount)
@Query((_returns) => [FollowList])
async getFollowingList(
@MyUserId() userId: number,
@Args('target') target: string,
@Args('limit', { defaultValue: 3 }) limit: number,
): Promise<FollowListWithCount> {
const followingList = await this.followService.getFollowingList(
@Args('sortOrder') sortOrder: FollowSortOrder,
): Promise<FollowList[]> {
return await this.followService.followingList(
userId,
target,
limit,
sortOrder,
);
const count = await this.followService.getFollowingCount(target);
}

return {
count,
followList: followingList,
};
@UseGuards(StatAuthGuard)
@Query((_returns) => FollowListPaginated)
async getFollowingPaginated(
@MyUserId() userId: number,
@Args() args: FollowListPaginatedArgs,
): Promise<FollowListPaginated> {
return await this.followService.followingPaginated(userId, args);
}
}
Loading

0 comments on commit 638c1cd

Please sign in to comment.