Skip to content

Commit

Permalink
feat: decimal 타입 custom transformer 사용
Browse files Browse the repository at this point in the history
dto 스키마 수정
  • Loading branch information
Miensoap authored and koomchang committed Nov 16, 2024
1 parent a5bb515 commit 8c50abf
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
12 changes: 12 additions & 0 deletions backend/src/config/DecimalTransformer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export class DecimalNumericTransformer {
to(data: number): number {
return data;
}

from(data: string): number {
return parseFloat(data);
}
}

const decimalNumericTransformer = new DecimalNumericTransformer();
export default decimalNumericTransformer;
8 changes: 4 additions & 4 deletions backend/src/place/dto/PlaceListResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export class PlaceListResponse {
readonly id: number,
readonly name: string,
readonly location: {
readonly lat: number;
readonly lng: number;
readonly latitude: number;
readonly longitude: number;
},
readonly google_place_id: string,
readonly category?: string,
Expand All @@ -22,8 +22,8 @@ export class PlaceListResponse {
place.id,
place.name,
{
lat: place.latitude,
lng: place.longitude,
latitude: place.latitude,
longitude: place.longitude,
},
place.googlePlaceId,
place.detailPageUrl,
Expand Down
8 changes: 4 additions & 4 deletions backend/src/place/dto/PlaceSearchResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export class PlaceSearchResponse {
readonly id: number,
readonly name: string,
readonly location: {
readonly lat: number;
readonly lng: number;
readonly latitude: number;
readonly longitude: number;
},
readonly google_place_id: string,
readonly category?: string,
Expand All @@ -22,8 +22,8 @@ export class PlaceSearchResponse {
place.id,
place.name,
{
lat: place.latitude,
lng: place.longitude,
latitude: place.latitude,
longitude: place.longitude,
},
place.googlePlaceId,
place.detailPageUrl,
Expand Down
19 changes: 16 additions & 3 deletions backend/src/place/entity/place.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Column, Entity } from 'typeorm';
import { BaseEntity } from '../../common/BaseEntity';
import decimalNumericTransformer from '@src/config/DecimalTransformer';

@Entity()
export class Place extends BaseEntity {
Expand All @@ -12,13 +13,25 @@ export class Place extends BaseEntity {
@Column({ nullable: true })
thumbnailUrl?: string;

@Column('float', { nullable: true })
@Column('decimal', {
precision: 3,
scale: 2,
transformer: decimalNumericTransformer,
})
rating?: number;

@Column('decimal', { precision: 10, scale: 7 })
@Column('decimal', {
precision: 10,
scale: 7,
transformer: decimalNumericTransformer,
})
longitude: number;

@Column('decimal', { precision: 10, scale: 7 })
@Column('decimal', {
precision: 10,
scale: 7,
transformer: decimalNumericTransformer,
})
latitude: number;

@Column({ nullable: true })
Expand Down

0 comments on commit 8c50abf

Please sign in to comment.