Skip to content

Commit

Permalink
Merge pull request #45 from DevKor-github/feature/timetable
Browse files Browse the repository at this point in the history
Feature/timetable
  • Loading branch information
Devheun authored Jul 19, 2024
2 parents e449789 + 3525752 commit 869120a
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 260 deletions.
4 changes: 1 addition & 3 deletions src/schedule/schedule.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { ScheduleService } from './schedule.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ScheduleEntity } from 'src/entities/schedule.entity';
import { AuthModule } from 'src/auth/auth.module';
import { ScheduleRepository } from './schedule.repository';
import { TimetableModule } from 'src/timetable/timetable.module';
import { TimetableCourseRepository } from 'src/timetable/timetable-course.repository';

@Module({
imports: [
Expand All @@ -15,7 +13,7 @@ import { TimetableCourseRepository } from 'src/timetable/timetable-course.reposi
forwardRef(() => TimetableModule),
],
controllers: [ScheduleController],
providers: [ScheduleService, ScheduleRepository, TimetableCourseRepository],
providers: [ScheduleService],
exports: [ScheduleService],
})
export class ScheduleModule {}
10 changes: 0 additions & 10 deletions src/schedule/schedule.repository.ts

This file was deleted.

37 changes: 23 additions & 14 deletions src/schedule/schedule.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
BadRequestException,
ConflictException,
Inject,
Injectable,
Expand All @@ -8,17 +9,18 @@ import {
import { ScheduleEntity } from 'src/entities/schedule.entity';
import { CreateScheduleRequestDto } from './dto/create-schedule-request.dto';
import { AuthorizedUserDto } from 'src/auth/dto/authorized-user-dto';
import { ScheduleRepository } from './schedule.repository';
import { TimetableService } from 'src/timetable/timetable.service';
import { DeleteScheduleResponseDto } from './dto/delete-schedule-response.dto';
import { UpdateScheduleRequestDto } from './dto/update-schedule-request.dto';
import { UpdateScheduleResponseDto } from './dto/update-schedule-response.dto';
import { DataSource } from 'typeorm';
import { DataSource, Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';

@Injectable()
export class ScheduleService {
constructor(
private readonly scheduleRepository: ScheduleRepository,
@InjectRepository(ScheduleEntity)
private readonly scheduleRepository: Repository<ScheduleEntity>,
@Inject(forwardRef(() => TimetableService))
private readonly timetableService: TimetableService,
private readonly dataSource: DataSource,
Expand Down Expand Up @@ -49,6 +51,14 @@ export class ScheduleService {
throw new NotFoundException('Timetable not found');
}

if (
createScheduleRequestDto.startTime >= createScheduleRequestDto.endTime
) {
throw new BadRequestException(
'Start time must be earlier than end time',
);
}

// 시간표에 존재하는 강의, 스케쥴과 추가하려는 스케쥴이 시간이 겹치는 지 확인
const isConflict = await this.checkTimeConflict(createScheduleRequestDto);

Expand Down Expand Up @@ -101,6 +111,13 @@ export class ScheduleService {
updateScheduleRequestDto.startTime &&
updateScheduleRequestDto.endTime
) {
if (
updateScheduleRequestDto.startTime >= updateScheduleRequestDto.endTime
) {
throw new BadRequestException(
'Start time must be earlier than end time',
);
}
// 시간표에 존재하는 강의, 스케쥴과 수정하려는 스케쥴이 시간이 겹치는 지 확인
const isConflict = await this.checkTimeConflict(
updateScheduleRequestDto,
Expand Down Expand Up @@ -184,17 +201,9 @@ export class ScheduleService {
);

for (const existingInfo of existingScheduleInfo) {
// 변경하고자 하는 일정이 기존의 일정 시간대 내에서 변경하는 경우 (ex : 토요일 10:30~12:00 -> 토요일 11:00 ~ 12:00)
if (
scheduleId === Number(existingInfo.id) &&
String(schedule.day) === existingInfo.day &&
this.timeToNumber(schedule.startTime) >=
this.timeToNumber(existingInfo.startTime) &&
this.timeToNumber(schedule.endTime) <=
this.timeToNumber(existingInfo.endTime)
) {
return false;
}
// 예외 발생 케이스 처리
if (scheduleId === Number(existingInfo.id)) continue;

if (
existingInfo.day === schedule.day &&
this.isConflictingTime(
Expand Down
26 changes: 3 additions & 23 deletions src/timetable/dto/get-courseinfo-timetable.dto.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import { ApiProperty } from '@nestjs/swagger';
import {
IsEnum,
IsNotEmpty,
IsNumber,
IsOptional,
IsString,
} from 'class-validator';

const DayType = {
Mon: 'Mon',
Expand All @@ -21,42 +14,29 @@ export type DayType = (typeof DayType)[keyof typeof DayType];

export class GetCourseInfoByTimetableIdResponseDto {
@ApiProperty({ description: '강의 ID' })
@IsNumber()
@IsNotEmpty()
courseId: number;

@ApiProperty({ description: '교수님 성함' })
@IsString()
@IsNotEmpty()
professorName: string;

@ApiProperty({ description: '강의명' })
@IsString()
@IsNotEmpty()
courseName: string;

@ApiProperty({ description: '학수 번호' })
@IsString()
@IsNotEmpty()
courseCode: string;

@ApiProperty({ description: '강의 계획서' })
syllabus: string;

@ApiProperty({ description: '시작 시간' })
@IsString()
@IsOptional()
startTime: string;

@ApiProperty({ description: '종료 시간' })
@IsString()
@IsOptional()
endTime: string;

@ApiProperty({ description: '강의실' })
@IsString()
@IsOptional()
classroom: string;

@ApiProperty({ description: '요일' })
@IsEnum(DayType)
@IsOptional()
day: DayType;
}
10 changes: 0 additions & 10 deletions src/timetable/timetable-course.repository.ts

This file was deleted.

7 changes: 3 additions & 4 deletions src/timetable/timetable.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@ import { TimetableController } from './timetable.controller';
import { TimetableService } from './timetable.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { TimetableEntity } from 'src/entities/timetable.entity';
import { TimetableRepository } from './timetable.repository';
import { TimetableCourseRepository } from './timetable-course.repository';
import { AuthModule } from 'src/auth/auth.module';
import { ScheduleModule } from 'src/schedule/schedule.module';
import { CourseModule } from 'src/course/course.module';
import { TimetableCourseEntity } from 'src/entities/timetable-course.entity';

@Module({
imports: [
TypeOrmModule.forFeature([TimetableEntity]),
TypeOrmModule.forFeature([TimetableEntity, TimetableCourseEntity]),
AuthModule,
CourseModule,
forwardRef(() => ScheduleModule),
],
controllers: [TimetableController],
providers: [TimetableService, TimetableRepository, TimetableCourseRepository],
providers: [TimetableService],
exports: [TimetableService],
})
export class TimetableModule {}
10 changes: 0 additions & 10 deletions src/timetable/timetable.repository.ts

This file was deleted.

Loading

0 comments on commit 869120a

Please sign in to comment.