-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #368 from boostcampwm2023/BE/story/modify-coordina…
…te-coordinates [BE] ✨ : coordinate 형식 변경에 따른 v2 api 구현
- Loading branch information
Showing
11 changed files
with
898 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
BE/musicspot/src/common/decorator/coordinate.v2.decorator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { | ||
registerDecorator, | ||
ValidationOptions, | ||
ValidationArguments, | ||
} from 'class-validator'; | ||
import { isLinestring, isPointString } from '../util/coordinate.v2.util'; | ||
|
||
export function IsCoordinateV2(validationOptions?: ValidationOptions) { | ||
return function (object: object, propertyName: string) { | ||
registerDecorator({ | ||
name: 'isCoordinateV2', | ||
target: object.constructor, | ||
propertyName: propertyName, | ||
options: validationOptions, | ||
validator: { | ||
validate(receiveValue: string, args: ValidationArguments) { | ||
return isPointString(receiveValue); | ||
}, | ||
}, | ||
}); | ||
}; | ||
} | ||
|
||
export function IsCoordinatesV2(validationOptions?: ValidationOptions) { | ||
return function (object: object, propertyName: string) { | ||
registerDecorator({ | ||
name: 'isCoordinatesV2', | ||
target: object.constructor, | ||
propertyName: propertyName, | ||
options: validationOptions, | ||
validator: { | ||
validate(receiveValue: string, args: ValidationArguments) { | ||
return isLinestring(receiveValue); | ||
}, | ||
}, | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
export const isPointString = (pointString: string): boolean => { | ||
const regex = /^\d+.\d+\s\d+.\d+$/; | ||
if (!pointString.match(regex)) { | ||
return false; | ||
} | ||
if (!isCorrectCoordinateRange(pointString)) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
|
||
export const isLinestring = (lineString: string): boolean => { | ||
const regex: RegExp = | ||
/^\d+.\d+\s\d+.\d+,(\d+.\d+\s\d+.\d+,)*\d+.\d+\s\d+.\d+$/; | ||
if (!lineString.match(regex)) { | ||
return false; | ||
} | ||
|
||
const points = lineString.split(','); | ||
for (let i = 0; i < points.length; i++) { | ||
if (!isCorrectCoordinateRange(points[i])) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
|
||
export const isCorrectCoordinateRange = (pointString: string): boolean => { | ||
const [lat, lon] = pointString.split(' ').map((str) => Number(str)); | ||
if (lat > 90 || lat < -90) { | ||
return false; | ||
} | ||
if (lon > 180 || lon < -180) { | ||
return false; | ||
} | ||
|
||
return true; | ||
}; | ||
|
||
export const parseCoordinateFromDtoToGeoV2 = (coordinate: string): string => { | ||
// coordinate = 1 2 | ||
return `POINT(${coordinate})`; | ||
}; | ||
|
||
export const parseCoordinateFromGeoToDtoV2 = (coordinate: string): string => { | ||
// coordinate = 'POINT(1 2)' | ||
|
||
const pointLen = 'POINT('.length; | ||
return coordinate.slice(pointLen, -1); | ||
}; | ||
|
||
export const parseCoordinatesFromDtoToGeoV2 = (coordinates: string): string => { | ||
// coordinates = 1 2,3 4 | ||
return `LINESTRING(${coordinates})`; | ||
}; | ||
|
||
export const parseCoordinatesFromGeoToDtoV2 = (coordinates: string): string => { | ||
// coordinates = 'LINESTRING(1 2,3 4)' | ||
const pointLen = 'LINESTRING('.length; | ||
return coordinates.slice(pointLen, -1); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { | ||
IsString, | ||
IsDateString, | ||
IsNumber, | ||
IsObject, | ||
} from 'class-validator'; | ||
import { IsCoordinatesV2 } from '../../../common/decorator/coordinate.v2.decorator'; | ||
|
||
export class EndJourneyReqDTOV2 { | ||
@ApiProperty({ | ||
example: 20, | ||
description: '여정 id', | ||
required: true, | ||
}) | ||
@IsNumber() | ||
readonly journeyId: number; | ||
|
||
@ApiProperty({ | ||
example: '37.555946 126.972384,37.555946 126.972384', | ||
description: '위치 좌표', | ||
required: true, | ||
}) | ||
@IsCoordinatesV2({ | ||
message: | ||
'잘못된 coordinates 형식입니다. Ex) 37.555946 126.972384,37.555946 126.972384', | ||
}) | ||
readonly coordinates: string; | ||
|
||
@ApiProperty({ | ||
example: '2023-11-22T12:00:00Z', | ||
description: '종료 timestamp', | ||
required: true, | ||
}) | ||
@IsDateString() | ||
readonly endTimestamp: string; | ||
|
||
@ApiProperty({ | ||
example: '여정 제목', | ||
description: '여정 제목', | ||
required: true, | ||
}) | ||
@IsString() | ||
readonly title: string; | ||
|
||
@IsObject() | ||
@ApiProperty({ | ||
description: '노래 정보', | ||
required: true, | ||
}) | ||
readonly song: object; | ||
} | ||
|
||
export class EndJourneyResDTOV2 { | ||
@ApiProperty({ | ||
example: 20, | ||
description: '여정 id', | ||
required: true, | ||
}) | ||
readonly journeyId: number; | ||
|
||
@ApiProperty({ | ||
example: '37.555946 126.972384,37.555946 126.972384', | ||
description: '위치 좌표', | ||
required: true, | ||
}) | ||
readonly coordinates: string; | ||
|
||
@ApiProperty({ | ||
example: '2023-11-22T15:30:00.000+09:00', | ||
description: '여정 종료 시간', | ||
required: true, | ||
}) | ||
readonly endTimestamp: string; | ||
|
||
@ApiProperty({ | ||
example: 2, | ||
description: '기록된 coordinate 수', | ||
required: true, | ||
}) | ||
readonly numberOfCoordinates: number; | ||
|
||
@ApiProperty({ | ||
description: '노래 정보', | ||
required: true, | ||
}) | ||
readonly song: object; | ||
} |
Oops, something went wrong.