Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProfileSpace관련 동작 관련 모듈로 API 이동 #355

Merged
merged 28 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
eb516dc
feat: 유저가 들어간 스페이스 찾기
Conut-1 Oct 4, 2024
43f685d
test: UsersController 테스트 추가
Conut-1 Oct 4, 2024
e63ef8a
fix: PrismaModule 의존성 추가
Conut-1 Oct 4, 2024
e6c9701
test: e2e 테스트 추가
Conut-1 Oct 4, 2024
8649827
feat: 유저가 들어간 스페이스 목록 API
Conut-1 Oct 4, 2024
29beac1
refactor: 비동기 동작 개선
Conut-1 Oct 4, 2024
aeb19db
feat: 이전 버전 제거
Conut-1 Oct 5, 2024
7f5fcc0
feat: 프로필 소유 검증 추가
Conut-1 Oct 6, 2024
43138bb
refactor: 유저 프로필 검증 부분 교체
Conut-1 Oct 6, 2024
9decbf6
refactor: mocking 방식 변경
Conut-1 Oct 6, 2024
dc0f1e2
feat: 스페이스 관련 동작 서비스로 추가
Conut-1 Oct 6, 2024
cad896f
refactor: 비동기 동작 개선
Conut-1 Oct 6, 2024
c892ca5
test: 테스트 추가
Conut-1 Oct 6, 2024
74081fe
remove: 불필요 파일 삭제
Conut-1 Oct 6, 2024
3fa19bf
refactor: Mocking 방식 변경
Conut-1 Oct 6, 2024
b3f296d
feat: joinSpace 추가
Conut-1 Oct 6, 2024
268392b
feat: leaveSpace 추가
Conut-1 Oct 6, 2024
baf605b
feat: findProfilesInSpace 추가
Conut-1 Oct 6, 2024
418a2c0
feat: 모듈에 맞지 않은 controller 제거
Conut-1 Oct 6, 2024
665dc6b
fix: uuid 함수 변경에 따라서 패턴 수정
Conut-1 Oct 7, 2024
9f8e241
test: 스페이스 참가 API 테스트 추가
Conut-1 Oct 7, 2024
9411967
test: 스페이스 나가기 API 테스트 추가
Conut-1 Oct 7, 2024
d614c8c
fix: 응답 상태 코드 변경
Conut-1 Oct 7, 2024
b9915be
fix: API 설명 수정
Conut-1 Oct 7, 2024
ea353ec
test: 스페이스에 참가한 프로필 가져오기 API 테스트 추가
Conut-1 Oct 7, 2024
abefa7d
fix: 테스트 수정
Conut-1 Oct 7, 2024
1b78d61
fix: API 설명 수정
Conut-1 Oct 7, 2024
7a7fe07
fix: 프로필 참가 여부 추가
Conut-1 Oct 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions nestjs-BE/server/src/profile-space/dto/create-profile-space.dto.ts

This file was deleted.

This file was deleted.

126 changes: 0 additions & 126 deletions nestjs-BE/server/src/profile-space/profile-space.controller.ts

This file was deleted.

7 changes: 2 additions & 5 deletions nestjs-BE/server/src/profile-space/profile-space.module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { Module, forwardRef } from '@nestjs/common';
import { Module } from '@nestjs/common';
import { ProfileSpaceService } from './profile-space.service';
import { ProfileSpaceController } from './profile-space.controller';
import { ProfilesModule } from '../profiles/profiles.module';
import { SpacesModule } from '../spaces/spaces.module';

@Module({
imports: [ProfilesModule, forwardRef(() => SpacesModule)],
controllers: [ProfileSpaceController],
imports: [ProfilesModule],
providers: [ProfileSpaceService],
exports: [ProfileSpaceService],
})
Expand Down
83 changes: 83 additions & 0 deletions nestjs-BE/server/src/profile-space/profile-space.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { Test, TestingModule } from '@nestjs/testing';
import { ProfileSpaceService } from './profile-space.service';
import { PrismaService } from '../prisma/prisma.service';
import { ProfileSpace } from '@prisma/client';

describe('ProfileSpaceService', () => {
let profileSpaceService: ProfileSpaceService;
let prisma: PrismaService;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [
ProfileSpaceService,
{
provide: PrismaService,
useValue: {
profileSpace: {
findFirst: jest.fn(),
findUnique: jest.fn(),
},
},
},
],
}).compile();

profileSpaceService = module.get<ProfileSpaceService>(ProfileSpaceService);
prisma = module.get<PrismaService>(PrismaService);
});

it('isSpaceEmpty empty', async () => {
const spaceUuid = 'space uuid';

(prisma.profileSpace.findFirst as jest.Mock).mockResolvedValue(null);

const isSpaceEmpty = profileSpaceService.isSpaceEmpty(spaceUuid);

await expect(isSpaceEmpty).resolves.toBeTruthy();
});

