This repository has been archived by the owner on Jun 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from gsainfoteam/hsh2
Hsh2
- Loading branch information
Showing
7 changed files
with
179 additions
and
24 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,15 +1,19 @@ | ||
import {Body, Controller, Post} from '@nestjs/common'; | ||
import {Body, Controller, Post, Req, UseGuards} from '@nestjs/common'; | ||
import {CreateLectureDto} from "../lecture/dto/create-lecture.dto"; | ||
import {LectureService} from "../lecture/lecture.service"; | ||
import {AssignmentService} from "./assignment.service"; | ||
import { CreateAssignmentDto } from './dto/create-assignment.dto'; | ||
import { AuthGuard } from '@nestjs/passport'; | ||
|
||
@Controller('assignment') | ||
@UseGuards(AuthGuard()) | ||
export class AssignmentController { | ||
|
||
constructor(private readonly assignmentService: AssignmentService) {} | ||
|
||
// @Post('/add') | ||
// createLectureAssignment(@Body() assignmentData: CreateassignmentDto): Promise<string> { | ||
// return this.assignmentService.createProfLecture(lectureData); | ||
// } | ||
} | ||
//과제 평가 | ||
@Post('add') | ||
@UseGuards(AuthGuard()) | ||
createLectureAssignment(@Req() req, @Body() createLectureAssignment: CreateAssignmentDto): Promise<string> { | ||
return this.assignmentService.createAssignment(createLectureAssignment, req.user.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
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 |
---|---|---|
@@ -1,6 +1,120 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { | ||
Injectable, | ||
ConflictException, | ||
NotFoundException | ||
} from '@nestjs/common'; | ||
import { CreateAssignmentDto } from './dto/create-assignment.dto'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Assignment } from './entity/assignment.entity'; | ||
import { Repository } from 'typeorm'; | ||
import { Lecture } from 'src/lecture/entity/lecture.entity'; | ||
import { Semester } from 'src/semester/entity/semester.entity'; | ||
import { Year } from 'src/year/entity/year.entity'; | ||
import { User } from 'src/user/entity/user.entity'; | ||
|
||
@Injectable() | ||
export class AssignmentService { | ||
constructor( | ||
@InjectRepository(Assignment) | ||
private assignmentRepository: Repository<Assignment>, | ||
@InjectRepository(Lecture) | ||
private lectureRepository: Repository<Lecture>, | ||
@InjectRepository(Semester) | ||
private semesterRepository: Repository<Semester>, | ||
@InjectRepository(Year) | ||
private yearRepository: Repository<Year>, | ||
@InjectRepository(User) | ||
private userRepository: Repository<User>, | ||
) {} | ||
|
||
async getAll(): Promise<Assignment[]> { | ||
return this.assignmentRepository.find({}); | ||
} | ||
|
||
async createAssignment(createAssignmentDto: CreateAssignmentDto, id:number): Promise<string>{ | ||
const { | ||
practice, | ||
report, | ||
project, | ||
other, | ||
lecture_id, | ||
semester_id, | ||
year | ||
} = createAssignmentDto; | ||
|
||
const user_id = id; | ||
|
||
//강의 검색 | ||
const found = await this.lectureRepository.findOneBy({ id: lecture_id }); | ||
|
||
//해당 과제 작성이력 조회 | ||
const found_user = await this.assignmentRepository.findOne({ | ||
relations: { | ||
lecture: true, | ||
user : true | ||
}, | ||
where: { | ||
user : { | ||
id: user_id | ||
}, | ||
lecture : { | ||
id: lecture_id | ||
}, | ||
} | ||
}); | ||
|
||
if (found_user) { | ||
throw new ConflictException( | ||
`이미 강의의 과제를 평가` | ||
); | ||
} else { // conditon 이전에 (lecture id , uuid)의 꼴이 같지 않는 경우를 세야함. | ||
if (found) { | ||
const assignment = new Assignment(); | ||
assignment.practice = practice; | ||
assignment.report = report; | ||
assignment.project = project; | ||
assignment.other = other; | ||
assignment.user = await this.userRepository.findOne({ | ||
relations : { | ||
records : true, | ||
}, | ||
where : { | ||
id : user_id | ||
} | ||
}) | ||
assignment.years = await this.yearRepository.findOne({ | ||
relations : { | ||
records : true, | ||
}, | ||
where : { | ||
year : year | ||
} | ||
}) | ||
assignment.semesters = await this.semesterRepository.findOne({ | ||
relations: { | ||
records: true, | ||
}, | ||
where : { | ||
id : semester_id | ||
} | ||
}) | ||
assignment.lecture = await this.lectureRepository.findOne({ | ||
relations: { | ||
records: true, | ||
}, | ||
where: { | ||
id: lecture_id, | ||
}, | ||
}); | ||
|
||
await this.assignmentRepository.manager.save(assignment); | ||
return "success"; | ||
} else { | ||
throw new NotFoundException( | ||
`해당되는 id : ${lecture_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,20 @@ | ||
export class CreateAssignmentDto { | ||
|
||
readonly lecture_id: number; | ||
|
||
readonly semester_id: number; | ||
|
||
readonly year: string; | ||
|
||
readonly assignment_EV: string; | ||
|
||
readonly practice: boolean; | ||
|
||
readonly report: boolean; | ||
|
||
readonly project: boolean; | ||
|
||
readonly other: boolean; | ||
|
||
|
||
} |
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