diff --git a/app/src/follow/dto/follow.dto.getFollowList.ts b/app/src/follow/dto/follow.dto.ts similarity index 87% rename from app/src/follow/dto/follow.dto.getFollowList.ts rename to app/src/follow/dto/follow.dto.ts index b33fb331..13158f96 100644 --- a/app/src/follow/dto/follow.dto.getFollowList.ts +++ b/app/src/follow/dto/follow.dto.ts @@ -9,7 +9,7 @@ export enum FollowSortOrder { registerEnumType(FollowSortOrder, { name: 'FollowSortOrder' }); @ArgsType() -export class FollowListPaginatedArgs extends PaginationIndexArgs { +export class FollowPaginatedArgs extends PaginationIndexArgs { @Field() targetId: number; diff --git a/app/src/follow/follow.cache.service.ts b/app/src/follow/follow.cache.service.ts index d9c077ff..df0604ee 100644 --- a/app/src/follow/follow.cache.service.ts +++ b/app/src/follow/follow.cache.service.ts @@ -1,7 +1,7 @@ import { CACHE_MANAGER } from '@nestjs/cache-manager'; import { Inject, Injectable } from '@nestjs/common'; import { CacheUtilService } from 'src/cache/cache.util.service'; -import { FollowListCacheType } from './model/follow.model'; +import { Follow } from './model/follow.model'; export const FOLLOW_LISTS = 'followLists'; @@ -19,7 +19,7 @@ export class FollowCacheService { }: { id: number; type: 'follower' | 'following'; - list: FollowListCacheType[]; + list: Follow[]; }): Promise { const key = `${id}:${type}:${FOLLOW_LISTS}`; @@ -28,15 +28,10 @@ export class FollowCacheService { await this.cacheUtilService.set(key, list, 0); } - async get( - userId: number, - type: 'follower' | 'following', - ): Promise { + async get(userId: number, type: 'follower' | 'following'): Promise { const key = `${userId}:${type}:${FOLLOW_LISTS}`; - const cachedData = await this.cacheUtilService.get( - key, - ); + const cachedData = await this.cacheUtilService.get(key); if (!cachedData) { return []; //todo: 흠,,, diff --git a/app/src/follow/follow.resolver.ts b/app/src/follow/follow.resolver.ts index eab08ae9..ee09a682 100644 --- a/app/src/follow/follow.resolver.ts +++ b/app/src/follow/follow.resolver.ts @@ -4,9 +4,9 @@ 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 } from './dto/follow.dto.getFollowList'; +import { FollowPaginatedArgs } from './dto/follow.dto'; import { FollowService } from './follow.service'; -import { FollowListPaginated, FollowSuccess } from './model/follow.model'; +import { FollowSuccess, MyFollowPaginated } from './model/follow.model'; const pubSub = new PubSub(); @@ -70,20 +70,20 @@ export class FollowResolver { } @UseGuards(StatAuthGuard) - @Query((_returns) => FollowListPaginated) + @Query((_returns) => MyFollowPaginated) async getFollowerPaginated( @MyUserId() userId: number, - @Args() args: FollowListPaginatedArgs, - ): Promise { + @Args() args: FollowPaginatedArgs, + ): Promise { return await this.followService.followerPaginated(userId, args); } @UseGuards(StatAuthGuard) - @Query((_returns) => FollowListPaginated) + @Query((_returns) => MyFollowPaginated) async getFollowingPaginated( @MyUserId() userId: number, - @Args() args: FollowListPaginatedArgs, - ): Promise { + @Args() args: FollowPaginatedArgs, + ): Promise { return await this.followService.followingPaginated(userId, args); } } diff --git a/app/src/follow/follow.service.ts b/app/src/follow/follow.service.ts index 8329e6db..b97f6147 100644 --- a/app/src/follow/follow.service.ts +++ b/app/src/follow/follow.service.ts @@ -10,16 +10,13 @@ import { } from 'src/database/mongoose/database.mongoose.query'; import { PaginationIndexService } from 'src/pagination/index/pagination.index.service'; import { follow } from './db/follow.database.schema'; -import { - FollowSortOrder, - type FollowListPaginatedArgs, -} from './dto/follow.dto.getFollowList'; +import { FollowSortOrder, type FollowPaginatedArgs } from './dto/follow.dto'; import { FollowCacheService } from './follow.cache.service'; import type { - FollowList, - FollowListCacheType, - FollowListPaginated, + Follow, FollowSuccess, + MyFollow, + MyFollowPaginated, } from './model/follow.model'; @Injectable() @@ -148,7 +145,7 @@ export class FollowService { targetId: number, sortOrder: FollowSortOrder, filter?: FilterQuery, - ): Promise { + ): Promise { const aggregate = this.followModel.aggregate(); const cachedFollowerList = await this.followCacheService.get( @@ -159,7 +156,7 @@ export class FollowService { if (cachedFollowerList.length) { return await this.checkFollowing({ userId, - cachedFollowList: cachedFollowerList, + followList: cachedFollowerList, }); } @@ -174,7 +171,7 @@ export class FollowService { const followerList = await this.checkFollowing({ userId, - cachedFollowList: followerUserPreview, + followList: followerUserPreview, }); await this.followCacheService.set({ @@ -188,11 +185,11 @@ export class FollowService { async followerPaginated( userId: number, - { pageNumber, pageSize, targetId, sortOrder }: FollowListPaginatedArgs, - ): Promise { + { pageNumber, pageSize, targetId, sortOrder }: FollowPaginatedArgs, + ): Promise { const followList = await this.followerList(userId, targetId, sortOrder); - return this.paginationIndexService.toPaginated(followList, { + return this.paginationIndexService.toPaginated(followList, { pageNumber, pageSize, }); @@ -203,7 +200,7 @@ export class FollowService { targetId: number, sortOrder: FollowSortOrder, filter?: FilterQuery, - ): Promise { + ): Promise { const aggregate = this.followModel.aggregate(); const cachedFollowingList = await this.followCacheService.get( @@ -214,7 +211,7 @@ export class FollowService { if (cachedFollowingList.length) { const followingList = await this.checkFollowing({ userId, - cachedFollowList: cachedFollowingList, + followList: cachedFollowingList, }); if (sortOrder === FollowSortOrder.FOLLOW_AT_ASC) { @@ -241,7 +238,7 @@ export class FollowService { const followingList = await this.checkFollowing({ userId, - cachedFollowList: followingUserPreview, + followList: followingUserPreview, }); await this.followCacheService.set({ @@ -255,11 +252,11 @@ export class FollowService { async followingPaginated( userId: number, - { pageNumber, pageSize, targetId, sortOrder }: FollowListPaginatedArgs, - ): Promise { + { pageNumber, pageSize, targetId, sortOrder }: FollowPaginatedArgs, + ): Promise { const followList = await this.followingList(userId, targetId, sortOrder); - return this.paginationIndexService.toPaginated(followList, { + return this.paginationIndexService.toPaginated(followList, { pageSize, pageNumber, }); @@ -289,7 +286,7 @@ export class FollowService { async followingListCache( targetId: number, sortOrder: FollowSortOrder, - ): Promise { + ): Promise { const following: Pick[] = await this.findAllAndLean({ filter: { userId: targetId }, @@ -327,7 +324,7 @@ export class FollowService { async followerListCache( targetId: number, sortOrder: FollowSortOrder, - ): Promise { + ): Promise { const follower: Pick[] = await this.findAllAndLean({ filter: { followId: targetId }, @@ -364,11 +361,11 @@ export class FollowService { async checkFollowing({ userId, - cachedFollowList, + followList, }: { userId: number; - cachedFollowList: FollowListCacheType[]; - }): Promise { + followList: Follow[]; + }): Promise { const followingList = await this.followCacheService.get( userId, 'following', @@ -376,8 +373,8 @@ export class FollowService { const followingListIds = followingList.map((e) => e.userPreview.id); - const followList = Promise.all( - cachedFollowList.map(async (follow) => { + const myFollow = Promise.all( + followList.map(async (follow) => { const isFollowing = followingListIds.includes(follow.userPreview.id); return { @@ -388,7 +385,7 @@ export class FollowService { }), ); - return followList; + return myFollow; } } diff --git a/app/src/follow/model/follow.model.ts b/app/src/follow/model/follow.model.ts index 4f814ce2..644a8d91 100644 --- a/app/src/follow/model/follow.model.ts +++ b/app/src/follow/model/follow.model.ts @@ -3,7 +3,7 @@ import { UserPreview } from 'src/common/models/common.user.model'; import { IndexPaginated } from 'src/pagination/index/models/pagination.index.model'; @ObjectType() -export class FollowList { +export class MyFollow { @Field() isFollowing: boolean; @@ -14,10 +14,10 @@ export class FollowList { followAt: Date; } -export type FollowListCacheType = Omit; +export type Follow = Omit; @ObjectType() -export class FollowListPaginated extends IndexPaginated(FollowList) {} +export class MyFollowPaginated extends IndexPaginated(MyFollow) {} @ObjectType() export class FollowSuccess { diff --git a/app/src/lambda/lambda.service.ts b/app/src/lambda/lambda.service.ts index af837aed..2855d04e 100644 --- a/app/src/lambda/lambda.service.ts +++ b/app/src/lambda/lambda.service.ts @@ -32,7 +32,7 @@ import { CacheUtilRankingService } from 'src/cache/cache.util.ranking.service'; import { CacheUtilService } from 'src/cache/cache.util.service'; import { DateRangeService } from 'src/dateRange/dateRange.service'; import { DateTemplate } from 'src/dateRange/dtos/dateRange.dto'; -import { FollowSortOrder } from 'src/follow/dto/follow.dto.getFollowList'; +import { FollowSortOrder } from 'src/follow/dto/follow.dto'; import { FollowCacheService } from 'src/follow/follow.cache.service'; import { FollowService } from 'src/follow/follow.service'; diff --git a/app/src/schema.gql b/app/src/schema.gql index 5ac53762..9149aafc 100644 --- a/app/src/schema.gql +++ b/app/src/schema.gql @@ -59,14 +59,14 @@ type UserRankingIndexPaginated { pageNumber: Int! } -type FollowList { +type MyFollow { isFollowing: Boolean! userPreview: UserPreview! followAt: DateTime! } -type FollowListPaginated { - nodes: [FollowList!]! +type MyFollowPaginated { + nodes: [MyFollow!]! totalCount: Int! pageSize: Int! pageNumber: Int! @@ -640,8 +640,8 @@ type Query { getSetting: Setting! getExpTable: [ExpTable!]! getIsFollowing(targetId: Int!): Boolean! - getFollowerPaginated(pageSize: Int! = 10, pageNumber: Int! = 1, targetId: Int!, sortOrder: FollowSortOrder! = FOLLOW_AT_DESC): FollowListPaginated! - getFollowingPaginated(pageSize: Int! = 10, pageNumber: Int! = 1, targetId: Int!, sortOrder: FollowSortOrder! = FOLLOW_AT_DESC): FollowListPaginated! + getFollowerPaginated(pageSize: Int! = 10, pageNumber: Int! = 1, targetId: Int!, sortOrder: FollowSortOrder! = FOLLOW_AT_DESC): MyFollowPaginated! + getFollowingPaginated(pageSize: Int! = 10, pageNumber: Int! = 1, targetId: Int!, sortOrder: FollowSortOrder! = FOLLOW_AT_DESC): MyFollowPaginated! } enum EvalLogSortOrder {