Skip to content

Commit

Permalink
✨ feat: 시도, 구군, 음식 카테고리, 피드, 피드 좋아요 entity,repository 추가 (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
yanggwangseong committed Nov 24, 2024
1 parent fa7f671 commit fc07bee
Show file tree
Hide file tree
Showing 14 changed files with 279 additions and 4 deletions.
21 changes: 21 additions & 0 deletions src/entities/article-like.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Entity, JoinColumn, ManyToOne, PrimaryColumn } from "typeorm";

import { ArticleEntity } from "./article.entity";
import { MemberEntity } from "./member.entity";

@Entity("article_likes")
export class ArticleLikeEntity {
@PrimaryColumn({ type: "int" })
articleId!: number;

@ManyToOne(() => ArticleEntity, (article) => article.articleLikes)
@JoinColumn({ name: "articleId", referencedColumnName: "id" })
article!: ArticleEntity;

@PrimaryColumn({ type: "int" })
memberId!: number;

@ManyToOne(() => MemberEntity, (member) => member.articleLikes)
@JoinColumn({ name: "memberId", referencedColumnName: "id" })
member!: MemberEntity;
}
71 changes: 71 additions & 0 deletions src/entities/article.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import {
Column,
CreateDateColumn,
Entity,
JoinColumn,
ManyToOne,
OneToMany,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from "typeorm";

import { ArticleLikeEntity } from "./article-like.entity";
import { CategoryEntity } from "./category.entity";
import { DistrictEntity } from "./district.entity";
import { MemberEntity } from "./member.entity";
import { RegionEntity } from "./region.entity";

@Entity("articles")
export class ArticleEntity {
@PrimaryGeneratedColumn({ type: "int" })
id!: number;

@Column({ type: "varchar", length: 100 })
title!: string;

@Column({ type: "text" })
content!: string;

@Column({ type: "datetime" })
startTime!: Date;

@Column({ type: "datetime" })
endTime!: Date;

@Column({ type: "int" })
memberId!: number;

@ManyToOne(() => MemberEntity, (member) => member.articles)
@JoinColumn({ name: "memberId", referencedColumnName: "id" })
member!: MemberEntity;

@Column({ type: "int" })
categoryId!: number;

@ManyToOne(() => CategoryEntity, (category) => category.articles)
@JoinColumn({ name: "categoryId", referencedColumnName: "id" })
category!: CategoryEntity;

@Column({ type: "int" })
regionId!: number;

@ManyToOne(() => RegionEntity, (region) => region.articles)
@JoinColumn({ name: "regionId", referencedColumnName: "id" })
region!: RegionEntity;

@Column({ type: "int" })
districtId!: number;

@ManyToOne(() => DistrictEntity, (district) => district.articles)
@JoinColumn({ name: "districtId", referencedColumnName: "id" })
district!: DistrictEntity;

@OneToMany(() => ArticleLikeEntity, (articleLike) => articleLike.article)
articleLikes!: ArticleLikeEntity[];

@CreateDateColumn({ type: "timestamp", nullable: false })
createdAt!: Date;

@UpdateDateColumn({ type: "timestamp", nullable: false })
updatedAt!: Date;
}
2 changes: 1 addition & 1 deletion src/entities/block-list.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {

@Entity("block_list")
export class BlockListEntity {
@PrimaryGeneratedColumn()
@PrimaryGeneratedColumn({ type: "int" })
id!: number;

@PrimaryColumn({ type: "int" })
Expand Down
15 changes: 15 additions & 0 deletions src/entities/category.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm";

import { ArticleEntity } from "./article.entity";

@Entity("category")
export class CategoryEntity {
@PrimaryGeneratedColumn({ type: "int" })
id!: number;

@Column({ type: "varchar", length: 50 })
name!: string;

@OneToMany(() => ArticleEntity, (article) => article.category)
articles!: ArticleEntity[];
}
30 changes: 30 additions & 0 deletions src/entities/district.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {
Column,
Entity,
JoinColumn,
ManyToOne,
OneToMany,
PrimaryGeneratedColumn,
} from "typeorm";

import { ArticleEntity } from "./article.entity";
import { RegionEntity } from "./region.entity";

@Entity("district")
export class DistrictEntity {
@PrimaryGeneratedColumn({ type: "int" })
id!: number;

@Column({ type: "varchar", length: 50 })
name!: string;

@Column({ type: "int" })
regionId!: number;

@ManyToOne(() => RegionEntity, (region) => region.districts)
@JoinColumn({ name: "regionId", referencedColumnName: "id" })
region!: RegionEntity;

@OneToMany(() => ArticleEntity, (article) => article.district)
articles!: ArticleEntity[];
}
12 changes: 11 additions & 1 deletion src/entities/member.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ import {
Column,
CreateDateColumn,
Entity,
OneToMany,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from "typeorm";

import { ArticleLikeEntity } from "./article-like.entity";
import { ArticleEntity } from "./article.entity";

@Entity("member")
export class MemberEntity {
@PrimaryGeneratedColumn()
@PrimaryGeneratedColumn({ type: "int" })
id!: number;

@IsNotEmpty()
Expand Down Expand Up @@ -52,6 +56,12 @@ export class MemberEntity {
@Column({ type: "boolean", default: false })
isEmailVerified!: boolean;

@OneToMany(() => ArticleEntity, (article) => article.member)
articles!: ArticleEntity[];

@OneToMany(() => ArticleLikeEntity, (articleLike) => articleLike.member)
articleLikes!: ArticleLikeEntity[];

@CreateDateColumn({ type: "timestamp", nullable: false })
createdAt!: Date;

Expand Down
19 changes: 19 additions & 0 deletions src/entities/region.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from "typeorm";

import { ArticleEntity } from "./article.entity";
import { DistrictEntity } from "./district.entity";

@Entity("region")
export class RegionEntity {
@PrimaryGeneratedColumn({ type: "int" })
id!: number;

@Column({ type: "varchar", length: 50 })
name!: string;

@OneToMany(() => DistrictEntity, (district) => district.region)
districts!: DistrictEntity[];

@OneToMany(() => ArticleEntity, (article) => article.region)
articles!: ArticleEntity[];
}
21 changes: 21 additions & 0 deletions src/repositories/article-likes.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Injectable } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { QueryRunner, Repository } from "typeorm";

import { ArticleLikeEntity } from "@APP/entities/article-like.entity";

@Injectable()
export class ArticleLikesRepository extends Repository<ArticleLikeEntity> {
constructor(
@InjectRepository(ArticleLikeEntity)
private readonly repository: Repository<ArticleLikeEntity>,
) {
super(repository.target, repository.manager, repository.queryRunner);
}

getRepository(qr?: QueryRunner) {
return qr
? qr.manager.getRepository<ArticleLikeEntity>(ArticleLikeEntity)
: this.repository;
}
}
21 changes: 21 additions & 0 deletions src/repositories/articles.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Injectable } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { QueryRunner, Repository } from "typeorm";

import { ArticleEntity } from "@APP/entities/article.entity";

@Injectable()
export class ArticlesRepository extends Repository<ArticleEntity> {
constructor(
@InjectRepository(ArticleEntity)
private readonly repository: Repository<ArticleEntity>,
) {
super(repository.target, repository.manager, repository.queryRunner);
}

getRepository(qr?: QueryRunner) {
return qr
? qr.manager.getRepository<ArticleEntity>(ArticleEntity)
: this.repository;
}
}
4 changes: 3 additions & 1 deletion src/repositories/block-list.repository.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Injectable } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { QueryRunner, Repository } from "typeorm";

import { BlockListEntity } from "@APP/entities/block-list.entity";

@Injectable()
export class BlockListRepository extends Repository<BlockListEntity> {
constructor(
@InjectRepository(BlockListEntity)
Expand All @@ -11,7 +13,7 @@ export class BlockListRepository extends Repository<BlockListEntity> {
super(repository.target, repository.manager, repository.queryRunner);
}

getMembersRepository(qr?: QueryRunner) {
getRepository(qr?: QueryRunner) {
return qr
? qr.manager.getRepository<BlockListEntity>(BlockListEntity)
: this.repository;
Expand Down
21 changes: 21 additions & 0 deletions src/repositories/categories.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Injectable } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { QueryRunner, Repository } from "typeorm";

import { CategoryEntity } from "@APP/entities/category.entity";

@Injectable()
export class CategoriesRepository extends Repository<CategoryEntity> {
constructor(
@InjectRepository(CategoryEntity)
private readonly repository: Repository<CategoryEntity>,
) {
super(repository.target, repository.manager, repository.queryRunner);
}

getRepository(qr?: QueryRunner) {
return qr
? qr.manager.getRepository<CategoryEntity>(CategoryEntity)
: this.repository;
}
}
21 changes: 21 additions & 0 deletions src/repositories/districts.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Injectable } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { QueryRunner, Repository } from "typeorm";

import { DistrictEntity } from "@APP/entities/district.entity";

@Injectable()
export class DistrictsRepository extends Repository<DistrictEntity> {
constructor(
@InjectRepository(DistrictEntity)
private readonly repository: Repository<DistrictEntity>,
) {
super(repository.target, repository.manager, repository.queryRunner);
}

getRepository(qr?: QueryRunner) {
return qr
? qr.manager.getRepository<DistrictEntity>(DistrictEntity)
: this.repository;
}
}
4 changes: 3 additions & 1 deletion src/repositories/members.repository.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Injectable } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { QueryRunner, Repository } from "typeorm";

import { MemberEntity } from "@APP/entities/member.entity";

@Injectable()
export class MembersRepository extends Repository<MemberEntity> {
constructor(
@InjectRepository(MemberEntity)
Expand All @@ -11,7 +13,7 @@ export class MembersRepository extends Repository<MemberEntity> {
super(repository.target, repository.manager, repository.queryRunner);
}

getMembersRepository(qr?: QueryRunner) {
getRepository(qr?: QueryRunner) {
return qr
? qr.manager.getRepository<MemberEntity>(MemberEntity)
: this.repository;
Expand Down
21 changes: 21 additions & 0 deletions src/repositories/regions.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Injectable } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { QueryRunner, Repository } from "typeorm";

import { RegionEntity } from "@APP/entities/region.entity";

@Injectable()
export class RegionsRepository extends Repository<RegionEntity> {
constructor(
@InjectRepository(RegionEntity)
private readonly repository: Repository<RegionEntity>,
) {
super(repository.target, repository.manager, repository.queryRunner);
}

getRepository(qr?: QueryRunner) {
return qr
? qr.manager.getRepository<RegionEntity>(RegionEntity)
: this.repository;
}
}

0 comments on commit fc07bee

Please sign in to comment.