< Summary

Information
Class: Syki.Back.Features.Teacher.CreateLessonAttendance.CreateLessonAttendanceService
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Features/Teacher/CreateLessonAttendance/CreateLessonAttendanceService.cs
Tag: 22_11348620282
Line coverage
95%
Covered lines: 22
Uncovered lines: 1
Coverable lines: 23
Total lines: 43
Line coverage: 95.6%
Branch coverage
91%
Covered branches: 11
Total branches: 12
Branch coverage: 91.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Create()91.66%12.021295%

File(s)

/home/runner/work/syki/syki/Back/Features/Teacher/CreateLessonAttendance/CreateLessonAttendanceService.cs

#LineLine coverage
 1namespace Syki.Back.Features.Teacher.CreateLessonAttendance;
 2
 3423public class CreateLessonAttendanceService(SykiDbContext ctx) : ITeacherService
 4{
 5    public async Task<OneOf<SykiSuccess, SykiError>> Create(Guid teacherId, Guid lessonId, CreateLessonAttendanceIn data
 6    {
 767        var lesson = await ctx.Lessons.Include(l => l.Attendances).FirstOrDefaultAsync(x => x.Id == lessonId);
 778        if (lesson == null) return new LessonNotFound();
 9
 7610        if (lesson.Date > DateTime.Now.ToDateOnly()) return new InvalidLesson();
 11
 7412        var @class = await ctx.Classes
 7413            .Include(x => x.Students)
 7414            .FirstOrDefaultAsync(x => x.Id == lesson.ClassId && x.TeacherId == teacherId);
 7515        if (@class == null) return new LessonNotFound();
 16
 14417        var allStudents = @class.Students.Select(x => x.Id).ToList();
 7318        if (!data.PresentStudents.IsSubsetOf(allStudents))
 119            return new InvalidStudentsList();
 20
 7221        var attendances = lesson.Attendances;
 28622        foreach (var studentId in allStudents)
 23        {
 7124            var present = data.PresentStudents.Contains(studentId);
 7125            var attendance = attendances.FirstOrDefault(a => a.StudentId == studentId);
 7126            if (attendance != null)
 27            {
 028                attendance.Update(present);
 29            }
 30            else
 31            {
 7132                attendance = new LessonAttendance(@class.Id, lesson.Id, studentId, present);
 7133                ctx.Add(attendance);
 34            }
 35        }
 36
 7237        lesson.Finish();
 38
 7239        await ctx.SaveChangesAsync();
 40
 7241        return new SykiSuccess();
 7642    }
 43}