Skip to content

Commit

Permalink
impl
Browse files Browse the repository at this point in the history
  • Loading branch information
saehun committed Jun 29, 2024
1 parent a3a425d commit 2b69d0e
Show file tree
Hide file tree
Showing 14 changed files with 705 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { AuthModule } from './auth/auth.module';
import { getNodeEnv, isIgnoreEnvFile } from './common/helper/env.helper';
import { envValidation } from './common/helper/env.validation';
import { MapModule } from './map/map.module';
import { PlaceModule } from './place/place.module';
import { SearchModule } from './search/search.module';
import { UserMapModule } from './user-map/user-map.module';
import { UserModule } from './user/user.module';
Expand All @@ -30,6 +31,7 @@ import { UserModule } from './user/user.module';
MapModule,
UserMapModule,
SearchModule,
PlaceModule,
],
controllers: [AppController],
providers: [AppService],
Expand Down
17 changes: 16 additions & 1 deletion src/entities/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { GroupMap } from './group-map.entity';
import { KakaoPlace } from './kakao-place.entity';
import { PlaceForMap } from './place-for-map.entity';
import { Place } from './place.entity';
import { UserMap } from './user-map.entity';
import { User } from './user.entity';

Expand All @@ -15,4 +17,17 @@ export * from './user.repository';
export * from './kakao-place.entity';
export * from './kakao-place.repository';

export const entities = [User, GroupMap, UserMap, KakaoPlace];
export * from './place-for-map.entity';
export * from './place-for-map.repository';

export * from './place.entity';
export * from './place.repository';

export const entities = [
User,
GroupMap,
UserMap,
KakaoPlace,
Place,
PlaceForMap,
];
14 changes: 14 additions & 0 deletions src/entities/kakao-place.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ export class KakaoPlace {
})
address: string;

@Property({
type: 'number',
comment: '카카오맵 경도',
default: 0,
})
x: number;

@Property({
type: 'number',
comment: '카카오맵 위도',
default: 0,
})
y: number;

@Property({
type: 'json',
comment: '카카오맵 menuInfo.menuList',
Expand Down
53 changes: 53 additions & 0 deletions src/entities/place-for-map.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {
Entity,
EntityRepositoryType,
ManyToOne,
OneToOne,
PrimaryKeyProp,
Property,
Rel,
} from '@mikro-orm/core';

import { GroupMap } from './group-map.entity';
import { PlaceForMapRepository } from './place-for-map.repository';
import { Place } from './place.entity';
import { User } from './user.entity';

@Entity({
comment: 'GroupMap에 속한 Place',
repository: () => PlaceForMapRepository,
})
export class PlaceForMap {
@ManyToOne(() => GroupMap, { primary: true })
map: Rel<GroupMap>;

@ManyToOne(() => Place, { primary: true })
place: Rel<Place>;

// 나중에 정규화 하고싶으면 PlaceForMapPhoto라는 Entity를 만들어서 관리하면 될듯.
@Property({
type: 'json',
comment: '사진 URL과 코멘트를 담은 객체 배열',
})
comments: { photoUrls: string[]; comment: string; userId: number }[];

// 나중에 정규화 하고싶으면 PlaceForMapLike라는 Entity를 만들어서 관리하면 될듯.
@Property({
type: 'json',
comment: '좋아요 누른 유저 ID 배열',
})
likedUserIds: number[];

@OneToOne(() => User)
createdBy: User;

@Property()
createdAt: Date = new Date();

@Property({ onUpdate: () => new Date() })
updatedAt: Date = new Date();

[PrimaryKeyProp]: ['map', 'place'];

[EntityRepositoryType]: PlaceForMapRepository;
}
5 changes: 5 additions & 0 deletions src/entities/place-for-map.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ExtendedEntityRepository } from 'src/common/helper/extended-repository.helper';

import { PlaceForMap } from './place-for-map.entity';

export class PlaceForMapRepository extends ExtendedEntityRepository<PlaceForMap> {}
46 changes: 46 additions & 0 deletions src/entities/place.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {
Entity,
EntityRepositoryType,
OneToOne,
PrimaryKey,
Property,
} from '@mikro-orm/core';

import { KakaoPlace } from './kakao-place.entity';
import { PlaceRepository } from './place.repository';

@Entity({
comment: '장소 정보',
repository: () => PlaceRepository,
})
export class Place {
@PrimaryKey({
type: 'integer',
autoincrement: true,
})
id: number;

// OneToOne
@OneToOne({ entity: () => KakaoPlace })
kakaoPlace: KakaoPlace;

@Property({
type: 'integer',
comment: '경도',
})
x: number;

@Property({
type: 'integer',
comment: '위도',
})
y: number;

@Property()
createdAt: Date = new Date();

@Property({ onUpdate: () => new Date() })
updatedAt: Date = new Date();

[EntityRepositoryType]: PlaceRepository;
}
5 changes: 5 additions & 0 deletions src/entities/place.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ExtendedEntityRepository } from 'src/common/helper/extended-repository.helper';

import { Place } from './place.entity';

export class PlaceRepository extends ExtendedEntityRepository<Place> {}
Loading

0 comments on commit 2b69d0e

Please sign in to comment.