Skip to content

Commit b3b7c51

Browse files
authored
Merge pull request #17 from ccaaffee/feat/openhours
Cafe 정보에 운영시간 정보 추가
2 parents 1f52fcc + bbfaeb4 commit b3b7c51

File tree

6 files changed

+169
-5
lines changed

6 files changed

+169
-5
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- CreateTable
2+
CREATE TABLE `OpenHours` (
3+
`id` INTEGER NOT NULL AUTO_INCREMENT,
4+
`monday` VARCHAR(191) NULL,
5+
`tuesday` VARCHAR(191) NULL,
6+
`wednesday` VARCHAR(191) NULL,
7+
`thursday` VARCHAR(191) NULL,
8+
`friday` VARCHAR(191) NULL,
9+
`saturday` VARCHAR(191) NULL,
10+
`sunday` VARCHAR(191) NULL,
11+
`cafeId` INTEGER NOT NULL,
12+
13+
UNIQUE INDEX `OpenHours_cafeId_key`(`cafeId`),
14+
PRIMARY KEY (`id`)
15+
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
16+
17+
-- AddForeignKey
18+
ALTER TABLE `OpenHours` ADD CONSTRAINT `OpenHours_cafeId_fkey` FOREIGN KEY (`cafeId`) REFERENCES `Cafe`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

prisma/schema.prisma

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ model Cafe {
2727
address String
2828
latitude Float // GPS 위도
2929
longitude Float // GPS 경도
30-
// openHours String? // 영업 시간 // 좀 더 세분화 필요
3130
instagram String? // 가게 인스타 계정 링크
3231
naverMap String? // 가게 네이버지도 링크
3332
phone String? // 가게 연락처
@@ -36,6 +35,22 @@ model Cafe {
3635
3736
userCafes UserCafe[]
3837
images Image[]
38+
39+
openHours OpenHours?
40+
}
41+
42+
model OpenHours {
43+
id Int @id @default(autoincrement())
44+
monday String?
45+
tuesday String?
46+
wednesday String?
47+
thursday String?
48+
friday String?
49+
saturday String?
50+
sunday String?
51+
52+
cafe Cafe @relation(fields: [cafeId], references: [id])
53+
cafeId Int @unique
3954
}
4055

4156
enum PreferenceStatus {

src/cafe/cafe.repository.ts

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export class CafeRepository {
2727
},
2828
orderBy: { id: 'asc' },
2929
},
30+
openHours: true,
3031
},
3132
});
3233
}
@@ -67,6 +68,7 @@ export class CafeRepository {
6768
},
6869
orderBy: { order: 'asc' },
6970
},
71+
openHours: true,
7072
},
7173
orderBy: {
7274
createdAt: 'desc',
@@ -118,6 +120,7 @@ export class CafeRepository {
118120
},
119121
orderBy: { order: 'asc' },
120122
},
123+
openHours: true,
121124
},
122125
});
123126

@@ -138,15 +141,24 @@ export class CafeRepository {
138141
return await this.prismaService.cafe.create({
139142
data: {
140143
...createCafeDto,
144+
openHours: {
145+
create: createCafeDto.openHours,
146+
},
141147
images: {},
142148
},
149+
include: {
150+
openHours: true,
151+
},
143152
});
144153
}
145154

