| | 1 | | namespace Syki.Back.Features.Student.GetStudentClassActivities; |
| | 2 | |
|
| 4 | 3 | | public class GetStudentClassActivitiesService(SykiDbContext ctx) : IStudentService |
| | 4 | | { |
| | 5 | | public async Task<OneOf<List<StudentClassActivityOut>, SykiError>> Get(Guid userId, Guid classId) |
| | 6 | | { |
| 4 | 7 | | var classOk = await ctx.ClassesStudents.AnyAsync(x => x.ClassId == classId && x.SykiStudentId == userId); |
| 6 | 8 | | if (!classOk) return new ClassNotFound(); |
| | 9 | |
|
| 2 | 10 | | var activities = await ctx.ClassActivities.AsNoTracking() |
| 2 | 11 | | .Where(x => x.ClassId == classId) |
| 2 | 12 | | .OrderBy(x => x.Note) |
| 2 | 13 | | .ThenBy(x => x.CreatedAt) |
| 2 | 14 | | .ToListAsync(); |
| 8 | 15 | | var ids = activities.ConvertAll(x => x.Id); |
| 2 | 16 | | var works = await ctx.ClassActivityWorks.AsNoTracking() |
| 2 | 17 | | .Where(x => ids.Contains(x.ClassActivityId) && x.SykiStudentId == userId).ToListAsync(); |
| | 18 | |
|
| 2 | 19 | | var result = new List<StudentClassActivityOut>(); |
| 16 | 20 | | foreach (var activity in activities) |
| | 21 | | { |
| 18 | 22 | | var work = works.First(x => x.ClassActivityId == activity.Id); |
| 6 | 23 | | result.Add(new() |
| 6 | 24 | | { |
| 6 | 25 | | Id = activity.Id, |
| 6 | 26 | | ClassId = activity.ClassId, |
| 6 | 27 | | Note = activity.Note, |
| 6 | 28 | | Title = activity.Title, |
| 6 | 29 | | Description = activity.Description, |
| 6 | 30 | | Type = activity.Type, |
| 6 | 31 | | Status = activity.Status, |
| 6 | 32 | | Weight = activity.Weight, |
| 6 | 33 | | WorkStatus = work.Status, |
| 6 | 34 | | CreatedAt = activity.CreatedAt, |
| 6 | 35 | | DueDate = activity.DueDate, |
| 6 | 36 | | DueHour = activity.DueHour, |
| 6 | 37 | | Value = work.Note, |
| 6 | 38 | | PonderedValue = work.Note * activity.Weight / 100M, |
| 6 | 39 | | }); |
| | 40 | | } |
| | 41 | |
|
| 2 | 42 | | return result; |
| 4 | 43 | | } |
| | 44 | | } |