-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathAggregationController.cs
More file actions
42 lines (37 loc) · 1.44 KB
/
AggregationController.cs
File metadata and controls
42 lines (37 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System.Linq;
using System.Threading.Tasks;
using HwProj.APIGateway.API.Models;
using HwProj.AuthService.Client;
using HwProj.Models.CoursesService.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace HwProj.APIGateway.API.Controllers;
public class AggregationController : ControllerBase
{
protected readonly IAuthServiceClient AuthServiceClient;
protected AggregationController(IAuthServiceClient authServiceClient)
{
AuthServiceClient = authServiceClient;
}
protected string? UserId =>
Request.HttpContext.User.Claims
.FirstOrDefault(claim => claim.Type.ToString() == "_id")
?.Value;
protected async Task<CoursePreviewView[]> GetCoursePreviews(CoursePreview[] courses)
{
var mentorIds = courses.SelectMany(t => t.MentorIds).Distinct().ToArray();
var mentors = await AuthServiceClient.GetAccountsData(mentorIds);
var mentorsDict = mentors.Where(x => x != null).ToDictionary(x => x.UserId);
return courses.Select(course => new CoursePreviewView
{
Id = course.Id,
Name = course.Name,
GroupName = course.GroupName,
IsCompleted = course.IsCompleted,
Mentors = course.MentorIds
.Select(x => mentorsDict.TryGetValue(x, out var mentor) ? mentor : null)
.Where(x => x != null)
.ToArray()!,
TaskId = course.TaskId
}).ToArray();
}
}