Skip to content

Commit

Permalink
Merge pull request #138 from innovationacademy-kr/be_v3/common
Browse files Browse the repository at this point in the history
Be v3/common
  • Loading branch information
sichoi42 authored Oct 31, 2022
2 parents 0f9730f + d1e2556 commit e633df9
Show file tree
Hide file tree
Showing 23 changed files with 240 additions and 2 deletions.
2 changes: 2 additions & 0 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { SearchModule } from './search/search.module';
import { join } from 'path';
import TypeOrmConfigService from './config/typeorm.config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { V3Module } from './v3/v3.module';

@Module({
imports: [
Expand All @@ -32,6 +33,7 @@ import { TypeOrmModule } from '@nestjs/typeorm';
rootPath: join(__dirname, '../../', 'frontend/build/'),
serveRoot: '',
}),
V3Module,
],
})
export class AppModule {}
1 change: 1 addition & 0 deletions backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AppModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableVersioning();
app.setGlobalPrefix('api');
const swaggerConfig = new DocumentBuilder()
.setTitle('Cabi Admin v2 API')
Expand Down
2 changes: 0 additions & 2 deletions backend/src/return/return.controller.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {
BadRequestException,
Controller,
Delete,
Get,
Logger,
Param,
ParseIntPipe,
Patch,
Query,
Expand Down
16 changes: 16 additions & 0 deletions backend/src/v3/cabinet/cabinet.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Controller, Logger, UseGuards } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { JWTAuthGuard } from 'src/auth/auth.guard';
import { CabinetService } from './cabinet.service';

@ApiTags('(V3) Cabinet')
@Controller({
version: '3',
path: 'cabinet',
})
@UseGuards(JWTAuthGuard)
export class CabinetController {
constructor(private cabinetService: CabinetService) {}

private logger = new Logger(CabinetController.name);
}
20 changes: 20 additions & 0 deletions backend/src/v3/cabinet/cabinet.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AuthModule } from 'src/auth/auth.module';
import Cabinet from 'src/entities/cabinet.entity';
import { CabinetController } from './cabinet.controller';
import { CabinetService } from './cabinet.service';
import { CabinetRepository } from './repository/cabinet.repository';

const repo = {
provide: 'ICabinetRepository',
useClass: CabinetRepository,
};

@Module({
imports: [AuthModule, TypeOrmModule.forFeature([Cabinet])],
exports: [CabinetService],
controllers: [CabinetController],
providers: [CabinetService, repo],
})
export class CabinetModule {}
12 changes: 12 additions & 0 deletions backend/src/v3/cabinet/cabinet.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Inject, Injectable, Logger } from '@nestjs/common';
import { ICabinetRepository } from './repository/cabinet.repository.interface';

@Injectable()
export class CabinetService {
private logger = new Logger(CabinetService.name);

constructor(
@Inject('ICabinetRepository')
private cabinetRepository: ICabinetRepository,
) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ICabinetRepository {}
11 changes: 11 additions & 0 deletions backend/src/v3/cabinet/repository/cabinet.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { InjectRepository } from '@nestjs/typeorm';
import Cabinet from 'src/entities/cabinet.entity';
import { Repository } from 'typeorm';
import { ICabinetRepository } from './cabinet.repository.interface';

export class CabinetRepository implements ICabinetRepository {
constructor(
@InjectRepository(Cabinet)
private cabinetRepository: Repository<Cabinet>,
) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface IReturnRepository {}
10 changes: 10 additions & 0 deletions backend/src/v3/return/repository/return.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { InjectRepository } from '@nestjs/typeorm';
import Cabinet from 'src/entities/cabinet.entity';
import { Repository } from 'typeorm';
import { IReturnRepository } from './return.repository.interface';

export class ReturnRepository implements IReturnRepository {
constructor(
@InjectRepository(Cabinet) private cabinetRepository: Repository<Cabinet>,
) {}
}
16 changes: 16 additions & 0 deletions backend/src/v3/return/return.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Controller, Logger, UseGuards } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { JWTAuthGuard } from 'src/auth/auth.guard';
import { ReturnService } from './return.service';

@ApiTags('(V3) Return')
@Controller({
version: '3',
path: 'return',
})
@UseGuards(JWTAuthGuard)
export class ReturnController {
private logger = new Logger(ReturnController.name);

constructor(private returnService: ReturnService) {}
}
20 changes: 20 additions & 0 deletions backend/src/v3/return/return.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AuthModule } from 'src/auth/auth.module';
import Cabinet from 'src/entities/cabinet.entity';
import { CabinetModule } from '../cabinet/cabinet.module';
import { ReturnRepository } from './repository/return.repository';
import { ReturnController } from './return.controller';
import { ReturnService } from './return.service';

