Skip to content

Commit

Permalink
Merge pull request #344 from boostcampwm2023/BE/task/restore-release
Browse files Browse the repository at this point in the history
[BE] ♻️ : BE/release -> main merge 문제 해결 시 누락된 코드 복구
  • Loading branch information
twoo1999 authored Jan 5, 2024
2 parents 121bd1d + dafa121 commit b912c42
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 29 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ node_modules


# compiled output
/dist
/node_modules
dist
node_modules

# Logs
logs
Expand Down
4 changes: 3 additions & 1 deletion BE/musicspot/src/common/util/coordinate.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export const is1DArray = (arr) => {
if (!isInCoordinateRange(arr)) {
return false;
}
} else {
return false;
}

return true;
Expand Down Expand Up @@ -33,4 +35,4 @@ export const isInCoordinateRange = (pos) => {
return false;
}
return true;
};
};
4 changes: 2 additions & 2 deletions BE/musicspot/src/journey/controller/journey.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ export class JourneyController {
description: '사용자가 진행중이었던 여정 정보',
type: Journey,
})
@Get('loadLastData')
async loadLastData(@Query('userId') userId: string) {
@Get(':userId/last')
async loadLastData(@Param('userId') userId: string) {
return await this.journeyService.loadLastJourney(userId);
}

Expand Down
52 changes: 33 additions & 19 deletions BE/musicspot/src/journey/service/journey.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,30 +193,44 @@ export class JourneyService {
}

async loadLastJourney(userId) {
const user = await this.userModel.findById(userId).lean();

if (!user) {
const user = await this.userModel.findOne({userId}).lean();
if(!user){
throw new UserNotFoundException();
}

const journeys = user.journeys;

const journey = await this.findLastJourney(journeys);
if (journey) {
return journey;
}
return '진행중이었던 여정이 없습니다.';
}
async findLastJourney(journeys) {
for (let i = 0; i < journeys.length; i++) {
let journey = await this.journeyModel.findById(journeys[i]).lean();
if (!journey) {
throw new JourneyNotFoundException();
}
if (journey.title === '') {
return journey;
const len = journeys.length;
const lastJourneyId = journeys[len-1];

const lastJourney = await this.journeyModel
.findById(lastJourneyId)
.populate({
path: 'spots',
model: 'Spot',
options: {
transform: (spot) => {
return {
coordinate: spot.coordinate,
timestamp: spot.timestamp,
photoUrl: makePresignedUrl(spot.photoKey),
};
},
},
})
.lean();

if (!lastJourney) {
return {
journey: null,
isRecording: false,
};
}
}
return false;

return {
journey: lastJourney.title ? null : lastJourney,
isRecording: lastJourney.title ? false : true,
};
}

async getJourneyById(journeyId) {
Expand Down
2 changes: 1 addition & 1 deletion BE/musicspot/src/spot/service/spot.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as path from 'path';
import { Test, TestingModule } from '@nestjs/testing';
import { SpotService } from './spot.service';
import mongoose from 'mongoose';
import { Spot, SpotSchema } from '../schema/spot.schemaㄴ';
import { Spot, SpotSchema } from '../schema/spot.schema';
import { getModelToken } from '@nestjs/mongoose';

import { Journey, JourneySchema } from '../../journey/schema/journey.schema';
Expand Down
19 changes: 15 additions & 4 deletions BE/musicspot/src/spot/service/spot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
bucketName,
makePresignedUrl,
} from '../../common/s3/objectStorage';
import { coordinateNotCorrectException } from 'src/filters/journey.exception';
import { is1DArray } from 'src/common/util/coordinate.util';
@Injectable()
export class SpotService {
constructor(
Expand All @@ -36,20 +38,29 @@ export class SpotService {
}

async insertToSpot(spotData) {
const data = { ...spotData, coordinate: JSON.parse(spotData.coordinate) };
const data = { ...spotData };
const createdSpotData = await new this.spotModel(data).save();
const spotId = createdSpotData._id;
const {_id, coordinate} = createdSpotData;
await this.journeyModel
.findOneAndUpdate(
{ _id: spotData.journeyId },
{ $push: { spots: spotId } },
{ $push: { spots: _id ,coordinates: coordinate} },
{ new: true },
)
.lean();
return createdSpotData.toObject();
}

async create(file, recordSpotDto) {
let parsedCoordinate;
try {
parsedCoordinate = JSON.parse(recordSpotDto.coordinate);
} catch (err) {
throw new coordinateNotCorrectException();
}
if (!is1DArray(parsedCoordinate)) {
throw new coordinateNotCorrectException();
}
const photoKey = await this.uploadPhotoToStorage(
recordSpotDto.journeyId,
file,
Expand All @@ -58,8 +69,8 @@ export class SpotService {
const createdSpotData = await this.insertToSpot({
...recordSpotDto,
photoKey,
coordinate: parsedCoordinate
});

const { journeyId, coordinate, timestamp } = createdSpotData;
const returnData: RecordSpotResDTO = {
journeyId,
Expand Down

0 comments on commit b912c42

Please sign in to comment.