Skip to content

Commit

Permalink
[BE] 스웨거 api 수정 및 폴더 구조 리팩토링 (#102)
Browse files Browse the repository at this point in the history
* dto 수정

* .env

* 폴더 수정 완료
  • Loading branch information
vvans authored Nov 23, 2023
1 parent 266a0b4 commit 9434edf
Show file tree
Hide file tree
Showing 24 changed files with 156 additions and 148 deletions.
4 changes: 3 additions & 1 deletion BE/musicspot/.env
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
MONGODB_URI=mongodb://localhost:27017/musicspot
DB_HOST=localhost
DB_PORT=27017
DB_NAME=musicspot
6 changes: 3 additions & 3 deletions BE/musicspot/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Module } from '@nestjs/common';
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';
import { JourneyModule } from './journey/module/journey.module';
import { SpotModule } from './spot/module/spot.module';
import { UserModule } from './user/module/user.module';
import * as dotenv from 'dotenv';
dotenv.config();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Test, TestingModule } from '@nestjs/testing';
import { JourneyController } from './journey.controller';

import { StartJourneyDTO } from './dto/journeyStart.dto';
import { JourneyService } from './journey.service';
import { StartJourneyDTO } from '.././dto/journeyStart.dto';
import { JourneyService } from '../service/journey.service';
import mongoose from 'mongoose';
import { User, UserSchema } from '../user/user.schema';
import { Journey, JourneySchema } from './journey.schema';
import { User, UserSchema } from '../../user/schema/user.schema';
import { Journey, JourneySchema } from '../schema/journey.schema';
import { getModelToken } from '@nestjs/mongoose';