it('isSpaceEmpty not empty', async () => {
const spaceUuid = 'space uuid';
const profileSpace = 'profile space';

(prisma.profileSpace.findFirst as jest.Mock).mockResolvedValue(
profileSpace,
);

const isSpaceEmpty = profileSpaceService.isSpaceEmpty(spaceUuid);

await expect(isSpaceEmpty).resolves.toBeFalsy();
});

it('isProfileInSpace joined', async () => {
const spaceUuid = 'space uuid';
const profileUuid = 'profile uuid';
const profileSpaceMock = { profileUuid, spaceUuid } as ProfileSpace;

(prisma.profileSpace.findUnique as jest.Mock).mockResolvedValue(
profileSpaceMock,
);

const isProfileInSpace = profileSpaceService.isProfileInSpace(
profileUuid,
spaceUuid,
);

await expect(isProfileInSpace).resolves.toBeTruthy();
});

it('isProfileInSpace not joined', async () => {
const spaceUuid = 'space uuid';
const profileUuid = 'profile uuid';

(prisma.profileSpace.findUnique as jest.Mock).mockResolvedValue(null);

const isProfileInSpace = profileSpaceService.isProfileInSpace(
profileUuid,
spaceUuid,
);

await expect(isProfileInSpace).resolves.toBeFalsy();
});
});
50 changes: 20 additions & 30 deletions nestjs-BE/server/src/profile-space/profile-space.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ import { Prisma, ProfileSpace } from '@prisma/client';
export class ProfileSpaceService {
constructor(private readonly prisma: PrismaService) {}

async findProfileSpacesByProfileUuid(
async createProfileSpace(
profileUuid: string,
): Promise<ProfileSpace[]> {
return this.prisma.profileSpace.findMany({
where: { profileUuid: profileUuid },
spaceUuid: string,
): Promise<ProfileSpace | null> {
return this.prisma.profileSpace.create({
data: { spaceUuid, profileUuid },
});
}

async findProfileSpacesBySpaceUuid(
async deleteProfileSpace(
profileUuid: string,
spaceUuid: string,
): Promise<ProfileSpace[]> {
return this.prisma.profileSpace.findMany({
where: { spaceUuid: spaceUuid },
): Promise<ProfileSpace | null> {
return this.prisma.profileSpace.delete({
where: { spaceUuid_profileUuid: { spaceUuid, profileUuid } },
});
}

Expand Down Expand Up @@ -48,28 +50,6 @@ export class ProfileSpaceService {
}
}

async leaveSpace(
profileUuid: string,
spaceUuid: string,
): Promise<ProfileSpace | null> {
try {
return await this.prisma.profileSpace.delete({
where: {
spaceUuid_profileUuid: {
spaceUuid: spaceUuid,
profileUuid: profileUuid,
},
},
});
} catch (err) {
if (err instanceof Prisma.PrismaClientKnownRequestError) {
return null;
} else {
throw err;
}
}
}

async isSpaceEmpty(spaceUuid: string) {
const first = await this.prisma.profileSpace.findFirst({
where: {
Expand All @@ -78,4 +58,14 @@ export class ProfileSpaceService {
});
return first ? false : true;
}

async isProfileInSpace(
profileUuid: string,
spaceUuid: string,
): Promise<boolean> {
const profileSpace = await this.prisma.profileSpace.findUnique({
where: { spaceUuid_profileUuid: { spaceUuid, profileUuid } },
});
return profileSpace ? true : false;
}
}
12 changes: 0 additions & 12 deletions nestjs-BE/server/src/profiles/dto/profile-space.dto.ts

This file was deleted.

16 changes: 1 addition & 15 deletions nestjs-BE/server/src/spaces/dto/create-space.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MAX_NAME_LENGTH } from '../../config/magic-number';
import { Expose } from 'class-transformer';
import { v4 as uuid } from 'uuid';

export class CreateSpaceRequestV2Dto {
export class CreateSpaceRequestDto {
@IsString()
@IsNotEmpty()
@MaxLength(MAX_NAME_LENGTH)
Expand All @@ -24,20 +24,6 @@ export class CreateSpaceRequestV2Dto {
icon: string;
}

export class CreateSpaceRequestDto {
@IsString()
@IsNotEmpty()
@MaxLength(MAX_NAME_LENGTH)
@ApiProperty({ example: 'Sample Space', description: 'Name of the space' })
name: string;

@ApiProperty({
example: 'space-icon.png',
description: 'Profile icon for the space',
})
icon: string;
}

export class CreateSpacePrismaDto {
name: string;
icon: string;
Expand Down
12 changes: 12 additions & 0 deletions nestjs-BE/server/src/spaces/dto/join-space.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ApiProperty } from '@nestjs/swagger';
import { Expose } from 'class-transformer';
import { IsNotEmpty, IsString } from 'class-validator';
import { v4 as uuid } from 'uuid';

export class JoinSpaceRequestDto {
@IsString()
@IsNotEmpty()
@Expose({ name: 'profile_uuid' })
@ApiProperty({ example: uuid(), description: 'Profile uuid' })
profileUuid: string;
}
Loading
Loading