Skip to content

Commit

Permalink
Merge pull request #374 from boostcampwm2023/BE/stroy/v2-modify-spot-…
Browse files Browse the repository at this point in the history
…table

[BE]: spot table 수정
  • Loading branch information
twoo1999 authored Feb 19, 2024
2 parents ff317ea + a53f02d commit f029682
Show file tree
Hide file tree
Showing 39 changed files with 1,496 additions and 423 deletions.
13 changes: 9 additions & 4 deletions BE/musicspot/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import * as dotenv from 'dotenv';
import { User } from './user/entities/user.entity';
import { Journey } from './journey/entities/journey.entity';
import {Spot} from './spot/entities/spot.entity'
import { Spot } from './spot/entities/spot.entity';
import { PhotoModule } from './photo/module/photo.module';
import { Photo } from './photo/entity/photo.entity';
import { DataSource } from 'typeorm';
import { SpotV2 } from './spot/entities/spot.v2.entity';
import { JourneyV2 } from './journey/entities/journey.v2.entity';
dotenv.config();

@Module({
Expand All @@ -25,9 +30,7 @@ dotenv.config();
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
entities: [
User, Journey, Spot,
],
entities: [User, Journey, Spot, Photo, SpotV2, JourneyV2],
synchronize: false,
legacySpatialSupport: false,
}),
Expand All @@ -38,11 +41,13 @@ dotenv.config();
JourneyModule,
UserModule,
SpotModule,
PhotoModule,
],
controllers: [AppController, ReleaseController],
providers: [AppService],
})
export class AppModule {
constructor(private dataSource: DataSource) {}
configure(consumer: MiddlewareConsumer) {
consumer.apply(LoggerMiddleware).forRoutes('/*');
}
Expand Down
248 changes: 166 additions & 82 deletions BE/musicspot/src/journey/controller/journey.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
Param,
Delete,
Version,
UseInterceptors,
UploadedFiles,
} from '@nestjs/common';
import { JourneyService } from '../service/journey.service';
import { StartJourneyReqDTO } from '../dto/journeyStart/journeyStart.dto';
Expand Down Expand Up @@ -44,12 +46,18 @@ import {
EndJourneyReqDTOV2,
EndJourneyResDTOV2,
} from '../dto/v2/endJourney.v2.dto';
import { FilesInterceptor } from '@nestjs/platform-express';
import {
RecordSpotReqDTOV2,
RecordSpotResDTOV2,
} from '../../spot/dto/v2/recordSpot.v2.dto';
import { JourneyV2DTO } from '../dto/v2/jounrey.dto';

