-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#41] 학점 등록 / 수정 기능 #44
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ae49f2d
Feat : 학점 controller 제작
namewhat99 644ad77
Feat : 학점 create Service 제작
namewhat99 7b92d4c
Feat : 학점 repository 제작
namewhat99 9bc192f
Fix : AppModule 수정
namewhat99 769c1e4
Feat : PR 전 수정
namewhat99 b61a47d
Feat : grad modify 설정
namewhat99 6b8ee57
Feat : grad modify repository 설정
namewhat99 66643ca
Fix : update 로 modifyGrade 수정
namewhat99 ef8df8e
Fix : test 파일 삭제
namewhat99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { | ||
Body, | ||
Controller, | ||
Delete, | ||
Param, | ||
Patch, | ||
Post, | ||
UseGuards, | ||
} from '@nestjs/common'; | ||
import { GradeService } from './grade.service'; | ||
import { JwtAuthGuard } from '../auth/guard/jwt-auth.guard'; | ||
import { OwnershipGuard } from '../auth/guard/ownership.guard'; | ||
import { UserId } from '../decorator/user-id.decorator'; | ||
|
||
@UseGuards(JwtAuthGuard) | ||
@Controller('api/stat/grade') | ||
export class GradeController { | ||
constructor(private readonly gradeService: GradeService) {} | ||
@Post() | ||
public async createGrade( | ||
@Body('grade') grade: number, | ||
@UserId() userId: string, | ||
) { | ||
await this.gradeService.gradeCreate(userId, grade); | ||
} | ||
|
||
@Patch(':id') | ||
@UseGuards(OwnershipGuard) | ||
public async modifyGrade( | ||
@Body('grade') grade: number, | ||
@Param('id') userId: string, | ||
) { | ||
await this.gradeService.gradeModify(userId, grade); | ||
} | ||
|
||
@Delete(':id') | ||
@UseGuards(OwnershipGuard) | ||
public async deleteGrade() { | ||
await this.gradeService.gradeDelete(); | ||
} | ||
} |
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,10 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { GradeService } from './grade.service'; | ||
import { GradeRepository } from './grade.repository'; | ||
import { GradeController } from './grade.controller'; | ||
|
||
@Module({ | ||
providers: [GradeService, GradeRepository], | ||
controllers: [GradeController], | ||
}) | ||
export class GradeModule {} |
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,36 @@ | ||
import { BaseRepository } from '../utils/base.repository'; | ||
import { Inject, Injectable } from '@nestjs/common'; | ||
import { DataSource, Repository } from 'typeorm'; | ||
import { Github } from '../Entity/github'; | ||
import { REQUEST } from '@nestjs/core'; | ||
import { Grade } from '../Entity/grade'; | ||
|
||
@Injectable() | ||
export class GradeRepository extends BaseRepository { | ||
private repository: Repository<Grade>; | ||
|
||
constructor(dataSource: DataSource, @Inject(REQUEST) req: Request) { | ||
super(dataSource, req); | ||
this.repository = this.getRepository(Grade); | ||
} | ||
|
||
public async save(grade: Grade) { | ||
await this.repository.save(grade); | ||
} | ||
|
||
public async findOne(id: string) { | ||
return await this.repository.findOneBy({ userId: id }); | ||
} | ||
|
||
public async update(newGrade: Grade) { | ||
return await this.repository.update( | ||
{ userId: newGrade.userId }, | ||
{ | ||
grade: newGrade.grade, | ||
point: newGrade.point, | ||
}, | ||
); | ||
} | ||
|
||
public async delete(id: string) {} | ||
} |
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, Injectable } from '@nestjs/common'; | ||
import { GradeRepository } from './grade.repository'; | ||
import { Grade } from '../Entity/grade'; | ||
|
||
@Injectable() | ||
export class GradeService { | ||
constructor(private gradeRepository: GradeRepository) {} | ||
public async gradeCreate(userId: string, grade: number) { | ||
const isExist = await this.gradeRepository.findOne(userId); | ||
|
||
if (isExist) { | ||
throw new BadRequestException('이미 등록했습니다.'); | ||
} | ||
const newGrade = new Grade(); | ||
newGrade.userId = userId; | ||
newGrade.grade = grade; | ||
newGrade.point = this.calculatePoint(grade); | ||
|
||
await this.gradeRepository.save(newGrade); | ||
} | ||
|
||
public async gradeModify(userId: string, grade: number) { | ||
const isExist = await this.gradeRepository.findOne(userId); | ||
|
||
if (!isExist) { | ||
throw new BadRequestException('등록된 학점정보가 없습니다'); | ||
} | ||
|
||
const newGrade = new Grade(); | ||
newGrade.userId = userId; | ||
newGrade.grade = grade; | ||
newGrade.point = this.calculatePoint(grade); | ||
|
||
await this.gradeRepository.update(newGrade); | ||
} | ||
|
||
public async gradeDelete() {} | ||
|
||
public calculatePoint(grade: number) { | ||
return 0; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
개인적인 생각으로는 NotFound 가 더 어울리지 않을까 생각이됩니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아 오키오키 반영해서 올리겠읍니다