Skip to content

Commit

Permalink
Merge pull request #114 from LocalMingle/dev
Browse files Browse the repository at this point in the history
[작업완료]: 검색 기능, 지역 데이터 수정
  • Loading branch information
kimjonghwa230412 authored Oct 27, 2023
2 parents 9ab6c50 + 436b39b commit b1a2cd1
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 34 deletions.
26 changes: 13 additions & 13 deletions src/data/interface/city.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const city = [
{ doName: '광주광역시' },
{ doName: '대전광역시' },
{ doName: '울산광역시' },
{ doName: '세종특별자치시' },
{ doName: '세종시' },
{ doName: '경기도' },
{ doName: '강원도' },
{ doName: '충청북도' },
Expand All @@ -19,7 +19,7 @@ export const city = [
{ doName: '전라남도' },
{ doName: '경상북도' },
{ doName: '경상남도' },
{ doName: '제주특별자치도' },
{ doName: '제주도' },
],
},
{
Expand All @@ -33,7 +33,7 @@ export const city = [
{ doName: '光州広域市' },
{ doName: '大田広域市' },
{ doName: '蔚山広域市' },
{ doName: '世宗特別自治市' },
{ doName: '世宗市' },
{ doName: '京畿道' },
{ doName: '江原道' },
{ doName: '忠清北道' },
Expand All @@ -42,21 +42,21 @@ export const city = [
{ doName: '全羅南道' },
{ doName: '慶尚北道' },
{ doName: '慶尚南道' },
{ doName: '濟州特別自治道' },
{ doName: '濟州道' },
],
},
{
lang: 'en',
items: [
{ doName: 'City / Province'},
{ doName: 'Seoul Special City' },
{ doName: 'Busan Metropolitan City' },
{ doName: 'Daegu Metropolitan City' },
{ doName: 'Incheon Metropolitan City' },
{ doName: 'Gwangju Metropolitan City' },
{ doName: 'Daejeon Metropolitan City' },
{ doName: 'Ulsan Metropolitan City' },
{ doName: 'Sejong Special Autonomous City' },
{ doName: 'Seoul' },
{ doName: 'Busan' },
{ doName: 'Daegu' },
{ doName: 'Incheon' },
{ doName: 'Gwangju' },
{ doName: 'Daejeon' },
{ doName: 'Ulsan' },
{ doName: 'Sejong' },
{ doName: 'Gyeonggi-do' },
{ doName: 'Gangwon-do' },
{ doName: 'Chungcheongbuk-do' },
Expand All @@ -65,7 +65,7 @@ export const city = [
{ doName: 'Jeollanam-do' },
{ doName: 'Gyeongsangbuk-do' },
{ doName: 'Gyeongsangnam-do' },
{ doName: 'Jeju Special Self-Governing Province' },
{ doName: 'Jeju-si' },
],
},
];
Expand Down
1 change: 0 additions & 1 deletion src/events/dto/create-event.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ApiProperty } from '@nestjs/swagger';
import { Event } from '@prisma/client';
import {
IsString,
IsInt,
Expand Down
73 changes: 60 additions & 13 deletions src/searches/searches.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,75 @@ export class SearchesController {

@Get()
@ApiOperation({ summary: '이벤트네임 or 콘텐츠 검색' })
async searchByNameOrContent(
@Query('query') query: string
): Promise<{ eventName: string; content: string }[]> {
return this.searchesService.searchByNameOrContent(query);
async searchByNameOrContent(@Query('query') query: string) {
const events = await this.searchesService.searchByNameOrContent(query);

const event = events.map((item) => {
const { GuestEvents, HostEvents, ...rest } = item;
const hostUser = HostEvents[0].User.UserDetail;

return {
event: rest,
guestList: GuestEvents.length,
hostUser: hostUser,
};
});
return event;
}

@Get('byLocation')
@ApiOperation({ summary: '이벤트 장소별 검색' })
@ApiQuery({ name: 'doName', type: String, required: true })
searchByLocation(@Query() query) {
return this.searchesService.searchByLocation(query);
@ApiQuery({ name: 'doName', type: String, example: '서울특별시, 경기도 등등'})
async searchByLocation(@Query() query:any) {
const events = await this.searchesService.searchByLocation(query);

const event = events.map((item) => {
const { GuestEvents, HostEvents, ...rest } = item;
const hostUser = HostEvents[0].User.UserDetail;

return {
event: rest,
guestList: GuestEvents.length,
hostUser: hostUser,
};
});
return event;
}

@Get('byCategory')
@ApiOperation({ summary: '카테고리별 검색' })
searchByCategory(@Query('query') query: string) {
return this.searchesService.searchByCategory(query);
@ApiQuery({ name: 'query', type: String, example:'☕맛집/커피, 🏃‍♂️운동/건강,🐾애완동, 📕공부/교육' })
async searchByCategory(@Query('query') query: string) {
const events = await this.searchesService.searchByCategory(query);

const event = events.map((item) => {
const { GuestEvents, HostEvents, ...rest } = item;
const hostUser = HostEvents[0].User.UserDetail;

return {
event: rest,
guestList: GuestEvents.length,
hostUser: hostUser,
};
});
return event;
}

@Get('byVerify')
@ApiOperation({ summary: '동네만 or 아무나 검색' })
searchByVerify(@Query('query') query: string) {
return this.searchesService.searchByVerify(query);
@ApiOperation({ summary: '🏡동네만 or 🙋‍♀️아무나 검색' })
@ApiQuery({ name: 'query', type: String, example: '🏡동네만, 🙋‍♀️아무나' })
async searchByVerify(@Query('query') query: string) {
const events = await this.searchesService.searchByVerify(query);

const event = events.map((item) => {
const { GuestEvents, HostEvents, ...rest } = item;
const hostUser = HostEvents[0].User.UserDetail;

return {
event: rest,
guestList: GuestEvents.length,
hostUser: hostUser,
};
});
return event;
}
}
91 changes: 84 additions & 7 deletions src/searches/searches.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ import { PrismaService } from '../prisma/prisma.service';
export class SearchesService {
constructor(private readonly prisma: PrismaService) {}

async searchByNameOrContent(
query: string
): Promise<{ eventName: string; content: string }[]> {
// 최소 2글자 이상의 검색어 확인
async searchByNameOrContent(query: string) {
if (query.length < 2) {
throw new BadRequestException('검색어는 최소 2글자 이상이어야 합니다.');
throw new BadRequestException('검색어를 2글자 이상 입력해주세요')
}
const events = await this.prisma.event.findMany({
where: {
Expand All @@ -20,25 +17,105 @@ export class SearchesService {
{ content: { contains: query } },
],
},
include: {
HostEvents: {
select: {
User: {
select: {
UserDetail: true,
},
},
},
},
GuestEvents: true,
_count: {
select: {
Viewlogs: true,
},
},
},
orderBy: {
createdAt: 'desc',
},
});
return events;
}

searchByLocation(query: any) {
return this.prisma.event.findMany({
where: { location_City: query.doName, isDeleted: false },
include: {
HostEvents: {
select: {
User: {
select: {
UserDetail: true,
},
},
},
},
GuestEvents: true,
_count: {
select: {
Viewlogs: true,
},
},
},
orderBy: {
createdAt: 'desc',
},
});
}

searchByCategory(query: string) {
searchByCategory(query:string) {
return this.prisma.event.findMany({
where: { category: query, isDeleted: false },
include: {
HostEvents: {
select: {
User: {
select: {
UserDetail: true,
},
},
},
},
GuestEvents: true,
_count: {
select: {
Viewlogs: true,
},
},
},
orderBy: {
createdAt: 'desc',
},
});
}

searchByVerify(query: string) {
searchByVerify(query:string) {
return this.prisma.event.findMany({
where: { isVerified: query, isDeleted: false },
include: {
HostEvents: {
select: {
User: {
select: {
UserDetail: true,
},
},
},
},
GuestEvents: true,
_count: {
select: {
Viewlogs: true,
},
},
},
orderBy: {
createdAt: 'desc',
},
});
}
}

0 comments on commit b1a2cd1

Please sign in to comment.