const repo = {
provide: 'IReturnRepository',
useClass: ReturnRepository,
};

@Module({
controllers: [ReturnController],
providers: [ReturnService, repo],
imports: [AuthModule, TypeOrmModule.forFeature([Cabinet]), CabinetModule], // for JWTAuthGuard
})
export class ReturnModule {}
13 changes: 13 additions & 0 deletions backend/src/v3/return/return.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Inject, Injectable, Logger } from '@nestjs/common';
import { CabinetService } from 'src/v3/cabinet/cabinet.service';
import { IReturnRepository } from './repository/return.repository.interface';

@Injectable()
export class ReturnService {
private logger = new Logger(ReturnService.name);

constructor(
@Inject('IReturnRepository') private returnRepository: IReturnRepository,
private cabinetService: CabinetService,
) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ISearchRepository {}
14 changes: 14 additions & 0 deletions backend/src/v3/search/repository/search.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { InjectRepository } from '@nestjs/typeorm';
import Cabinet from 'src/entities/cabinet.entity';
import LentLog from 'src/entities/lent.log.entity';
import User from 'src/entities/user.entity';
import { Repository } from 'typeorm';
import { ISearchRepository } from './search.repository.interface';

export class SearchRepository implements ISearchRepository {
constructor(
@InjectRepository(User) private userRepository: Repository<User>,
@InjectRepository(Cabinet) private cabinetRepository: Repository<Cabinet>,
@InjectRepository(LentLog) private lentLogRepository: Repository<LentLog>,
) {}
}
16 changes: 16 additions & 0 deletions backend/src/v3/search/search.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Controller, Logger, UseGuards } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { JWTAuthGuard } from 'src/auth/auth.guard';
import { SearchService } from './search.service';

@ApiTags('(V3) Search')
@Controller({
version: '3',
path: 'search',
})
@UseGuards(JWTAuthGuard)
export class SearchController {
private logger = new Logger(SearchController.name);

constructor(private searchService: SearchService) {}
}
21 changes: 21 additions & 0 deletions backend/src/v3/search/search.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AuthModule } from 'src/auth/auth.module';
import Cabinet from 'src/entities/cabinet.entity';
import LentLog from 'src/entities/lent.log.entity';
import User from 'src/entities/user.entity';
import { SearchRepository } from './repository/search.repository';
import { SearchController } from './search.controller';
import { SearchService } from './search.service';

const repo = {
provide: 'ISearchRepository',
useClass: SearchRepository,
};

@Module({
controllers: [SearchController],
providers: [SearchService, repo],
imports: [AuthModule, TypeOrmModule.forFeature([User, Cabinet, LentLog])],
})
export class SearchModule {}
10 changes: 10 additions & 0 deletions backend/src/v3/search/search.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Inject, Injectable, Logger } from '@nestjs/common';
import { ISearchRepository } from './repository/search.repository.interface';

@Injectable()
export class SearchService {
private logger = new Logger(SearchService.name);
constructor(
@Inject('ISearchRepository') private searchRepository: ISearchRepository,
) {}
}
2 changes: 2 additions & 0 deletions backend/src/v3/user/repository/user.repository.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface IUserRepository {}
10 changes: 10 additions & 0 deletions backend/src/v3/user/repository/user.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { InjectRepository } from '@nestjs/typeorm';
import User from 'src/entities/user.entity';
import { Repository } from 'typeorm';
import { IUserRepository } from './user.repository.interface';

export class UserRepository implements IUserRepository {
constructor(
@InjectRepository(User) private userRepository: Repository<User>,
) {}
}
17 changes: 17 additions & 0 deletions backend/src/v3/user/user.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import User from 'src/entities/user.entity';
import { UserRepository } from './repository/user.repository';
import { UserService } from './user.service';

const repo = {
provide: 'IUserRepository',
useClass: UserRepository,
};

@Module({
imports: [TypeOrmModule.forFeature([User])],
providers: [UserService, repo],
exports: [UserService],
})
export class UserModule {}
10 changes: 10 additions & 0 deletions backend/src/v3/user/user.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Inject } from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import { IUserRepository } from './repository/user.repository.interface';

@Injectable()
export class UserService {
constructor(
@Inject('IUserRepository') private userRepository: IUserRepository,
) {}
}
13 changes: 13 additions & 0 deletions backend/src/v3/v3.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Module } from '@nestjs/common';
import { AuthModule } from 'src/auth/auth.module';
import { CabinetModule } from './cabinet/cabinet.module';
import { ReturnModule } from './return/return.module';
import { SearchModule } from './search/search.module';
import { UserModule } from './user/user.module';

@Module({
imports: [AuthModule, CabinetModule, ReturnModule, SearchModule, UserModule],
controllers: [],
providers: [],
})
export class V3Module {}

0 comments on commit e633df9

Please sign in to comment.