Skip to content

Commit

Permalink
Merge pull request #538 from boostcampwm2023/BE/feature/#401
Browse files Browse the repository at this point in the history
달성 기록에 대해 이모지 통계를 조회할 수 있는 API를 작성한다.
  • Loading branch information
Dltmd202 authored Dec 9, 2023
2 parents 689ceb9 + 34e2e0b commit e2726eb
Show file tree
Hide file tree
Showing 12 changed files with 1,021 additions and 65 deletions.
244 changes: 244 additions & 0 deletions BE/src/group/emoji/application/group-achievement-emoji.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,4 +640,248 @@ describe('GroupAchievementEmojiService Test', () => {
});
});
});

describe('getGroupAchievementEmojiCount는 그룹 달성기록에 이모지를 조회할 수 있다.', () => {
it('그룹 달성기록에 이모지를 조회할 수 있다.', async () => {
await transactionTest(dataSource, async () => {
// given
const leader = await usersFixture.getUser('user');
const group = await groupFixture.createGroups(leader);
const groupCategory = await groupCategoryFixture.createCategory(
leader,
group,
);
const groupAchievement =
await groupAchievementFixture.createGroupAchievement(
leader,
group,
groupCategory,
);

const user = await usersFixture.getUser('otherUser');
await groupFixture.addMember(group, user, UserGroupGrade.MANAGER);

// when
const groupAchievementEmojiListElements =
await groupAchievementEmojiService.getGroupAchievementEmojiCount(
user,
group.id,
groupAchievement.id,
);

// then
expect(groupAchievementEmojiListElements.LIKE.id).toBe(Emoji.LIKE);
expect(groupAchievementEmojiListElements.LIKE.count).toBe(0);
expect(groupAchievementEmojiListElements.LIKE.isSelected).toBe(false);
expect(groupAchievementEmojiListElements.FIRE.id).toBe(Emoji.FIRE);
expect(groupAchievementEmojiListElements.FIRE.count).toBe(0);
expect(groupAchievementEmojiListElements.FIRE.isSelected).toBe(false);
expect(groupAchievementEmojiListElements.SMILE.id).toBe(Emoji.SMILE);
expect(groupAchievementEmojiListElements.SMILE.count).toBe(0);
expect(groupAchievementEmojiListElements.SMILE.isSelected).toBe(false);
});
});

it('그룹 달성기록에 이모지를 조회할 수 있다.', async () => {
await transactionTest(dataSource, async () => {
// given
const leader = await usersFixture.getUser('user');
const group = await groupFixture.createGroups(leader);
const groupCategory = await groupCategoryFixture.createCategory(
leader,
group,
);
const groupAchievement =
await groupAchievementFixture.createGroupAchievement(
leader,
group,
groupCategory,
);

const user = await usersFixture.getUser('otherUser');
await groupFixture.addMember(group, user, UserGroupGrade.MANAGER);

await groupAchievementEmojiFixture.createGroupAchievementEmoji(
user,
groupAchievement,
Emoji.LIKE,
);

// when
const groupAchievementEmojiListElements =
await groupAchievementEmojiService.getGroupAchievementEmojiCount(
user,
group.id,
groupAchievement.id,
);

// then
expect(groupAchievementEmojiListElements.LIKE.id).toBe(Emoji.LIKE);
expect(groupAchievementEmojiListElements.LIKE.count).toBe(1);
expect(groupAchievementEmojiListElements.LIKE.isSelected).toBe(true);
expect(groupAchievementEmojiListElements.FIRE.id).toBe(Emoji.FIRE);
expect(groupAchievementEmojiListElements.FIRE.count).toBe(0);
expect(groupAchievementEmojiListElements.FIRE.isSelected).toBe(false);
expect(groupAchievementEmojiListElements.SMILE.id).toBe(Emoji.SMILE);
expect(groupAchievementEmojiListElements.SMILE.count).toBe(0);
expect(groupAchievementEmojiListElements.SMILE.isSelected).toBe(false);
});
});

it('그룹 달성기록에 이모지를 조회할 수 있다.', async () => {
await transactionTest(dataSource, async () => {
// given
const leader = await usersFixture.getUser('user');
const group = await groupFixture.createGroups(leader);
const groupCategory = await groupCategoryFixture.createCategory(
leader,
group,
);
const groupAchievement =
await groupAchievementFixture.createGroupAchievement(
leader,
group,
groupCategory,
);

const user = await usersFixture.getUser('otherUser');
await groupFixture.addMember(group, user, UserGroupGrade.MANAGER);

await groupAchievementEmojiFixture.createGroupAchievementEmoji(
user,
groupAchievement,
Emoji.FIRE,
);

// when
const groupAchievementEmojiListElements =
await groupAchievementEmojiService.getGroupAchievementEmojiCount(
user,
group.id,
groupAchievement.id,
);

// then
expect(groupAchievementEmojiListElements.LIKE.id).toBe(Emoji.LIKE);
expect(groupAchievementEmojiListElements.LIKE.count).toBe(0);
expect(groupAchievementEmojiListElements.LIKE.isSelected).toBe(false);
expect(groupAchievementEmojiListElements.FIRE.id).toBe(Emoji.FIRE);
expect(groupAchievementEmojiListElements.FIRE.count).toBe(1);
expect(groupAchievementEmojiListElements.FIRE.isSelected).toBe(true);
expect(groupAchievementEmojiListElements.SMILE.id).toBe(Emoji.SMILE);
expect(groupAchievementEmojiListElements.SMILE.count).toBe(0);
expect(groupAchievementEmojiListElements.SMILE.isSelected).toBe(false);
});
});

it('그룹 달성기록에 이모지를 조회할 수 있다.', async () => {
await transactionTest(dataSource, async () => {
// given
const leader = await usersFixture.getUser('user');
const group = await groupFixture.createGroups(leader);
const groupCategory = await groupCategoryFixture.createCategory(
leader,
group,
);
const groupAchievement =
await groupAchievementFixture.createGroupAchievement(
leader,
group,
groupCategory,
);

const user = await usersFixture.getUser('otherUser');
await groupFixture.addMember(group, user, UserGroupGrade.MANAGER);

await groupAchievementEmojiFixture.createGroupAchievementEmoji(
user,
groupAchievement,
Emoji.FIRE,
);

await groupAchievementEmojiFixture.createGroupAchievementEmojis(
10,
groupAchievement,
Emoji.LIKE,
);

// when
const groupAchievementEmojiListElements =
await groupAchievementEmojiService.getGroupAchievementEmojiCount(
user,
group.id,
groupAchievement.id,
);

// then
expect(groupAchievementEmojiListElements.LIKE.id).toBe(Emoji.LIKE);
expect(groupAchievementEmojiListElements.LIKE.count).toBe(10);
expect(groupAchievementEmojiListElements.LIKE.isSelected).toBe(false);
expect(groupAchievementEmojiListElements.FIRE.id).toBe(Emoji.FIRE);
expect(groupAchievementEmojiListElements.FIRE.count).toBe(1);
expect(groupAchievementEmojiListElements.FIRE.isSelected).toBe(true);
expect(groupAchievementEmojiListElements.SMILE.id).toBe(Emoji.SMILE);
expect(groupAchievementEmojiListElements.SMILE.count).toBe(0);
expect(groupAchievementEmojiListElements.SMILE.isSelected).toBe(false);
});
});

it('그룹 달성기록에 이모지를 조회할 수 있다.', async () => {
await transactionTest(dataSource, async () => {
// given
const leader = await usersFixture.getUser('user');
const group = await groupFixture.createGroups(leader);
const groupCategory = await groupCategoryFixture.createCategory(
leader,
group,
);
const groupAchievement =
await groupAchievementFixture.createGroupAchievement(
leader,
group,
groupCategory,
);

const user = await usersFixture.getUser('otherUser');
await groupFixture.addMember(group, user, UserGroupGrade.MANAGER);

await groupAchievementEmojiFixture.createGroupAchievementEmoji(
user,
groupAchievement,
Emoji.FIRE,
);

await groupAchievementEmojiFixture.createGroupAchievementEmojis(
15,
groupAchievement,
Emoji.FIRE,
);

await groupAchievementEmojiFixture.createGroupAchievementEmojis(
10,
groupAchievement,
Emoji.LIKE,
);

// when
const groupAchievementEmojiListElements =
await groupAchievementEmojiService.getGroupAchievementEmojiCount(
user,
group.id,
groupAchievement.id,
);

// then
expect(groupAchievementEmojiListElements.LIKE.id).toBe(Emoji.LIKE);
expect(groupAchievementEmojiListElements.LIKE.count).toBe(10);
expect(groupAchievementEmojiListElements.LIKE.isSelected).toBe(false);
expect(groupAchievementEmojiListElements.FIRE.id).toBe(Emoji.FIRE);
expect(groupAchievementEmojiListElements.FIRE.count).toBe(16);
expect(groupAchievementEmojiListElements.FIRE.isSelected).toBe(true);
expect(groupAchievementEmojiListElements.SMILE.id).toBe(Emoji.SMILE);
expect(groupAchievementEmojiListElements.SMILE.count).toBe(0);
expect(groupAchievementEmojiListElements.SMILE.isSelected).toBe(false);
});
});
});
});
59 changes: 30 additions & 29 deletions BE/src/group/emoji/application/group-achievement-emoji.service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Injectable } from '@nestjs/common';
import { GroupAchievementEmojiRepository } from '../entities/group-achievement-emoji.repository';
import { Transactional } from '../../../config/transaction-manager';
import { User } from '../../../users/domain/user.domain';
import { Emoji } from '../domain/emoji';
import { GroupAchievementRepository } from '../../achievement/entities/group-achievement.repository';
import { UnauthorizedAchievementException } from '../../../achievement/exception/unauthorized-achievement.exception';
import { GroupAchievementEmoji } from '../domain/group-achievement-emoji.domain';
import { UserGroupRepository } from '../../group/entities/user-group.repository';
import { NoSuchGroupUserException } from '../../achievement/exception/no-such-group-user.exception';
import { GroupAchievementEmojiResponse } from '../dto/group-achievement-emoji-response';
import { Injectable } from "@nestjs/common";
import { GroupAchievementEmojiRepository } from "../entities/group-achievement-emoji.repository";
import { Transactional } from "../../../config/transaction-manager";
import { User } from "../../../users/domain/user.domain";
import { Emoji } from "../domain/emoji";
import { GroupAchievementRepository } from "../../achievement/entities/group-achievement.repository";
import { UnauthorizedAchievementException } from "../../../achievement/exception/unauthorized-achievement.exception";
import { GroupAchievementEmoji } from "../domain/group-achievement-emoji.domain";
import { UserGroupRepository } from "../../group/entities/user-group.repository";
import { NoSuchGroupUserException } from "../../achievement/exception/no-such-group-user.exception";
import { GroupAchievementEmojiResponse } from "../dto/group-achievement-emoji-response";
import { CompositeGroupAchievementEmoji } from "../dto/composite-group-achievement-emoji";

