Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request #82 from gsainfoteam/hsh2
Browse files Browse the repository at this point in the history
Hsh2
  • Loading branch information
minjunj authored Jan 4, 2024
2 parents c3e2cd6 + 0e48e71 commit 72a1410
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 11 additions & 7 deletions src/assignment/assignment.controller.ts
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);
}
}
7 changes: 6 additions & 1 deletion src/assignment/assignment.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ import { AssignmentService } from './assignment.service';
import { AssignmentController } from './assignment.controller';
import {TypeOrmModule} from "@nestjs/typeorm";
import {Assignment} from "./entity/assignment.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';
import { Lecture } from 'src/lecture/entity/lecture.entity';


@Module({
imports: [TypeOrmModule.forFeature([Assignment])],
imports: [TypeOrmModule.forFeature([Assignment, Lecture, Semester, Year, User])],
providers: [AssignmentService],
controllers: [AssignmentController]
})
Expand Down
116 changes: 115 additions & 1 deletion src/assignment/assignment.service.ts
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} 강의가 없습니다.`,
);
}
}
}

}
20 changes: 20 additions & 0 deletions src/assignment/dto/create-assignment.dto.ts
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;


}
35 changes: 26 additions & 9 deletions src/assignment/entity/assignment.entity.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { Lecture } from 'src/lecture/entity/lecture.entity';
import {
Entity,
Column,
PrimaryGeneratedColumn,
JoinColumn,
OneToOne,
ManyToMany,
ManyToOne,
JoinTable,
} from 'typeorm';
import {Record} from "../../record/entity/record.entity";
import { Lecture } from 'src/lecture/entity/lecture.entity';
import { Semester } from 'src/semester/entity/semester.entity';
import { User } from 'src/user/entity/user.entity';
import { Year } from 'src/year/entity/year.entity';

@Entity()
export class Assignment {
Expand All @@ -23,11 +28,23 @@ export class Assignment {
project: boolean;

@Column()
others: boolean;



@OneToOne(() => Record, (record ) => record.assignment)
@JoinColumn()
record : Record;
other: boolean;

@ManyToOne((Type) => Lecture, (lecture) => lecture.lecture_name, {
cascade: true,
eager: true,
})
lecture: Lecture;

@ManyToOne((Type) => Semester, { cascade: true })
@JoinTable()
semesters: Semester;

@ManyToOne((Type) => Year, { cascade: true })
@JoinTable()
years: Year;

@ManyToOne((Type) => User, { cascade: true })
@JoinTable()
user: User;
}
5 changes: 0 additions & 5 deletions src/record/entity/record.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import {
ManyToOne,
JoinTable, OneToOne,
} from 'typeorm';
import {Scoring} from "../../scoring/entity/scoring.entity";
import {Assignment} from "../../assignment/entity/assignment.entity";

@Entity()
export class Record {
Expand Down Expand Up @@ -62,7 +60,4 @@ export class Record {
@ManyToOne((Type) => User, { cascade: true })
@JoinTable()
user: User;

@OneToOne(() => Assignment, (assignment) => assignment.record)
assignment : Assignment;
}

0 comments on commit 72a1410

Please sign in to comment.