describe('JourneyController', () => {
Expand All @@ -30,7 +30,6 @@ describe('JourneyController', () => {
useValue: userModel,
},
],

}).compile();

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

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

});
});
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Controller, Post, Body } from '@nestjs/common';
import { JourneyService } from './journey.service';
import { StartJourneyDTO } from './dto/journeyStart.dto';
import { JourneyService } from '../service/journey.service';
import { StartJourneyDTO } from '.././dto/journeyStart.dto';
import { ApiCreatedResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import { Journey } from './journey.schema';
import { EndJourneyDTO } from './dto/journeyEnd.dto';
import { RecordJourneyDTO } from './dto/journeyRecord.dto';
import { Journey } from '../schema/journey.schema';
import { EndJourneyDTO } from '.././dto/journeyEnd.dto';
import { RecordJourneyDTO } from '.././dto/journeyRecord.dto';

@Controller('journey')
@ApiTags('journey 관련 API')
Expand Down
6 changes: 6 additions & 0 deletions BE/musicspot/src/journey/dto/journeyEnd.dto.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ApiProperty } from '@nestjs/swagger';
import {
ArrayMaxSize,
ArrayMinSize,
Expand All @@ -7,6 +8,11 @@ import {
} from 'class-validator';

export class EndJourneyDTO {
@ApiProperty({
example: '655efda2fdc81cae36d20650',
description: '여정 id',
required: true,
})
@IsString()
readonly _id: string;

Expand Down
16 changes: 16 additions & 0 deletions BE/musicspot/src/journey/dto/journeyStart.dto.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ApiProperty } from '@nestjs/swagger';
import {
ArrayMaxSize,
ArrayMinSize,
Expand All @@ -7,15 +8,30 @@ import {
} from 'class-validator';

export class StartJourneyDTO {
@ApiProperty({
example: [37.555946, 126.972384],
description: '위치 좌표',
required: true,
})
@IsArray()
@ArrayMaxSize(2, { message: 'coordinate has only 2' })
@ArrayMinSize(2, { message: 'coordinate has only 2' })
@IsNumber({}, { each: true })
readonly coordinate: number[];

@ApiProperty({
example: '2023-11-22T12:00:00Z',
description: 'timestamp',
required: true,
})
@IsString()
readonly timestamp: string;

@ApiProperty({
example: '[email protected]',
description: '이메일',
required: true,
})
@IsString()
readonly email: string;
}
103 changes: 0 additions & 103 deletions BE/musicspot/src/journey/journey.service.spec.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Module } from '@nestjs/common';
import { JourneyController } from './journey.controller';
import { JourneyService } from './journey.service';
import { JourneyController } from '../controller/journey.controller';
import { JourneyService } from '../service/journey.service';
import { MongooseModule } from '@nestjs/mongoose';
import { JourneySchema, Journey } from './journey.schema';
import { UserService } from '../user/user.service';
import { User, UserSchema } from 'src/user/user.schema';
import { UserModule } from '../user/user.module';
import { JourneySchema, Journey } from '../schema/journey.schema';
import { UserService } from '../../user/serivce/user.service';
import { User, UserSchema } from 'src/user/schema/user.schema';
import { UserModule } from '../../user/module/user.module';

@Module({
imports: [
Expand Down
File renamed without changes.
68 changes: 68 additions & 0 deletions BE/musicspot/src/journey/service/journey.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { Test, TestingModule } from '@nestjs/testing';
import { JourneyService } from './journey.service';
import mongoose from 'mongoose';
import { User, UserSchema } from '../../user/schema/user.schema';
import { Journey, JourneySchema } from '../schema/journey.schema';
import { getModelToken } from '@nestjs/mongoose';
import { StartJourneyDTO } from '../dto/journeyStart.dto';
import { UserService } from '../../user/serivce/user.service';

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}`,
);
userModel = mongoose.model(User.name, UserSchema);
journeyModel = mongoose.model(Journey.name, JourneySchema);

const module: TestingModule = await Test.createTestingModule({
providers: [
JourneyService,
UserService,
{
provide: getModelToken(Journey.name),
useValue: journeyModel,
},
{
provide: getModelToken(User.name),
useValue: userModel,
},
],
}).compile();

service = module.get<JourneyService>(JourneyService);
});

it('journey 시작 테스트', async () => {
const coordinate = [37.675986, 126.776032];
const timestamp = '2023-11-22T15:30:00.000+09:00';
const email = 'test-email';

const createJourneyData: StartJourneyDTO = {
coordinate,
timestamp,
email,
};

const createdJourneyData =
await service.insertJourneyData(createJourneyData);
expect(coordinate).toEqual(createdJourneyData.coordinates[0]);
expect(timestamp).toEqual(createdJourneyData.timestamp);
expect(createdJourneyData.spots).toEqual([]);

const updateUserInfo = await service.pushJourneyIdToUser(
createdJourneyData._id,
email,
);
// console.log(createdUserData);
expect(updateUserInfo.modifiedCount).toEqual(1);
});

afterAll(async () => {
mongoose.connection.close();
});
});
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Model } from 'mongoose';
import { InjectModel } from '@nestjs/mongoose';
import { Injectable } from '@nestjs/common';
import { StartJourneyDTO } from './dto/journeyStart.dto';
import { Journey } from './journey.schema';
import { StartJourneyDTO } from '../dto/journeyStart.dto';
import { Journey } from '../schema/journey.schema';

import { User } from '../user/user.schema';
import { UserService } from '../user/user.service';
import { EndJourneyDTO } from './dto/journeyEnd.dto';
import { RecordJourneyDTO } from './dto/journeyRecord.dto';
import { User } from '../../user/schema/user.schema';
import { UserService } from '../../user/serivce/user.service';
import { EndJourneyDTO } from '../dto/journeyEnd.dto';
import { RecordJourneyDTO } from '../dto/journeyRecord.dto';

@Injectable()
export class JourneyService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import {
UploadedFile,
} from '@nestjs/common';
import { ApiCreatedResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import { RecordSpotDTO } from './dto/recordSpot.dto';
import { SpotService } from './spot.service';
import { RecordSpotDTO } from '../dto/recordSpot.dto';
import { SpotService } from '../service/spot.service';
import { FileInterceptor } from '@nestjs/platform-express';
import { Spot } from './spot.schema';
import { Spot } from '../schema/spot.schema';
@Controller('spot')
@ApiTags('spot 관련 API')
export class SpotController {
Expand Down
23 changes: 22 additions & 1 deletion BE/musicspot/src/spot/dto/recordSpot.dto.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ApiProperty } from '@nestjs/swagger';
import {
ArrayMaxSize,
ArrayMinSize,
Expand All @@ -7,16 +8,36 @@ import {
} from 'class-validator';

export class RecordSpotDTO {
@ApiProperty({
example: '655efda2fdc81cae36d20650',
description: '여정 id',
required: true,
})
@IsString()
readonly journeyId: string;

@ApiProperty({
example: [37.555946, 126.972384],
description: '위치 좌표',
required: true,
})
@IsArray()
@ArrayMaxSize(2, { message: 'coordinate has only 2' })
@ArrayMinSize(2, { message: 'coordinate has only 2' })
@IsNumber({}, { each: true })
readonly coordinate: number[];

@ApiProperty({
example: '2023-11-22T12:00:00Z',
description: 'timestamp',
required: true,
})
@IsString()
readonly timestamp: string;

@ApiProperty({
example: 'base64-encoded-binary-image-data', // Update this with a valid base64-encoded image data
description: 'Buffer',
required: true,
})
readonly photoData: Buffer;
}
Loading

0 comments on commit 9434edf

Please sign in to comment.