Skip to content

Commit

Permalink
feat: โœจ FollowerList ์ถ”๊ฐ€
Browse files Browse the repository at this point in the history
- #405

feat: โœจ MakeFollow: ํ”„๋ก ํŠธ ํ…Œ์ŠคํŠธ์šฉ ์ž„์‹œ ํ•จ์ˆ˜ ์ถ”๊ฐ€

- #405

refactor: โ™ป๏ธ ๋ณ€์ˆ˜๋ช… ์ˆ˜์ • ๋ฐ ํ•จ์ˆ˜ ๋ถ„๋ฆฌ

login -> target, FollowListByMe -> FollowList, FollowUserList -> FollowListWithCount, followUser->followLser, cursusUserService์— ์œ ์ € ์•„์ด๋”” ์ฐพ๋Š” ํ•จ์ˆ˜ ์ถ”๊ฐ€, ์ค‘๋ณต๋˜๋Š” ํ•จ์ˆ˜ ๋ถ„๋ฆฌ

- #405

refactor: โ™ป๏ธ checkFollowingStatus ํ•จ์ˆ˜ ํ™œ์šฉํ•˜๋„๋ก ๋ณ€๊ฒฝ

- #405
  • Loading branch information
niamu01 committed Feb 20, 2024
1 parent ab0710f commit 23a8eb7
Show file tree
Hide file tree
Showing 6 changed files with 244 additions and 109 deletions.
43 changes: 43 additions & 0 deletions app/src/api/cursusUser/cursusUser.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ export class CursusUserService {
return this.cursusUserModel.aggregate<ReturnType>();
}

async getuserIdByLogin(login: string): Promise<number | null> {
const userId = await this.findOneAndLean({
filter: { 'user.login': login },
}).then((user) => user?.user.id);

if (!userId) {
return null;
}

return userId;
}

async findAllAndLean(
queryArgs?: QueryArgs<cursus_user>,
): Promise<cursus_user[]> {
Expand Down Expand Up @@ -116,6 +128,37 @@ export class CursusUserService {
}));
}

async findOneUserPreviewAndLean(
queryArgs?: Omit<QueryArgs<cursus_user>, 'select'>,
): Promise<UserPreview | null> {
const cursusUsers: {
user: {
id: number;
login: string;
image: {
link?: string;
};
};
} | null = await this.findOneAndLean({
...queryArgs,
select: {
'user.id': 1,
'user.login': 1,
'user.image.link': 1,
},
});

if (!cursusUsers) {
return null;
}

return {
id: cursusUsers.user.id,
login: cursusUsers.user.login,
imgUrl: cursusUsers.user.image.link,
};
}

async userFullProfile(
filter?: FilterQuery<cursus_user>,
): Promise<UserFullProfile[]> {
Expand Down
1 change: 0 additions & 1 deletion app/src/follow/follow.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { FollowService } from './follow.service';
CursusUserModule,
],
providers: [FollowResolver, FollowService],
//exports: [FollowService],
})
// eslint-disable-next-line
export class FollowModule {}
53 changes: 35 additions & 18 deletions app/src/follow/follow.resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,72 @@ import { MyUserId } from 'src/auth/myContext';
import { StatAuthGuard } from 'src/auth/statAuthGuard';
import { HttpExceptionFilter } from 'src/http-exception.filter';
import { FollowService } from './follow.service';
import { FollowResult, FollowUserList } from './model/follow.model';
import { FollowListWithCount, FollowResult } from './model/follow.model';

@UseFilters(HttpExceptionFilter)
@UseGuards(StatAuthGuard)
@Resolver()
export class FollowResolver {
constructor(private readonly followService: FollowService) {}

@Mutation((_returns) => FollowResult, {
description: 'ํ”„๋ก ํŠธ ํ…Œ์ŠคํŠธ์šฉ ์ž„์‹œ ํ•จ์ˆ˜',
})
async MakeFollow(
@Args('to') to: string,
@Args('from') from: string,
@Args('type') type: 'follow' | 'unfollow',
): Promise<typeof FollowResult> {
return await this.followService.MakeFollowUser(to, from, type);
}

@Mutation((_returns) => FollowResult)
async followUser(
@MyUserId() userId: number,
@Args('login') login: string,
@Args('target') target: string,
): Promise<typeof FollowResult> {
return await this.followService.followUser(userId, login);
return await this.followService.followUser(userId, target);
}

@Mutation((_returns) => FollowResult)
async unFollowUser(
async unfollowUser(
@MyUserId() userId: number,
@Args('login') login: string,
@Args('target') target: string,
): Promise<typeof FollowResult> {
return await this.followService.unFollowUser(userId, login);
return await this.followService.unfollowUser(userId, target);
}

@Mutation((_returns) => FollowUserList)
@Mutation((_returns) => FollowListWithCount)
async getFollowerList(
@MyUserId() userId: number,
@Args('login') login: string,
): Promise<FollowUserList> {
const followUser = await this.followService.getFollowerList(login);
const count = await this.followService.getFollowerCount(login);
@Args('target') target: string,
): Promise<FollowListWithCount> {
const followerList = await this.followService.getFollowerList(
userId,
target,
);
const count = await this.followService.getFollowerCount(target);

return {
count,
followUser,
followList: followerList,
};
}

@Mutation((_returns) => FollowUserList)
@Mutation((_returns) => FollowListWithCount)
async getFollowingList(
@MyUserId() userId: number,
@Args('login') login: string,
): Promise<FollowUserList> {
const followUser = await this.followService.getFollowingList(userId, login);
const count = await this.followService.getFollowingCount(login);
@Args('target') target: string,
): Promise<FollowListWithCount> {
const followingList = await this.followService.getFollowingList(
userId,
target,
);
const count = await this.followService.getFollowingCount(target);

return {
count,
followUser,
followList: followingList,
};
}
}
Loading

0 comments on commit 23a8eb7

Please sign in to comment.