Skip to content

Commit 81b5cc4

Browse files
authored
Merge pull request #349 from boostcampwm2023/BE-feature/spaces
ํ”„๋กœํ•„ ๊ฒ€์‚ฌ ์ถ”๊ฐ€
2 parents 71b4499 + 71675d5 commit 81b5cc4

13 files changed

+1048
-231
lines changed

โ€Žnestjs-BE/server/src/auth/auth.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class AuthService {
6161
'Refresh token expired. Please log in again.',
6262
);
6363
}
64-
const accessToken = await this.createAccessToken(token.user_id);
64+
const accessToken = await this.createAccessToken(token.userUuid);
6565
return accessToken;
6666
} catch (error) {
6767
throw new UnauthorizedException(

โ€Žnestjs-BE/server/src/profile-space/profile-space.controller.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class ProfileSpaceController {
9696
profile.uuid,
9797
);
9898
const spaceUuids = profileSpaces.map(
99-
(profileSpace) => profileSpace.space_uuid,
99+
(profileSpace) => profileSpace.spaceUuid,
100100
);
101101
const spaces = await this.spacesService.findSpaces(spaceUuids);
102102
return { statusCode: 200, message: 'Success', data: spaces };
@@ -118,7 +118,7 @@ export class ProfileSpaceController {
118118
const profileSpaces =
119119
await this.profileSpaceService.findProfileSpacesBySpaceUuid(space.uuid);
120120
const profileUuids = profileSpaces.map(
121-
(profileSpace) => profileSpace.profile_uuid,
121+
(profileSpace) => profileSpace.profileUuid,
122122
);
123123
const profiles = await this.profilesService.findProfiles(profileUuids);
124124
return { statusCode: 200, message: 'Success', data: profiles };

โ€Žnestjs-BE/server/src/profile-space/profile-space.service.ts

+26-17
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,43 @@
11
import { Injectable } from '@nestjs/common';
22
import { PrismaService } from '../prisma/prisma.service';
3-
import { Prisma, Profile_space } from '@prisma/client';
3+
import { Prisma, ProfileSpace } from '@prisma/client';
44

55
@Injectable()
66
export class ProfileSpaceService {
77
constructor(private readonly prisma: PrismaService) {}
88

99
async findProfileSpacesByProfileUuid(
1010
profileUuid: string,
11-
): Promise<Profile_space[]> {
12-
return this.prisma.profile_space.findMany({
13-
where: { profile_uuid: profileUuid },
11+
): Promise<ProfileSpace[]> {
12+
return this.prisma.profileSpace.findMany({
13+
where: { profileUuid: profileUuid },
1414
});
1515
}
1616

1717
async findProfileSpacesBySpaceUuid(
1818
spaceUuid: string,
19-
): Promise<Profile_space[]> {
20-
return this.prisma.profile_space.findMany({
21-
where: { space_uuid: spaceUuid },
19+
): Promise<ProfileSpace[]> {
20+
return this.prisma.profileSpace.findMany({
21+
where: { spaceUuid: spaceUuid },
22+
});
23+
}
24+
25+
async findProfileSpaceByBothUuid(
26+
profileUuid: string,
27+
spaceUuid: string,
28+
): Promise<ProfileSpace | null> {
29+
return this.prisma.profileSpace.findUnique({
30+
where: { spaceUuid_profileUuid: { spaceUuid, profileUuid } },
2231
});
2332
}
2433

2534
async joinSpace(
2635
profileUuid: string,
2736
spaceUuid: string,
28-
): Promise<Profile_space | null> {
37+
): Promise<ProfileSpace | null> {
2938
try {
30-
return await this.prisma.profile_space.create({
31-
data: { space_uuid: spaceUuid, profile_uuid: profileUuid },
39+
return await this.prisma.profileSpace.create({
40+
data: { spaceUuid: spaceUuid, profileUuid: profileUuid },
3241
});
3342
} catch (err) {
3443
if (err instanceof Prisma.PrismaClientKnownRequestError) {
@@ -42,13 +51,13 @@ export class ProfileSpaceService {
4251
async leaveSpace(
4352
profileUuid: string,
4453
spaceUuid: string,
45-
): Promise<Profile_space | null> {
54+
): Promise<ProfileSpace | null> {
4655
try {
47-
return await this.prisma.profile_space.delete({
56+
return await this.prisma.profileSpace.delete({
4857
where: {
49-
space_uuid_profile_uuid: {
50-
space_uuid: spaceUuid,
51-
profile_uuid: profileUuid,
58+
spaceUuid_profileUuid: {
59+
spaceUuid: spaceUuid,
60+
profileUuid: profileUuid,
5261
},
5362
},
5463
});
@@ -62,9 +71,9 @@ export class ProfileSpaceService {
6271
}
6372

6473
async isSpaceEmpty(spaceUuid: string) {
65-
const first = await this.prisma.profile_space.findFirst({
74+
const first = await this.prisma.profileSpace.findFirst({
6675
where: {
67-
space_uuid: spaceUuid,
76+
spaceUuid: spaceUuid,
6877
},
6978
});
7079
return first ? false : true;

โ€Žnestjs-BE/server/src/profiles/profiles.service.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ export class ProfilesService {
1010
constructor(private prisma: PrismaService) {}
1111

1212
async findProfile(userUuid: string): Promise<Profile | null> {
13-
return this.prisma.profile.findUnique({ where: { userId: userUuid } });
13+
return this.prisma.profile.findUnique({ where: { userUuid } });
14+
}
15+
16+
async findProfileByProfileUuid(uuid: string): Promise<Profile | null> {
17+
return this.prisma.profile.findUnique({ where: { uuid } });
1418
}
1519

1620
async findProfiles(profileUuids: string[]): Promise<Profile[]> {
@@ -21,11 +25,11 @@ export class ProfilesService {
2125

2226
async getOrCreateProfile(data: CreateProfileDto): Promise<Profile> {
2327
return this.prisma.profile.upsert({
24-
where: { userId: data.user_id },
28+
where: { userUuid: data.user_id },
2529
update: {},
2630
create: {
2731
uuid: generateUuid(),
28-
userId: data.user_id,
32+
userUuid: data.user_id,
2933
image: data.image,
3034
nickname: data.nickname,
3135
},
@@ -38,7 +42,7 @@ export class ProfilesService {
3842
): Promise<Profile | null> {
3943
try {
4044
return await this.prisma.profile.update({
41-
where: { userId: userUuid },
45+
where: { userUuid },
4246
data: { ...updateProfileDto },
4347
});
4448
} catch (err) {

โ€Žnestjs-BE/server/src/spaces/dto/create-space.dto.ts

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
11
import { ApiProperty } from '@nestjs/swagger';
22
import { IsNotEmpty, IsString, MaxLength } from 'class-validator';
33
import { MAX_NAME_LENGTH } from '../../config/magic-number';
4+
import { Expose } from 'class-transformer';
5+
import { v4 as uuid } from 'uuid';
46

5-
export class CreateSpaceDto {
7+
export class CreateSpaceRequestV2Dto {
8+
@IsString()
9+
@IsNotEmpty()
10+
@MaxLength(MAX_NAME_LENGTH)
11+
@ApiProperty({ example: 'Sample Space', description: 'Name of the space' })
12+
name: string;
13+
14+
@IsString()
15+
@IsNotEmpty()
16+
@Expose({ name: 'profile_uuid' })
17+
@ApiProperty({ example: uuid(), description: 'Profile uuid' })
18+
profileUuid: string;
19+
20+
@ApiProperty({
21+
example: 'space-icon.png',
22+
description: 'Profile icon for the space',
23+
})
24+
icon: string;
25+
}
26+
27+
export class CreateSpaceRequestDto {
628
@IsString()
729
@IsNotEmpty()
830
@MaxLength(MAX_NAME_LENGTH)
@@ -15,3 +37,8 @@ export class CreateSpaceDto {
1537
})
1638
icon: string;
1739
}
40+
41+
export class CreateSpacePrismaDto {
42+
name: string;
43+
icon: string;
44+
}

โ€Žnestjs-BE/server/src/spaces/dto/update-space.dto.ts

+28-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { ApiProperty } from '@nestjs/swagger';
2-
import { IsNotEmpty, IsString, MaxLength } from 'class-validator';
2+
import { IsNotEmpty, IsOptional, IsString, MaxLength } from 'class-validator';
33
import { MAX_NAME_LENGTH } from '../../config/magic-number';
44

5-
export class UpdateSpaceDto {
5+
export class UpdateSpaceRequestV2Dto {
6+
@IsOptional()
67
@IsString()
78
@IsNotEmpty()
89
@MaxLength(MAX_NAME_LENGTH)
@@ -13,10 +14,35 @@ export class UpdateSpaceDto {
1314
})
1415
name: string;
1516

17+
@IsOptional()
1618
@ApiProperty({
1719
example: 'new image',
1820
description: 'Updated space icon',
1921
required: false,
2022
})
2123
icon: string;
2224
}
25+
26+
export class UpdateSpaceRequestDto {
27+
@IsString()
28+
@IsNotEmpty()
29+
@MaxLength(MAX_NAME_LENGTH)
30+
@ApiProperty({
31+
example: 'new space',
32+
description: 'Updated space name',
33+
required: false,
34+
})
35+
name: string;
36+
37+
@ApiProperty({
38+
example: 'new image',
39+
description: 'Updated space icon',
40+
required: false,
41+
})
42+
icon: string;
43+
}
44+
45+
export class UpdateSpacePrismaDto {
46+
name: string;
47+
icon: string;
48+
}

โ€Žnestjs-BE/server/src/spaces/entities/space.entity.ts

-1
This file was deleted.

0 commit comments

Comments
ย (0)