-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
✨ [#4]Feat: 지역 테이블 분리
- Loading branch information
Showing
26 changed files
with
407 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { ValidationArguments } from 'class-validator'; | ||
|
||
export const numberValidationMessage = (args: ValidationArguments) => { | ||
return `${args.property}은 number type으로 입력해주세요.`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { PickType } from '@nestjs/swagger'; | ||
import { RegionModel } from '../entities/region.entity'; | ||
|
||
export class CreateRegionDto extends PickType(RegionModel, ['name']) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { PartialType } from '@nestjs/swagger'; | ||
import { CreateRegionDto } from './create-region.dto'; | ||
|
||
export class UpdateRegionDto extends PartialType(CreateRegionDto) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { BaseModel } from '../../common/entity/base.entity'; | ||
import { Column, Entity, OneToMany } from 'typeorm'; | ||
import { IsString } from 'class-validator'; | ||
import { stringValidationMessage } from '../../common/validation-message/string-validation-message'; | ||
import { StoresModel } from '../../stores/entity/stores.entity'; | ||
|
||
@Entity('region') | ||
export class RegionModel extends BaseModel { | ||
@Column() | ||
@IsString({ | ||
message: stringValidationMessage, | ||
}) | ||
name: string; | ||
|
||
@OneToMany(() => StoresModel, (store) => store.region) | ||
stores: StoresModel[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { RegionController } from './region.controller'; | ||
import { RegionService } from './region.service'; | ||
|
||
describe('RegionController', () => { | ||
let controller: RegionController; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [RegionController], | ||
providers: [RegionService], | ||
}).compile(); | ||
|
||
controller = module.get<RegionController>(RegionController); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(controller).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'; | ||
import { RegionService } from './region.service'; | ||
import { CreateRegionDto } from './dto/create-region.dto'; | ||
import { UpdateRegionDto } from './dto/update-region.dto'; | ||
|
||
@Controller('region') | ||
export class RegionController { | ||
constructor(private readonly regionService: RegionService) {} | ||
|
||
@Post() | ||
create(@Body() createRegionDto: CreateRegionDto) { | ||
return this.regionService.create(createRegionDto); | ||
} | ||
|
||
@Get() | ||
findAll() { | ||
return this.regionService.findAll(); | ||
} | ||
|
||
@Get(':id') | ||
findOne(@Param('id') id: string) { | ||
return this.regionService.findOne(+id); | ||
} | ||
|
||
@Patch(':id') | ||
update(@Param('id') id: string, @Body() updateRegionDto: UpdateRegionDto) { | ||
return this.regionService.update(+id, updateRegionDto); | ||
} | ||
|
||
@Delete(':id') | ||
remove(@Param('id') id: string) { | ||
return this.regionService.remove(+id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { RegionService } from './region.service'; | ||
import { RegionController } from './region.controller'; | ||
import { RegionModel } from './entities/region.entity'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([RegionModel])], | ||
controllers: [RegionController], | ||
providers: [RegionService], | ||
}) | ||
export class RegionModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { RegionService } from './region.service'; | ||
|
||
describe('RegionService', () => { | ||
let service: RegionService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [RegionService], | ||
}).compile(); | ||
|
||
service = module.get<RegionService>(RegionService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { CreateRegionDto } from './dto/create-region.dto'; | ||
import { UpdateRegionDto } from './dto/update-region.dto'; | ||
|
||
@Injectable() | ||
export class RegionService { | ||
create(createRegionDto: CreateRegionDto) { | ||
return 'This action adds a new region'; | ||
} | ||
|
||
findAll() { | ||
return `This action returns all region`; | ||
} | ||
|
||
findOne(id: number) { | ||
return `This action returns a #${id} region`; | ||
} | ||
|
||
update(id: number, updateRegionDto: UpdateRegionDto) { | ||
return `This action updates a #${id} region`; | ||
} | ||
|
||
remove(id: number) { | ||
return `This action removes a #${id} region`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { CreateReviewsDto } from './create-reviews.dto'; | ||
import { PartialType } from '@nestjs/swagger'; | ||
|
||
export class UpdateReviewsDto extends PartialType(CreateReviewsDto) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { | ||
BadRequestException, | ||
CanActivate, | ||
ExecutionContext, | ||
Injectable, | ||
UnauthorizedException, | ||
} from '@nestjs/common'; | ||
import { ReviewsService } from '../reviews.service'; | ||
import { UsersModel } from '../../users/entity/users.entity'; | ||
import { Request } from 'express'; | ||
|
||
@Injectable() | ||
export class IsReviewMine implements CanActivate { | ||
constructor(private readonly reviewService: ReviewsService) {} | ||
async canActivate(context: ExecutionContext): Promise<boolean> { | ||
const req = context.switchToHttp().getRequest() as Request & { | ||
user: UsersModel; | ||
}; | ||
|
||
const user = req.user; | ||
|
||
if (!user) { | ||
throw new UnauthorizedException('사용자 정보를 가져올 수 없습니다.'); | ||
} | ||
|
||
// Path Parameter로 reviewId를 받아옵니다. | ||
const reviewId = req.params.reviewId; | ||
|
||
if (!reviewId) { | ||
throw new BadRequestException('리뷰Id가 파라미터로 제공되어야합니다.'); | ||
} | ||
const result = await this.reviewService.isReviewMine( | ||
user.id, | ||
parseInt(reviewId), | ||
); | ||
|
||
if (!result) { | ||
throw new UnauthorizedException('해당 리뷰를 수정할 권한이 없습니다.'); | ||
} | ||
return true; | ||
} | ||
} |
Oops, something went wrong.