| | 1 | | namespace Syki.Back.Features.Academic.GetClassroomAgenda; |
| | 2 | |
|
| 0 | 3 | | public class GetClassroomAgendaService(SykiDbContext ctx) : ITeacherService |
| | 4 | | { |
| | 5 | | public async Task<OneOf<List<AgendaDayOut>, SykiError>> Get(Guid institution, Guid classroomId) |
| | 6 | | { |
| 0 | 7 | | var classroom = await ctx.Classrooms.AsNoTracking().FirstOrDefaultAsync(x => x.InstitutionId == institution && x |
| 0 | 8 | | if (classroom == null) return new ClassroomNotFound(); |
| | 9 | |
|
| 0 | 10 | | var ids = await ctx.ClassroomsClasses.Where(c => c.ClassroomId == classroomId && c.IsActive).Select(x => x.Class |
| 0 | 11 | | var classes = await ctx.Classes.AsNoTracking() |
| 0 | 12 | | .Include(t => t.Discipline) |
| 0 | 13 | | .Include(t => t.Schedules) |
| 0 | 14 | | .Where(t => t.InstitutionId == institution && ids.Contains(t.Id)) |
| 0 | 15 | | .ToListAsync(); |
| | 16 | |
|
| 0 | 17 | | var response = classes.ConvertAll(t => |
| 0 | 18 | | { |
| 0 | 19 | | return new EnrollmentClassOut |
| 0 | 20 | | { |
| 0 | 21 | | Id = t.Id, |
| 0 | 22 | | Discipline = t.Discipline.Name, |
| 0 | 23 | | Schedules = t.Schedules.ConvertAll(h => h.ToOut()), |
| 0 | 24 | | }; |
| 0 | 25 | | }); |
| | 26 | |
|
| 0 | 27 | | var agenda = response.ToAgendas(); |
| 0 | 28 | | var result = new List<AgendaDayOut>(); |
| | 29 | |
|
| 0 | 30 | | foreach (var day in Enum.GetValues<Day>()) |
| | 31 | | { |
| 0 | 32 | | if (day == Day.Saturday) continue; |
| 0 | 33 | | var item = agenda.FirstOrDefault(x => x.Day == day) ?? new AgendaDayOut() { Day = day }; |
| 0 | 34 | | result.Add(item); |
| | 35 | | } |
| | 36 | |
|
| 0 | 37 | | return result; |
| 0 | 38 | | } |
| | 39 | | } |