Skip to content

Commit

Permalink
Merge pull request #897 from dangdangwalk/backend/DANG-1265
Browse files Browse the repository at this point in the history
backend/DANG-1265: repository 레이어에 인터페이스 추가
  • Loading branch information
opehn authored Oct 8, 2024
2 parents 6a92620 + 7a729ab commit 8d58390
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 19 deletions.
4 changes: 2 additions & 2 deletions backend/server/src/breed/breed.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { EntityManager, Repository } from 'typeorm';

import { Breed } from './breed.entity';

import { AbstractRepository } from '../common/database/abstract.repository';
import { TypeORMRepository } from '../common/database/typeorm.repository';

@Injectable()
export class BreedRepository extends AbstractRepository<Breed> {
export class BreedRepository extends TypeORMRepository<Breed> {
constructor(
@InjectRepository(Breed)
breedRepository: Repository<Breed>,
Expand Down
21 changes: 21 additions & 0 deletions backend/server/src/common/database/base.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { DeepPartial, FindManyOptions, ObjectLiteral } from 'typeorm';

export interface IBaseRepository<T> {
create(entity: DeepPartial<T>): Promise<T>;

createIfNotExists(entity: DeepPartial<T>, attributes: keyof T | (keyof T)[]): Promise<T>;

insert(entity: Partial<T> | Partial<T>[]): Promise<ObjectLiteral>;

findOneWithNoException(where: FindManyOptions<T>): Promise<T | null>;

findOne(where: object): Promise<T>;

find(where: object): Promise<T[]>;

update(where: object, partialEntity: Partial<T>): Promise<ObjectLiteral>;

delete(where: object): Promise<ObjectLiteral>;

updateAndFindOne(where: object, partialEntity: Partial<T>): Promise<T>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import {
} from 'typeorm';
import { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity';

export abstract class AbstractRepository<T extends ObjectLiteral> {
import { IBaseRepository } from './base.interface';

export abstract class TypeORMRepository<T extends ObjectLiteral> implements IBaseRepository<T> {
constructor(
private readonly entityRepository: Repository<T>,
private readonly entityManager: EntityManager,
Expand Down
4 changes: 2 additions & 2 deletions backend/server/src/dog-walk-day/dog-walk-day.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { EntityManager, Repository } from 'typeorm';

import { DogWalkDay } from './dog-walk-day.entity';

import { AbstractRepository } from '../common/database/abstract.repository';
import { TypeORMRepository } from '../common/database/typeorm.repository';

@Injectable()
export class DogWalkDayRepository extends AbstractRepository<DogWalkDay> {
export class DogWalkDayRepository extends TypeORMRepository<DogWalkDay> {
constructor(
@InjectRepository(DogWalkDay)
dogWalkDayRepository: Repository<DogWalkDay>,
Expand Down
4 changes: 2 additions & 2 deletions backend/server/src/dogs/dogs.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { EntityManager, Repository } from 'typeorm';

import { Dogs } from './dogs.entity';

import { AbstractRepository } from '../common/database/abstract.repository';
import { TypeORMRepository } from '../common/database/typeorm.repository';

@Injectable()
export class DogsRepository extends AbstractRepository<Dogs> {
export class DogsRepository extends TypeORMRepository<Dogs> {
constructor(
@InjectRepository(Dogs)
dogsRepository: Repository<Dogs>,
Expand Down
4 changes: 2 additions & 2 deletions backend/server/src/excrements/excrements.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { EntityManager, Repository } from 'typeorm';

import { Excrements } from './excrements.entity';

import { AbstractRepository } from '../common/database/abstract.repository';
import { TypeORMRepository } from '../common/database/typeorm.repository';

export class ExcrementsRepository extends AbstractRepository<Excrements> {
export class ExcrementsRepository extends TypeORMRepository<Excrements> {
constructor(
@InjectRepository(Excrements) excrementsRepository: Repository<Excrements>,
entityManager: EntityManager,
Expand Down
4 changes: 2 additions & 2 deletions backend/server/src/journals-dogs/journals-dogs.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { EntityManager, Repository } from 'typeorm';

import { JournalsDogs } from './journals-dogs.entity';

import { AbstractRepository } from '../common/database/abstract.repository';
import { TypeORMRepository } from '../common/database/typeorm.repository';

@Injectable()
export class JournalsDogsRepository extends AbstractRepository<JournalsDogs> {
export class JournalsDogsRepository extends TypeORMRepository<JournalsDogs> {
constructor(
@InjectRepository(JournalsDogs)
journalsDogsRepository: Repository<JournalsDogs>,
Expand Down
4 changes: 2 additions & 2 deletions backend/server/src/journals/journals.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { EntityManager, Repository } from 'typeorm';

import { Journals } from './journals.entity';

import { AbstractRepository } from '../common/database/abstract.repository';
import { TypeORMRepository } from '../common/database/typeorm.repository';

@Injectable()
export class JournalsRepository extends AbstractRepository<Journals> {
export class JournalsRepository extends TypeORMRepository<Journals> {
constructor(
@InjectRepository(Journals)
walkJournalRepository: Repository<Journals>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { EntityManager, Repository } from 'typeorm';

import { TodayWalkTime } from './today-walk-time.entity';

import { AbstractRepository } from '../common/database/abstract.repository';
import { TypeORMRepository } from '../common/database/typeorm.repository';

@Injectable()
export class TodayWalkTimeRepository extends AbstractRepository<TodayWalkTime> {
export class TodayWalkTimeRepository extends TypeORMRepository<TodayWalkTime> {
constructor(
@InjectRepository(TodayWalkTime)
todayWalkTimeRepository: Repository<TodayWalkTime>,
Expand Down
4 changes: 2 additions & 2 deletions backend/server/src/users-dogs/users-dogs.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { EntityManager, Repository } from 'typeorm';

import { UsersDogs } from './users-dogs.entity';

import { AbstractRepository } from '../common/database/abstract.repository';
import { TypeORMRepository } from '../common/database/typeorm.repository';

@Injectable()
export class UsersDogsRepository extends AbstractRepository<UsersDogs> {
export class UsersDogsRepository extends TypeORMRepository<UsersDogs> {
constructor(
@InjectRepository(UsersDogs)
usersDogsRepository: Repository<UsersDogs>,
Expand Down
4 changes: 2 additions & 2 deletions backend/server/src/users/users.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { EntityManager, Repository } from 'typeorm';

import { Users } from './users.entity';

import { AbstractRepository } from '../common/database/abstract.repository';
import { TypeORMRepository } from '../common/database/typeorm.repository';

@Injectable()
export class UsersRepository extends AbstractRepository<Users> {
export class UsersRepository extends TypeORMRepository<Users> {
constructor(
@InjectRepository(Users)
usersRepository: Repository<Users>,
Expand Down

0 comments on commit 8d58390

Please sign in to comment.