From c9c344617b427158530d65b403c7aec914ae58a9 Mon Sep 17 00:00:00 2001 From: Seokyun Ha Date: Sun, 29 Oct 2023 22:44:07 +0900 Subject: [PATCH] Implement Benefits Module (#79) --- .../benefit/affiliate/affiliate.controller.ts | 57 +++++++++++++++++++ src/popo/benefit/affiliate/affiliate.dto.ts | 5 ++ .../benefit/affiliate/affiliate.entity.ts | 29 ++++++++++ .../benefit/affiliate/affiliate.module.ts | 15 +++++ .../benefit/affiliate/affiliate.service.ts | 34 +++++++++++ src/popo/benefit/benefit.module.ts | 11 ++++ .../benefit/discount/discount.controller.ts | 57 +++++++++++++++++++ src/popo/benefit/discount/discount.dto.ts | 7 +++ src/popo/benefit/discount/discount.entity.ts | 35 ++++++++++++ src/popo/benefit/discount/discount.module.ts | 15 +++++ src/popo/benefit/discount/discount.service.ts | 34 +++++++++++ src/popo/popo.module.ts | 16 +++--- 12 files changed, 308 insertions(+), 7 deletions(-) create mode 100644 src/popo/benefit/affiliate/affiliate.controller.ts create mode 100644 src/popo/benefit/affiliate/affiliate.dto.ts create mode 100644 src/popo/benefit/affiliate/affiliate.entity.ts create mode 100644 src/popo/benefit/affiliate/affiliate.module.ts create mode 100644 src/popo/benefit/affiliate/affiliate.service.ts create mode 100644 src/popo/benefit/benefit.module.ts create mode 100644 src/popo/benefit/discount/discount.controller.ts create mode 100644 src/popo/benefit/discount/discount.dto.ts create mode 100644 src/popo/benefit/discount/discount.entity.ts create mode 100644 src/popo/benefit/discount/discount.module.ts create mode 100644 src/popo/benefit/discount/discount.service.ts diff --git a/src/popo/benefit/affiliate/affiliate.controller.ts b/src/popo/benefit/affiliate/affiliate.controller.ts new file mode 100644 index 0000000..45d65f1 --- /dev/null +++ b/src/popo/benefit/affiliate/affiliate.controller.ts @@ -0,0 +1,57 @@ +import { + Body, + Controller, + Delete, + Get, + Param, + Post, + Put, + UseGuards, +} from '@nestjs/common'; +import { ApiBody, ApiTags } from '@nestjs/swagger'; + +import { AffiliateService } from './affiliate.service'; +import { AffiliateDto } from './affiliate.dto'; +import { Roles } from 'src/auth/authroization/roles.decorator'; +import { RolesGuard } from 'src/auth/authroization/roles.guard'; +import { UserType } from 'src/popo/user/user.meta'; +import { JwtAuthGuard } from 'src/auth/guards/jwt-auth.guard'; + +@ApiTags('Benefit/Affiliate') +@Controller('benefit/affiliate') +export class AffiliateController { + constructor(private readonly affiliateService: AffiliateService) {} + + @Post() + @Roles(UserType.admin, UserType.association) + @UseGuards(JwtAuthGuard, RolesGuard) + @ApiBody({ type: AffiliateDto }) + createAffiliate(@Body() dto: AffiliateDto) { + return this.affiliateService.save(dto); + } + + @Get() + getAllAffiliates() { + return this.affiliateService.findAll(); + } + + @Get(':id') + getAffiliateByUuid(@Param('id') id: number) { + return this.affiliateService.findById(id); + } + + @Put(':id') + @Roles(UserType.admin, UserType.association) + @UseGuards(JwtAuthGuard, RolesGuard) + @ApiBody({ type: AffiliateDto }) + updateAffiliate(@Param('id') id: number, @Body() dto: AffiliateDto) { + return this.affiliateService.update(id, dto); + } + + @Delete(':id') + @Roles(UserType.admin, UserType.association) + @UseGuards(JwtAuthGuard, RolesGuard) + deleteAffiliate(@Param('id') id: number) { + return this.affiliateService.delete(id); + } +} diff --git a/src/popo/benefit/affiliate/affiliate.dto.ts b/src/popo/benefit/affiliate/affiliate.dto.ts new file mode 100644 index 0000000..df75bf8 --- /dev/null +++ b/src/popo/benefit/affiliate/affiliate.dto.ts @@ -0,0 +1,5 @@ +export class AffiliateDto { + readonly title: string; + readonly content_short: string; + readonly content: string; +} diff --git a/src/popo/benefit/affiliate/affiliate.entity.ts b/src/popo/benefit/affiliate/affiliate.entity.ts new file mode 100644 index 0000000..fa6ad79 --- /dev/null +++ b/src/popo/benefit/affiliate/affiliate.entity.ts @@ -0,0 +1,29 @@ +import { + BaseEntity, + Column, + CreateDateColumn, + Entity, + PrimaryGeneratedColumn, + UpdateDateColumn, +} from 'typeorm'; + +@Entity() +export class Affiliate extends BaseEntity { + @PrimaryGeneratedColumn('increment') + id: number; + + @Column({ nullable: false }) + title: string; + + @Column('text', { nullable: true }) + content_short: string; + + @Column('text', { nullable: false }) + content: string; + + @CreateDateColumn() + createdAt: Date; + + @UpdateDateColumn() + updateAt: Date; +} diff --git a/src/popo/benefit/affiliate/affiliate.module.ts b/src/popo/benefit/affiliate/affiliate.module.ts new file mode 100644 index 0000000..aa27efd --- /dev/null +++ b/src/popo/benefit/affiliate/affiliate.module.ts @@ -0,0 +1,15 @@ +import { Module } from '@nestjs/common'; +import { TypeOrmModule } from '@nestjs/typeorm'; + +import { Affiliate } from './affiliate.entity'; +import { AffiliateController } from './affiliate.controller'; +import { AffiliateService } from './affiliate.service'; + +@Module({ + imports: [ + TypeOrmModule.forFeature([Affiliate]), + ], + providers: [AffiliateService], + controllers: [AffiliateController], +}) +export class AffiliateModule {} diff --git a/src/popo/benefit/affiliate/affiliate.service.ts b/src/popo/benefit/affiliate/affiliate.service.ts new file mode 100644 index 0000000..8fc8db2 --- /dev/null +++ b/src/popo/benefit/affiliate/affiliate.service.ts @@ -0,0 +1,34 @@ +import { Injectable } from '@nestjs/common'; +import { InjectRepository } from '@nestjs/typeorm'; +import { Repository } from 'typeorm'; + +import { Affiliate } from './affiliate.entity'; +import { AffiliateDto } from './affiliate.dto'; + +@Injectable() +export class AffiliateService { + constructor( + @InjectRepository(Affiliate) + private readonly affiliateRepo: Repository, + ) {} + + save(dto: AffiliateDto) { + return this.affiliateRepo.save(dto); + } + + findAll() { + return this.affiliateRepo.find(); + } + + findById(id: number) { + return this.affiliateRepo.findOneBy({id: id }); + } + + update(id: number, dto: AffiliateDto) { + return this.affiliateRepo.update({ id: id }, dto); + } + + delete(id: number) { + return this.affiliateRepo.delete({ id: id }); + } +} diff --git a/src/popo/benefit/benefit.module.ts b/src/popo/benefit/benefit.module.ts new file mode 100644 index 0000000..faf50be --- /dev/null +++ b/src/popo/benefit/benefit.module.ts @@ -0,0 +1,11 @@ +import { Module } from '@nestjs/common'; +import { AffiliateModule } from './affiliate/affiliate.module'; +import { DiscountModule } from './discount/discount.module'; + +@Module({ + imports: [ + AffiliateModule, + DiscountModule, + ] +}) +export class BenefitModule {} diff --git a/src/popo/benefit/discount/discount.controller.ts b/src/popo/benefit/discount/discount.controller.ts new file mode 100644 index 0000000..e0efd24 --- /dev/null +++ b/src/popo/benefit/discount/discount.controller.ts @@ -0,0 +1,57 @@ +import { + Body, + Controller, + Delete, + Get, + Param, + Post, + Put, + UseGuards, +} from '@nestjs/common'; +import { ApiBody, ApiTags } from '@nestjs/swagger'; + +import { DiscountService } from './discount.service'; +import { DiscountDto } from './discount.dto'; +import { Roles } from 'src/auth/authroization/roles.decorator'; +import { RolesGuard } from 'src/auth/authroization/roles.guard'; +import { UserType } from 'src/popo/user/user.meta'; +import { JwtAuthGuard } from 'src/auth/guards/jwt-auth.guard'; + +@ApiTags('Benefit/Discount') +@Controller('benefit/discount') +export class DiscountController { + constructor(private readonly discountService: DiscountService) {} + + @Post() + @Roles(UserType.admin, UserType.association) + @UseGuards(JwtAuthGuard, RolesGuard) + @ApiBody({ type: DiscountDto }) + createDiscount(@Body() dto: DiscountDto) { + return this.discountService.save(dto); + } + + @Get() + getAllDiscounts() { + return this.discountService.findAll(); + } + + @Get(':id') + getDiscountByUuid(@Param('id') id: number) { + return this.discountService.findById(id); + } + + @Put(':id') + @Roles(UserType.admin, UserType.association) + @UseGuards(JwtAuthGuard, RolesGuard) + @ApiBody({ type: DiscountDto }) + updateDiscount(@Param('id') id: number, @Body() dto: DiscountDto) { + return this.discountService.update(id, dto); + } + + @Delete(':id') + @Roles(UserType.admin, UserType.association) + @UseGuards(JwtAuthGuard, RolesGuard) + deleteDiscount(@Param('id') id: number) { + return this.discountService.delete(id); + } +} diff --git a/src/popo/benefit/discount/discount.dto.ts b/src/popo/benefit/discount/discount.dto.ts new file mode 100644 index 0000000..de600e4 --- /dev/null +++ b/src/popo/benefit/discount/discount.dto.ts @@ -0,0 +1,7 @@ +export class DiscountDto { + readonly title: string; + readonly region: string; + readonly open_hour: string; + readonly phone: string; + readonly content: string; +} diff --git a/src/popo/benefit/discount/discount.entity.ts b/src/popo/benefit/discount/discount.entity.ts new file mode 100644 index 0000000..24bc11b --- /dev/null +++ b/src/popo/benefit/discount/discount.entity.ts @@ -0,0 +1,35 @@ +import { + BaseEntity, + Column, + CreateDateColumn, + Entity, + PrimaryGeneratedColumn, + UpdateDateColumn, +} from 'typeorm'; + +@Entity() +export class Discount extends BaseEntity { + @PrimaryGeneratedColumn('increment') + id: number; + + @Column({ nullable: false }) + title: string; + + @Column({ nullable: true }) + region: string; + + @Column({ nullable: true }) + open_hour: string; + + @Column({ nullable: true }) + phone: string; + + @Column('text', { nullable: false }) + content: string; + + @CreateDateColumn() + createdAt: Date; + + @UpdateDateColumn() + updateAt: Date; +} diff --git a/src/popo/benefit/discount/discount.module.ts b/src/popo/benefit/discount/discount.module.ts new file mode 100644 index 0000000..6ac6e6b --- /dev/null +++ b/src/popo/benefit/discount/discount.module.ts @@ -0,0 +1,15 @@ +import { Module } from '@nestjs/common'; +import { TypeOrmModule } from '@nestjs/typeorm'; + +import { Discount } from './discount.entity'; +import { DiscountController } from './discount.controller'; +import { DiscountService } from './discount.service'; + +@Module({ + imports: [ + TypeOrmModule.forFeature([Discount]), + ], + providers: [DiscountService], + controllers: [DiscountController], +}) +export class DiscountModule {} diff --git a/src/popo/benefit/discount/discount.service.ts b/src/popo/benefit/discount/discount.service.ts new file mode 100644 index 0000000..e468c6f --- /dev/null +++ b/src/popo/benefit/discount/discount.service.ts @@ -0,0 +1,34 @@ +import { Injectable } from '@nestjs/common'; +import { InjectRepository } from '@nestjs/typeorm'; +import { Repository } from 'typeorm'; + +import { Discount } from './discount.entity'; +import { DiscountDto } from './discount.dto'; + +@Injectable() +export class DiscountService { + constructor( + @InjectRepository(Discount) + private readonly discountRepo: Repository, + ) {} + + save(dto: DiscountDto) { + return this.discountRepo.save(dto); + } + + findAll() { + return this.discountRepo.find(); + } + + findById(id: number) { + return this.discountRepo.findOneBy({id: id }); + } + + update(id: number, dto: DiscountDto) { + return this.discountRepo.update({ id: id }, dto); + } + + delete(id: number) { + return this.discountRepo.delete({ id: id }); + } +} diff --git a/src/popo/popo.module.ts b/src/popo/popo.module.ts index 35ea045..e2e8dc2 100644 --- a/src/popo/popo.module.ts +++ b/src/popo/popo.module.ts @@ -1,21 +1,23 @@ import { Module } from '@nestjs/common'; -import { UserModule } from './user/user.module'; -import { PlaceModule } from './place/place.module'; +import { BenefitModule } from './benefit/benefit.module'; import { EquipModule } from './equip/equip.module'; -import { ReservationModule } from './reservation/reservation.module'; import { IntroduceModule } from './introduce/introduce.module'; -import { WhitebookModule } from './whitebook/whitebook.module'; +import { PlaceModule } from './place/place.module'; +import { ReservationModule } from './reservation/reservation.module'; import { SettingModule } from './setting/setting.module'; +import { UserModule } from './user/user.module'; +import { WhitebookModule } from './whitebook/whitebook.module'; @Module({ imports: [ - UserModule, + BenefitModule, PlaceModule, EquipModule, - ReservationModule, IntroduceModule, - WhitebookModule, + ReservationModule, SettingModule, + UserModule, + WhitebookModule, ], controllers: [], providers: [],