@Injectable()
export class GroupAchievementEmojiService {
Expand Down Expand Up @@ -56,24 +57,17 @@ export class GroupAchievementEmojiService {
}

@Transactional({ readonly: true })
async getGroupAchievementEmojiCount(user: User, groupAchievementId: number) {
return [
await this.groupAchievementEmojiRepository.findGroupAchievementEmojiMetaData(
user,
groupAchievementId,
Emoji.LIKE,
),
await this.groupAchievementEmojiRepository.findGroupAchievementEmojiMetaData(
user,
groupAchievementId,
Emoji.FIRE,
),
await this.groupAchievementEmojiRepository.findGroupAchievementEmojiMetaData(
user,
groupAchievementId,
Emoji.SMILE,
),
];
async getGroupAchievementEmojiCount(
user: User,
groupId: number,
groupAchievementId: number,
): Promise<CompositeGroupAchievementEmoji> {
await this.validateUserGroup(user, groupId);
await this.validateGroupAchievement(groupId, groupAchievementId);
return await this.groupAchievementEmojiRepository.findAllGroupAchievementEmojiMetaData(
user,
groupAchievementId,
);
}

private async getGroupAchievement(groupId: number, achievementId: number) {
Expand All @@ -86,6 +80,13 @@ export class GroupAchievementEmojiService {
return grouopAchievement;
}

private async validateGroupAchievement(
groupId: number,
achievementId: number,
) {
await this.getGroupAchievement(groupId, achievementId);
}

private async validateUserGroup(user: User, groupId: number) {
const userGroup =
await this.userGroupRepository.findOneByUserCodeAndGroupId(
Expand Down
Loading

0 comments on commit e2726eb

Please sign in to comment.