Skip to content

Commit

Permalink
[BE] 여정 기록 api (#97)
Browse files Browse the repository at this point in the history
* swagger 설정

* ✨ MongoDB 설정

MongoDB 설정입니다.

* 📝 Dependency 추가

class-transformer, class-validator, uuid 추가

* ✨ 검증 파이프 추가

검증 파이프 추가

* 🎨 잡다한 코드 수정

테스트 및 의미없는 부분 수정

* ✨ Journal 추가 기능 추가

journal 시작 시 새로운 journal을 db에 추가하고 추가된 journal을 클라이언트로 응답

* test

* test 제거

* ✨ Person 모듈 추가

Person 관련 module, service, controller, schema 추가

* 🧪 Person 모듈 테스트

PersonService 테스트 입니다.

* ✨ Journal 아이디 추가 구현

여정 시작 시 journal id를 유저에 추가하는 기능 구현

* 🧪 사용자 데이터에 journal id 추가하는 기능 테스트

사용자 데이터에 journal id 추가하는 기능 테스트

* 🎨 의존성 추가를 위한 작업

import에 personService를 추가해서 의존성 주입

* 🐛 Import 수정

Person Model이 제대로 주입되지 않는 상황 수정

* ✨ Spot 저장 구현

spot 저장 구현

* 🧪 Spot 저장 테스트 구현

spot 저장 테스트 구현

* 🎨 Rename modules

journals->journey
person->user

* 🎨 Rename spot module

spots->spot 으로 모듈이름 변경

* ✨ Spot 생성 및 spot id 추가

spot 생성하면 해당 journey에 spot id 추가

* ✨ Object storage dependency 추가

object storaghe dependency 추가

* ♻️ Change schema

스키마 변경과 변경에 따른 DTO, 컨트롤러 수정

* 📦 Create 메서드 분리

create 메서드 내부 로직을 모듈화

* 🧪 SpotService 테스트 코드 추가

spotService 테스트 코드 추가

* ✨ swagger api 설명 추가

* ♻️ 환경변수를 통한 보안 강화

* ♻️ Storage 접근 시 환경변수 사용

---------

Co-authored-by: JUNGHOON IM <[email protected]>
  • Loading branch information
twoo1999 and vvans authored Nov 23, 2023
1 parent b9d276c commit 2a42238
Show file tree
Hide file tree
Showing 16 changed files with 348 additions and 16 deletions.
133 changes: 119 additions & 14 deletions BE/musicspot/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion BE/musicspot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"@nestjs/mongoose": "^10.0.2",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/swagger": "^7.1.15",

"@types/multer": "^1.4.10",
"aws-sdk": "^2.348.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"gitmoji-cli": "^9.0.0",
Expand Down
3 changes: 2 additions & 1 deletion BE/musicspot/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AppController } from './app.controller';
import { AppService } from './app.service';
import { MongooseModule } from '@nestjs/mongoose';
import { JourneyModule } from './journey/journey.module';

import { SpotModule } from './spot/spot.module';
import { UserModule } from './user/user.module';
@Module({
imports: [
Expand All @@ -12,6 +12,7 @@ import { UserModule } from './user/user.module';
),
JourneyModule,
UserModule,
SpotModule,
],
controllers: [AppController],
providers: [AppService],
Expand Down
3 changes: 3 additions & 0 deletions BE/musicspot/src/journey/journey.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Test, TestingModule } from '@nestjs/testing';
import { JourneyController } from './journey.controller';

import { StartJourneyDTO } from './dto/journeyStart.dto';
import { JourneyService } from './journey.service';
import mongoose from 'mongoose';
Expand Down Expand Up @@ -29,6 +30,7 @@ describe('JourneyController', () => {
useValue: userModel,
},
],

}).compile();

controller = module.get<JourneyController>(JourneyController);
Expand All @@ -52,5 +54,6 @@ describe('JourneyController', () => {

afterAll(async () => {
mongoose.connection.close();

});
});
3 changes: 3 additions & 0 deletions BE/musicspot/src/journey/journey.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { StartJourneyDTO } from './dto/journeyStart.dto';
import { ApiCreatedResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import { Journey } from './journey.schema';
import { EndJourneyDTO } from './dto/journeyEnd.dto';

@Controller('journey')
@ApiTags('journey 관련 API')
export class JourneyController {
Expand All @@ -18,6 +19,7 @@ export class JourneyController {
description: '생성된 여정 데이터를 반환',
type: Journey,
})

@Post('start')
async create(@Body() startJourneyDTO: StartJourneyDTO) {
return await this.journeyService.create(startJourneyDTO);
Expand All @@ -34,4 +36,5 @@ export class JourneyController {
async end(@Body() endJourneyDTO: EndJourneyDTO) {
return await this.journeyService.end(endJourneyDTO);
}

}
1 change: 1 addition & 0 deletions BE/musicspot/src/journey/journey.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class Journey {

@Prop({ type: String })
timestamp: string;

}

export const JourneySchema = SchemaFactory.createForClass(Journey);
1 change: 1 addition & 0 deletions BE/musicspot/src/journey/journey.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('JourneysService', () => {
let service: JourneyService;
let userModel;
let journeyModel;

beforeAll(async () => {
mongoose.connect(
`mongodb://${process.env.DB_HOST}:${process.env.DB_PORT}/${process.env.DB_NAME}`,
Expand Down
2 changes: 2 additions & 0 deletions BE/musicspot/src/journey/journey.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { InjectModel } from '@nestjs/mongoose';
import { Injectable } from '@nestjs/common';
import { StartJourneyDTO } from './dto/journeyStart.dto';
import { Journey } from './journey.schema';

import { User } from '../user/user.schema';
import { UserService } from '../user/user.service';
import { EndJourneyDTO } from './dto/journeyEnd.dto';
Expand All @@ -14,6 +15,7 @@ export class JourneyService {
@InjectModel(User.name) private userModel: Model<User>,
) {}
async insertJourneyData(startJourneyDTO: StartJourneyDTO) {

const journeyData = {
...startJourneyDTO,
spots: [],
Expand Down
22 changes: 22 additions & 0 deletions BE/musicspot/src/spot/dto/recordSpot.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {
ArrayMaxSize,
ArrayMinSize,
IsArray,
IsNumber,
IsString,
} from 'class-validator';

export class RecordSpotDTO {
@IsString()
readonly journeyId: string;
@IsArray()
@ArrayMaxSize(2, { message: 'coordinate has only 2' })
@ArrayMinSize(2, { message: 'coordinate has only 2' })
@IsNumber({}, { each: true })
readonly coordinate: number[];

@IsString()
readonly timestamp: string;

readonly photoData: Buffer;
}
18 changes: 18 additions & 0 deletions BE/musicspot/src/spot/spot.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { SpotController } from './spot.controller';

describe('SpotController', () => {
let controller: SpotController;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [SpotController],
}).compile();

controller = module.get<SpotController>(SpotController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
});
});
Loading

0 comments on commit 2a42238

Please sign in to comment.