146155
async createCafeWithImages({ images, ...cafeData }: CreateCafeDto) {
147156
return await this.prismaService.cafe.create({
148157
data: {
149158
...cafeData,
159+
openHours: {
160+
create: cafeData.openHours,
161+
},
150162
images: {
151163
create: [
152164
...images.map((image, idx) => ({
@@ -169,6 +181,7 @@ export class CafeRepository {
169181
},
170182
orderBy: { order: 'asc' },
171183
},
184+
openHours: true,
172185
},
173186
});
174187
}
@@ -195,6 +208,9 @@ export class CafeRepository {
195208
},
196209
data: {
197210
...updateCafeData,
211+
openHours: {
212+
update: updateCafeData.openHours,
213+
},
198214
},
199215
include: {
200216
images: {
@@ -208,6 +224,7 @@ export class CafeRepository {
208224
},
209225
orderBy: { id: 'asc' },
210226
},
227+
openHours: true,
211228
},
212229
});
213230

@@ -246,9 +263,23 @@ export class CafeRepository {
246263
'createdAt', i.createdAt
247264
)
248265
)
249-
END AS images
266+
END AS images,
267+
CASE
268+
WHEN oh.cafeId IS NULL THEN NULL
269+
ELSE JSON_OBJECT(
270+
'monday', oh.monday,
271+
'tuesday', oh.tuesday,
272+
'wednesday', oh.wednesday,
273+
'thursday', oh.thursday,
274+
'friday', oh.friday,
275+
'saturday', oh.saturday,
276+
'sunday', oh.sunday
277+
)
278+
END AS openHours
250279
FROM Cafe AS c
251280
LEFT JOIN Image AS i ON c.id = i.cafeId
281+
LEFT JOIN OpenHours AS oh
282+
ON c.id = oh.cafeId
252283
WHERE ST_Distance_Sphere(
253284
point(longitude, latitude),
254285
point(${query.longitude}, ${query.latitude})
@@ -325,13 +356,27 @@ export class CafeRepository {
325356
'createdAt', i.createdAt
326357
)
327358
)
328-
END AS images
359+
END AS images,
360+
CASE
361+
WHEN oh.cafeId IS NULL THEN NULL
362+
ELSE JSON_OBJECT(
363+
'monday', oh.monday,
364+
'tuesday', oh.tuesday,
365+
'wednesday', oh.wednesday,
366+
'thursday', oh.thursday,
367+
'friday', oh.friday,
368+
'saturday', oh.saturday,
369+
'sunday', oh.sunday
370+
)
371+
END AS openHours
329372
FROM Cafe AS c
330373
LEFT JOIN Image AS i
331374
ON c.id = i.cafeId
332375
LEFT JOIN UserCafe AS uc
333376
ON c.id = uc.cafeId
334377
AND uc.userUuid = ${userUuid}
378+
LEFT JOIN OpenHours AS oh
379+
ON c.id = oh.cafeId
335380
WHERE ST_Distance_Sphere(
336381
point(c.longitude, c.latitude),
337382
point(${query.longitude}, ${query.latitude})

src/cafe/dto/req/createCafe.dto.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import {
55
IsOptional,
66
IsString,
77
IsUrl,
8+
ValidateNested,
89
} from 'class-validator';
10+
import { OpenHoursDto } from './openHours.dto';
11+
import { Type } from 'class-transformer';
912

1013
export class CreateCafeDto {
1114
@ApiProperty({
@@ -85,4 +88,14 @@ export class CreateCafeDto {
8588
@IsString({ each: true })
8689
@IsOptional()
8790
images?: string[];
91+
92+
@ApiProperty({
93+
type: OpenHoursDto,
94+
description: 'Cafe open hours',
95+
required: false,
96+
})
97+
@ValidateNested()
98+
@Type(() => OpenHoursDto)
99+
@IsOptional()
100+
openHours?: OpenHoursDto;
88101
}

src/cafe/dto/req/openHours.dto.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
import { IsOptional, IsString } from 'class-validator';
3+
4+
export class OpenHoursDto {
5+
@ApiProperty({
6+
type: String,
7+
description: '카페 월요일 운영 시간',
8+
example: '09:00-18:00',
9+
required: false,
10+
})
11+
@IsString()
12+
@IsOptional()
13+
monday?: string;
14+
15+
@ApiProperty({
16+
type: String,
17+
description: '카페 화요일 운영 시간',
18+
example: '09:00-18:00',
19+
required: false,
20+
})
21+
@IsString()
22+
@IsOptional()
23+
tuesday?: string;
24+
25+
@ApiProperty({
26+
type: String,
27+
description: '카페 수요일 운영 시간',
28+
example: '09:00-18:00',
29+
required: false,
30+
})
31+
@IsString()
32+
@IsOptional()
33+
wednesday?: string;
34+
35+
@ApiProperty({
36+
type: String,
37+
description: '카페 목요일 운영 시간',
38+
example: '09:00-18:00',
39+
required: false,
40+
})
41+
@IsString()
42+
@IsOptional()
43+
thursday?: string;
44+
45+
@ApiProperty({
46+
type: String,
47+
description: '카페 금요일 운영 시간',
48+
example: '09:00-18:00',
49+
required: false,
50+
})
51+
@IsString()
52+
@IsOptional()
53+
friday?: string;
54+
55+
@ApiProperty({
56+
type: String,
57+
description: '카페 토요일 운영 시간',
58+
example: '09:00-18:00',
59+
required: false,
60+
})
61+
@IsString()
62+
@IsOptional()
63+
saturday?: string;
64+
65+
@ApiProperty({
66+
type: String,
67+
description: '카페 일요일 운영 시간',
68+
example: '09:00-18:00',
69+
required: false,
70+
})
71+
@IsString()
72+
@IsOptional()
73+
sunday?: string;
74+
}

src/cafe/dto/req/pagination.dto.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ export class PaginationDto {
1919
description: 'Number of pages to get(default: 20)',
2020
required: false,
2121
})
22-
@Min(1)
23-
@Max(1)
22+
@Max(20)
2423
@IsNumber()
2524
@IsOptional()
2625
@Type(() => Number)

0 commit comments

Comments
 (0)