Skip to content

Commit

Permalink
merge #268: iOS 요청 반영
Browse files Browse the repository at this point in the history
[fix] iOS 요청 반영
  • Loading branch information
yaongmeow authored Dec 6, 2023
2 parents 53a3248 + b913471 commit c60fbda
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 148 deletions.
24 changes: 2 additions & 22 deletions BE/src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,15 @@
import {
Controller,
Get,
Param,
Post,
Res,
UploadedFile,
UseInterceptors,
} from '@nestjs/common';
import { Controller, Get, Param, Res } from '@nestjs/common';
import { AppService } from './app.service';
import { StorageService } from './storage/storage.service';
import { FileInterceptor } from '@nestjs/platform-express';
import { request } from 'http';

@Controller()
export class AppController {
constructor(
private readonly appService: AppService,
private readonly storageService: StorageService
) {}
constructor(private readonly appService: AppService) {}

@Get()
getHello(): string {
return this.appService.getHello();
}

@Post('/upload')
@UseInterceptors(FileInterceptor('file'))
async upload(@UploadedFile() file: Express.Multer.File) {
return this.storageService.upload('', file);
}

@Get('apps/:filename')
async ipa(@Res() response, @Param('filename') filename: string) {
const url = await this.appService.download(filename);
Expand Down
84 changes: 24 additions & 60 deletions BE/src/postings/posting.swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,101 +35,65 @@ export const searchByWord_OK = [

export const search_OK = [
{
id: 'c0fc7b89-97fc-4e02-99b4-80a958c98172',
title: 'bread lover❤️',
createdAt: '2023-11-28T09:28:07.880Z',
thumbnail: null,
startDate: '2023-08-16',
endDate: '2023-08-18',
days: 3,
id: '4d365e7c-3e82-472d-bf87-7faf65d9377d',
title: '즐거운 여행❤️',
created_at: '2023-12-04T01:51:14.671Z',
thumbnail:
'https://traveline.kr.object.ncloudstorage.com/123456789012345678901234567890123456/4d365e7c-3e82-472d-bf87-7faf65d9377d/01eeaf67-6710-40b7-97ab-cd11d8a64794.jpg?AWSAccessKeyId=qjvpzL57YZV54DgXNdvd&Expires=1701864219&Signature=0LpCyEAHQKCLqIaTq3zseYTiBVA%3D',
period: '2박 3일',
headcount: '5인 이상',
budget: '10 - 50만 원',
location: '대전',
season: '여름',
vehicle: null,
theme: ['힐링', '맛집'],
withWho: ['가족'],
theme: ['힐링', '맛집'],
writer: {
id: '123456789012345678901234567890123456',
name: 'lemon',
name: 'pong',
avatar: null,
resourceId: 'temp',
socialType: 1,
},
likeds: [],
reports: [
{
reporter: '000056789012345678901234567890123456',
posting: 'c0fc7b89-97fc-4e02-99b4-80a958c98172',
},
],
likeds: '1',
},
{
id: '51336ad1-3769-4827-bfb1-1080df368532',
title: 'bread lover',
createdAt: '2023-11-28T06:19:24.042Z',
id: '9a0396ba-4892-436a-a97c-58be59b59327',
title: '대전 여행😎 ',
created_at: '2023-12-02T08:36:04.676Z',
thumbnail: null,
startDate: '2023-08-16',
endDate: '2023-08-18',
days: 3,
period: '2박 3일',
headcount: '5인 이상',
budget: '10 - 50만 원',
location: '대전',
season: '여름',
vehicle: null,
theme: ['힐링', '맛집'],
withWho: ['가족'],
theme: ['힐링', '맛집'],
writer: {
id: '000056789012345678901234567890123456',
id: '123456789012345678901234567890123456',
name: 'pong',
avatar: null,
resourceId: 'km',
socialType: 1,
},
likeds: [
{
user: '123456789012345678901234567890123456',
posting: '51336ad1-3769-4827-bfb1-1080df368532',
},
],
reports: [],
likeds: '0',
},
{
id: 'e9c76262-cb37-45a4-b713-a08a625b79d7',
title: 'trip~',
createdAt: '2023-11-28T05:58:04.646Z',
thumbnail: null,
startDate: '2023-12-29',
endDate: '2024-01-03',
days: 6,
period: '3박 ~',
headcount: '2인',
budget: '100만 원 ~',
location: '서울',
season: '겨울',
vehicle: '대중교통',
theme: ['맛집', '액티비티'],
withWho: ['친구'],
period: '2박 3일',
headcount: '5인 이상',
budget: '10 - 50만 원',
location: '대전',
season: '여름',
vehicle: null,
withWho: ['가족'],
theme: ['힐링', '맛집'],
writer: {
id: '000056789012345678901234567890123456',
id: '123456789012345678901234567890123456',
name: 'pong',
avatar: null,
resourceId: 'km',
socialType: 1,
},
likeds: [
{
user: '000056789012345678901234567890123456',
posting: 'e9c76262-cb37-45a4-b713-a08a625b79d7',
},
{
user: '123456789012345678901234567890123456',
posting: 'e9c76262-cb37-45a4-b713-a08a625b79d7',
},
],
reports: [],
likeds: '1',
},
];

Expand Down
4 changes: 1 addition & 3 deletions BE/src/postings/postings.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ export class PostingsController {
description: '검색어와 선택 태그의 교집합에 해당하는 게시글을 반환합니다.',
})
@ApiOkResponse({ schema: { example: search_OK } })
async search(
@Query() searchPostingDto: SearchPostingDto
): Promise<Posting[]> {
async search(@Query() searchPostingDto: SearchPostingDto) {
return this.postingsService.findAll(searchPostingDto);
}

Expand Down
3 changes: 2 additions & 1 deletion BE/src/postings/postings.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import { PostingsRepository } from './repositories/postings.repository';
import { LikedsRepository } from './repositories/likeds.repository';
import { ReportsRepository } from './repositories/reports.repository';
import { UsersModule } from '../users/users.module';
import { StorageModule } from 'src/storage/storage.module';

@Module({
imports: [DatabaseModule, UsersModule],
imports: [DatabaseModule, UsersModule, StorageModule],
controllers: [PostingsController],
providers: [
...postingsProviders,
Expand Down
31 changes: 29 additions & 2 deletions BE/src/postings/postings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ import { Liked } from './entities/liked.entity';
import { Report } from './entities/report.entity';
import { Period, Season } from './postings.types';
import { BLOCKING_LIMIT } from './postings.constants';
import { StorageService } from 'src/storage/storage.service';

@Injectable()
export class PostingsService {
constructor(
private readonly userRepository: UserRepository,
private readonly postingsRepository: PostingsRepository,
private readonly likedsRepository: LikedsRepository,
private readonly reportsRepository: ReportsRepository
private readonly reportsRepository: ReportsRepository,
private readonly storageService: StorageService
) {}

async create(userId: string, createPostingDto: CreatePostingDto) {
Expand All @@ -43,7 +45,7 @@ export class PostingsService {
}

async findAll(dto: SearchPostingDto) {
return this.postingsRepository.findAll(
const postings = await this.postingsRepository.findAll(
dto.keyword,
dto.sorting,
dto.offset,
Expand All @@ -57,6 +59,31 @@ export class PostingsService {
dto.theme,
dto.withWho
);

return Promise.all(
postings.map(async (posting) => ({
id: posting.p_id,
title: posting.p_title,
created_at: posting.p_created_at,
thumbnail: posting.p_thumbnail
? await this.storageService.getImageUrl(posting.p_thumbnail)
: null,
period: posting.p_period,
headcount: posting.p_headcount,
budget: posting.p_budget,
location: posting.p_location,
season: posting.p_season,
vehicle: posting.p_vehicle,
withWho: posting.p_with_who,
theme: posting.p_theme,
writer: {
id: posting.u_id,
name: posting.u_name,
avatar: posting.u_avatar,
},
likeds: posting.likeds,
}))
);
}

async findAllBytitle(keyword: string) {
Expand Down
18 changes: 9 additions & 9 deletions BE/src/postings/repositories/postings.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ export class PostingsRepository {
) {
const qb = this.postingsRepository
.createQueryBuilder('p')
.leftJoinAndSelect('p.writer', 'user')
.where('p.title LIKE :keyword', { keyword: `%${keyword}%` });
.leftJoin('p.likeds', 'l', 'l.isDeleted = :isDeleted', {
isDeleted: false,
})
.leftJoinAndSelect('p.writer', 'u')
.where('p.title LIKE :keyword', { keyword: `%${keyword}%` })
.groupBy('p.id')
.addSelect('COUNT(l.posting)', 'likeds');

if (budget) {
qb.where('p.budget = :budget', { budget });
Expand Down Expand Up @@ -127,20 +132,15 @@ export class PostingsRepository {
}

if (sorting === Sorting.좋아요순) {
qb.leftJoin('p.likeds', 'liked', 'liked.isDeleted = :isDeleted', {
isDeleted: false,
})
.groupBy('p.id')
.addSelect('COUNT(liked.posting)', 'likedCount')
.orderBy('likedCount', 'DESC');
qb.orderBy('likeds', 'DESC');
} else {
qb.orderBy('p.createdAt', 'DESC');
}

return qb
.skip((offset - 1) * limit)
.take(limit)
.getMany();
.getRawMany();
}

async findAllByTitle(keyword: string) {
Expand Down
2 changes: 1 addition & 1 deletion BE/src/timelines/dto/create-timeline.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class CreateTimelineDto {
@ApiProperty({
required: false,
type: 'file',
description: '업로드하는 사진',
description: '업로드하는 사진 (파일 크기 2MB까지 가능)',
})
@IsOptional()
image: Express.Multer.File;
Expand Down
17 changes: 13 additions & 4 deletions BE/src/timelines/timelines.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,15 @@ export class TimelinesController {
@Req() request,
@UploadedFile() image: Express.Multer.File,
@Body() createTimelineDto: CreateTimelineDto
): Promise<Timeline> {
) {
const userId = request['user'].id;
return this.timelinesService.create(userId, image, createTimelineDto);
const { id } = await this.timelinesService.create(
userId,
image,
createTimelineDto
);

return { id };
}

@Get()
Expand Down Expand Up @@ -151,7 +157,9 @@ export class TimelinesController {
}

@Put(':id')
@UseInterceptors(FileInterceptor('image'))
@UseInterceptors(
FileInterceptor('image', { limits: { fileSize: 1024 * 1024 * 2 } })
)
@ApiOperation({
summary: 'id에 해당하는 타임라인 수정',
description: 'id에 해당하는 타임라인을 수정합니다.',
Expand All @@ -165,7 +173,8 @@ export class TimelinesController {
@Body() updateTimelineDto: UpdateTimelineDto
) {
const userId = request['user'].id;
return this.timelinesService.update(id, userId, image, updateTimelineDto);
await this.timelinesService.update(id, userId, image, updateTimelineDto);
return { id };
}

@Delete(':id')
Expand Down
47 changes: 2 additions & 45 deletions BE/src/timelines/timelines.swagger.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,4 @@
export const create_OK = {
title: '두근두근 출발 날 😍',
day: 1,
description:
'서울역의 상징성은 정치적으로도 연관이 깊다. 호남선, 전라선, 장항선은 2004년 KTX 개통으로 인해서 용산역이 주 출발역으로 바뀌었을 때에 국회의원들이 들고 일어났다. 그 후 일부 KTX가 용산 경유 서울역 착발로 바뀌었다. 강릉선 KTX은 특히 서울역에서 영동 지방으로 직접 가는 정기 열차이며 서울역 착발임을 한국철도공사가 크게 알렸고, 이는 신의 한 수가 된다. 그 전에는 강원도 가는 기차는 청량리역이 진리였다. 영서 지방은 ITX-청춘 용산발 춘천행, DMZ-train 서울발 백마고지행 둘뿐이었다.',
date: '2023-08-16',
place: '서울역',
time: '07:30',
posting: {
id: '9a0396ba-4892-436a-a97c-58be59b59327',
title: '대전 여행😎 ',
createdAt: '2023-12-02T08:36:04.676Z',
thumbnail: null,
startDate: '2023-08-16',
endDate: '2023-08-18',
days: 3,
period: '2박 3일',
headcount: '5인 이상',
budget: '10 - 50만 원',
location: '대전',
season: '여름',
vehicle: null,
theme: ['힐링', '맛집'],
withWho: ['가족'],
writer: {
id: '123456789012345678901234567890123456',
name: 'pong',
avatar: null,
resourceId: 'temp111',
socialType: 1,
},
reports: [],
likeds: [],
},
coordX: '126.970606917394',
coordY: '37.5546788388674',
image:
'123456789012345678901234567890123456/4d2084e5-0b1f-449a-9908-2918bd384f661a1a8809-2ee7-4a39-ab02-e7b50f4ded4e.jpg',
id: '01d97f2b-515c-4a44-91b8-dfa48d806b00',
};
export const create_OK = { id: 'f2a7a09c-70d4-46d1-84e1-67b2f8a8b30d' };

export const findOne_OK = {
id: '01d97f2b-515c-4a44-91b8-dfa48d806b00',
Expand Down Expand Up @@ -71,11 +32,7 @@ export const findOne_OK = {
},
};

export const update_OK = {
generatedMaps: [],
raw: [],
affected: 1,
};
export const update_OK = { id: 'f2a7a09c-70d4-46d1-84e1-67b2f8a8b30d' };

export const remove_OK = {
id: '01d97f2b-515c-4a44-91b8-dfa48d806b00',
Expand Down
Loading

0 comments on commit c60fbda

Please sign in to comment.