Skip to content

Commit

Permalink
Merge pull request #26 from B3-3iL-DLW/refactor/refactor-data-layer-api
Browse files Browse the repository at this point in the history
Refactor/refactor data layer api
  • Loading branch information
Yuta1409 authored Mar 13, 2024
2 parents b4fd334 + 6dc0913 commit 48be23c
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ class DayScheduleModel {
int get jour => entity.jour;

List<EventEntity> get events => entity.events;

factory DayScheduleModel.fromEntity(DayScheduleEntity entity) {
return DayScheduleModel(
entity: entity,
);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import 'package:app_student/api/day_schedule/entities/day_schedule_entity.dart';

import 'package:app_student/api/day_schedule/models/day_schedule_model.dart';
import '../entities/week_schedule_entity.dart';

class WeekScheduleModel {
final WeekScheduleEntity weekSchedule;
final String code;
final List<DayScheduleModel> daySchedules;

WeekScheduleModel({
required this.weekSchedule,
required this.code,
required this.daySchedules,
});

String get code => weekSchedule.code;
List<DayScheduleEntity> get daySchedules => weekSchedule.daySchedules;
factory WeekScheduleModel.fromEntity(WeekScheduleEntity entity) {
return WeekScheduleModel(
code: entity.code,
daySchedules: entity.daySchedules
.map((dayScheduleEntity) =>
DayScheduleModel.fromEntity(dayScheduleEntity))
.toList(),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class WeekScheduleRepository {
Future<List<WeekScheduleModel>> getWeeksSchedule(className) {
return apiService.getData('/api/timetable?class_param=$className', (item) {
final entity = WeekScheduleEntity.fromJson(item);
return WeekScheduleModel(weekSchedule: entity);
return WeekScheduleModel.fromEntity(entity);
});
}
}
2 changes: 1 addition & 1 deletion frontend/app_student/lib/main_dev.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:app_student/api/week_schedule/repositories/week_schedule_repositories.dart';
import 'package:app_student/api/week_schedule/repositories/week_schedule_repository.dart';
import 'package:app_student/config/dev_config.dart';
import 'package:app_student/week_schedule/views/week_schedule.dart';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:app_student/api/week_schedule/repositories/week_schedule_repositories.dart';
import 'package:app_student/api/week_schedule/repositories/week_schedule_repository.dart';
import 'package:bloc/bloc.dart';
import 'package:meta/meta.dart';

Expand Down
41 changes: 2 additions & 39 deletions frontend/app_student/lib/week_schedule/views/week_schedule.dart
Original file line number Diff line number Diff line change
@@ -1,46 +1,9 @@
import 'package:app_student/api/day_schedule/entities/day_schedule_entity.dart';
import 'package:app_student/api/week_schedule/models/week_schedule_model.dart';
import 'package:app_student/api/week_schedule/repositories/week_schedule_repositories.dart';
import 'package:app_student/api/week_schedule/repositories/week_schedule_repository.dart';
import 'package:app_student/week_schedule/cubit/week_schedule_cubit.dart';
import 'package:app_student/week_schedule/views/widgets/week_schedule_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

class DayScheduleWidget extends StatelessWidget {
final DayScheduleEntity daySchedule;

const DayScheduleWidget({super.key, required this.daySchedule});

@override
Widget build(BuildContext context) {
return ExpansionTile(
title: Text('Date: ${daySchedule.date}'),
children: daySchedule.events.map((event) {
return ListTile(
title: Text('Event: ${event.activite}'),
subtitle: Text(
'Start at: ${event.horaires.startAt}, End Time: ${event.horaires.endAt}'),
);
}).toList(),
);
}
}

class WeekScheduleWidget extends StatelessWidget {
final WeekScheduleModel weekSchedule;

const WeekScheduleWidget({super.key, required this.weekSchedule});

@override
Widget build(BuildContext context) {
return ExpansionTile(
title: Text('Code: ${weekSchedule.code}'),
children: weekSchedule.daySchedules.map((daySchedule) {
return DayScheduleWidget(daySchedule: daySchedule);
}).toList(),
);
}
}

class WeekSchedulePage extends StatelessWidget {
const WeekSchedulePage({super.key});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:app_student/api/day_schedule/models/day_schedule_model.dart';
import 'package:flutter/material.dart';

class DayScheduleWidget extends StatelessWidget {
final DayScheduleModel daySchedule;

const DayScheduleWidget({super.key, required this.daySchedule});

@override
Widget build(BuildContext context) {
return ExpansionTile(
title: Text('Date: ${daySchedule.date}'),
children: daySchedule.events.map((event) {
return ListTile(
title: Text('Event: ${event.activite}'),
subtitle: Text(
'Start at: ${event.horaires.startAt}, End Time: ${event.horaires.endAt}'),
);
}).toList(),
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:app_student/api/week_schedule/models/week_schedule_model.dart';
import 'package:app_student/week_schedule/views/widgets/day_schedule_widget.dart';
import 'package:flutter/material.dart';

class WeekScheduleWidget extends StatelessWidget {
final WeekScheduleModel weekSchedule;

const WeekScheduleWidget({super.key, required this.weekSchedule});

@override
Widget build(BuildContext context) {
return ExpansionTile(
title: Text('Code: ${weekSchedule.code}'),
children: weekSchedule.daySchedules.map((daySchedule) {
return DayScheduleWidget(daySchedule: daySchedule);
}).toList(),
);
}
}

0 comments on commit 48be23c

Please sign in to comment.