@Controller('journey')
@ApiTags('journey 관련 API')
export class JourneyController {
constructor(private journeyService: JourneyService) {}

@ApiTags('Journey V1')
@ApiOperation({
summary: '여정 시작 API',
description: '여정 기록을 시작합니다.',
Expand All @@ -63,20 +71,25 @@ export class JourneyController {
return await this.journeyService.insertJourneyData(startJourneyDTO);
}

@Version('2')
@ApiOperation({
summary: '여정 시작 API(V2)',
description: '여정 기록을 시작합니다.',
})
@ApiCreatedResponse({
description: '생성된 여정 데이터를 반환',
type: StartJourneyResDTOV2,
})
@Post('start')
async createV2(@Body() startJourneyDTO: StartJourneyReqDTOV2) {
return await this.journeyService.insertJourneyDataV2(startJourneyDTO);
}
// @Version('2')
// @ApiOperation({
// summary: '여정 시작 API(V2)',
// description: '여정 기록을 시작합니다.',
// })
// @ApiCreatedResponse({
// description: '생성된 여정 데이터를 반환',
// type: StartJourneyResDTOV2,
// })
// @Post('start')
// async createV2(@Body() startJourneyDTO: StartJourneyReqDTOV2) {
// try {
// return await this.journeyService.insertJourneyDataV2(startJourneyDTO);
// } catch (err) {
// console.log(err);
// }
// }

@ApiTags('Journey V1')
@ApiOperation({
summary: '여정 종료 API',
description: '여정을 종료합니다.',
Expand All @@ -90,6 +103,7 @@ export class JourneyController {
return await this.journeyService.end(endJourneyReqDTO);
}

@ApiTags('Journey V2')
@Version('2')
@ApiOperation({
summary: '여정 종료 API(V2)',
Expand All @@ -99,11 +113,19 @@ export class JourneyController {
description: '여정 종료 정보 반환',
type: EndJourneyResDTOV2,
})
@Post('end')
async endV2(@Body() endJourneyReqDTO: EndJourneyReqDTOV2) {
return await this.journeyService.endV2(endJourneyReqDTO);
@Post(':journeyId/end')
async endV2(
@Param('journeyId') journeyId: number,
@Body() endJourneyReqDTO: EndJourneyReqDTOV2,
) {
try {
return await this.journeyService.endV2(journeyId, endJourneyReqDTO);
} catch (err) {
console.log(err);
}
}

@ApiTags('Journey V1')
@ApiOperation({
summary: '여정 좌표 기록API',
description: '여정의 좌표를 기록합니다.',
Expand All @@ -119,52 +141,54 @@ export class JourneyController {
return returnData;
}

@Version('2')
@ApiOperation({
summary: '여정 조회 API',
description: '해당 범위 내의 여정들을 반환합니다.',
})
@ApiQuery({
name: 'userId',
description: '유저 ID',
required: true,
example: 'yourUserId',
})
@ApiQuery({
name: 'minCoordinate',
description: '최소 좌표',
required: true,
example: '37.5 127.0',
})
@ApiQuery({
name: 'maxCoordinate',
description: '최대 좌표',
required: true,
example: '38.0 128.0',
})
@ApiCreatedResponse({
description: '범위에 있는 여정의 기록들을 반환',
type: CheckJourneyResDTO,
})
@Get()
@UsePipes(ValidationPipe)
async getJourneyByCoordinate(
@Query('userId') userId: UUID,
@Query('minCoordinate') minCoordinate: string,
@Query('maxCoordinate') maxCoordinate: string,
) {
console.log('min:', minCoordinate, 'max:', maxCoordinate);
const checkJourneyDTO = {
userId,
minCoordinate,
maxCoordinate,
};
return await this.journeyService.getJourneyByCoordinationRangeV2(
checkJourneyDTO,
);
}
// @Version('2')
// @ApiOperation({
// summary: '여정 조회 API',
// description: '해당 범위 내의 여정들을 반환합니다.',
// })
// @ApiQuery({
// name: 'userId',
// description: '유저 ID',
// required: true,
// example: 'yourUserId',
// })
// @ApiQuery({
// name: 'minCoordinate',
// description: '최소 좌표',
// required: true,
// example: '37.5 127.0',
// })
// @ApiQuery({
// name: 'maxCoordinate',
// description: '최대 좌표',
// required: true,
// example: '38.0 128.0',
// })
// @ApiCreatedResponse({
// description: '범위에 있는 여정의 기록들을 반환',
// type: CheckJourneyResDTO,
// })
// @Get()
// @UsePipes(ValidationPipe)
// async getJourneyByCoordinate(
// @Query('userId') userId: UUID,
// @Query('minCoordinate') minCoordinate: string,
// @Query('maxCoordinate') maxCoordinate: string,
// ) {
// console.log('min:', minCoordinate, 'max:', maxCoordinate);
// const checkJourneyDTO = {
// userId,
// minCoordinate,
// maxCoordinate,
// };
// return await this.journeyService.getJourneyByCoordinationRangeV2(
// checkJourneyDTO,
// );
// }

@ApiTags('Journey V1')
@ApiOperation({
summary: '여정 조회 API',
summary: '여정 조회 API(Coordinate 범위)',
description: '해당 범위 내의 여정들을 반환합니다.',
})
@ApiQuery({
Expand Down Expand Up @@ -211,21 +235,27 @@ export class JourneyController {
);
}

@Version('2')
@ApiOperation({
summary: '최근 여정 조회 API',
description: '진행 중인 여정이 있었는 지 확인',
})
@ApiCreatedResponse({
description: '사용자가 진행중이었던 여정 정보',
type: LastJourneyResDTO,
})
@Get('last')
async loadLastDataV2(@Body('userId') userId) {
return await this.journeyService.getLastJourneyByUserIdV2(userId);
}
// @Version('2')
// @ApiOperation({
// summary: '최근 여정 조회 API',
// description: '진행 중인 여정이 있었는 지 확인',
// })
// @ApiCreatedResponse({
// description: '사용자가 진행중이었던 여정 정보',
// type: LastJourneyResDTO,
// })
// @Get('last')
// async loadLastDataV2(@Body('userId') userId) {
// try {
// return await this.journeyService.getLastJourneyByUserIdV2(userId);
// } catch (err) {
// console.log(err);
// }
// }

@ApiTags('Journey V1')
@ApiOperation({
summary: '최근 여정 조회 API',
summary: '마지막 여정 진행 중 여부 확인 API',
description: '진행 중인 여정이 있었는 지 확인',
})
@ApiCreatedResponse({
Expand All @@ -236,23 +266,29 @@ export class JourneyController {
async loadLastData(@Body('userId') userId) {
return await this.journeyService.getLastJourneyByUserId(userId);
}

@ApiTags('Journey V2')
@Version('2')
@ApiOperation({
summary: '여정 조회 API',
summary: '여정 조회 API(journeyId)',
description: 'journey id를 통해 여정을 조회',
})
@ApiCreatedResponse({
description: 'journey id에 해당하는 여정을 반환',
type: [Journey],
type: JourneyV2DTO,
isArray: true,
})
@Get(':journeyId')
async getJourneyByIdV2(@Param('journeyId') journeyId: string) {
return await this.journeyService.getJourneyByIdV2(journeyId);
async getJourneyByIdV2(@Param('journeyId') journeyId: number) {
try {
return await this.journeyService.getJourneyByIdV2(journeyId);
} catch (err) {
console.log(err);
}
}

@ApiTags('Journey V1')
@ApiOperation({
summary: '여정 조회 API',
summary: '여정 조회 API(journeyId)',
description: 'journey id를 통해 여정을 조회',
})
@ApiCreatedResponse({
Expand All @@ -264,6 +300,7 @@ export class JourneyController {
return await this.journeyService.getJourneyById(journeyId);
}

@ApiTags('Journey V1')
@ApiOperation({
summary: '여정 삭제 api',
description: 'journey id에 따른 여정 삭제',
Expand All @@ -276,4 +313,51 @@ export class JourneyController {
async deleteJourneyById(@Body() deleteJourneyDto: DeleteJourneyReqDTO) {
return await this.journeyService.deleteJourneyById(deleteJourneyDto);
}

@ApiTags('Spot V2')
@Version('2')
@ApiOperation({
summary: 'spot 저장 api(V2)',
description: '복수개의 사진을 가지는 spot을 저장',
})
@ApiCreatedResponse({
description: '저장된 spot을 반환(presigned url)',
type: RecordSpotResDTOV2,
})
@UseInterceptors(FilesInterceptor('images'))
@Post(':journeyId/spot')
async saveSpotToJourney(
@UploadedFiles() images: Array<Express.Multer.File>,
@Param('journeyId') journeyId: string,
@Body() recordSpotDto: RecordSpotReqDTOV2,
) {
try {
return await this.journeyService.saveSpot(
images,
journeyId,
recordSpotDto,
);
} catch (err) {
console.log(err);
}
}

@ApiTags('Journey V2')
@Version('2')
@ApiOperation({
summary: 'journey 삭제 API',
description: 'journey id를 통해 journey 데이터 삭제'
})
@ApiCreatedResponse({
description: '여정 삭제'
})
@Delete(':journeyId')
async deleteJourney(@Param('journeyId') journeyId:number){
try{
return this.journeyService.deleteJourney(journeyId);
} catch (err){
console.log(err)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class SpotDTO {
readonly photoUrl: string;
}

class journeyMetadataDto {
export class journeyMetadataDto {
@ApiProperty({
description: '여정 시작 시간',
example: '2023-11-22T15:30:00.000+09:00',
Expand Down
Loading

0 comments on commit f029682

Please sign in to comment.