-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathAggregationController.cs
More file actions
42 lines (35 loc) · 1.34 KB
/
AggregationController.cs
File metadata and controls
42 lines (35 loc) · 1.34 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 getMentorsTasks = courses.Select(t => AuthServiceClient.GetAccountsData(t.MentorIds)).ToList();
await Task.WhenAll(getMentorsTasks);
var mentorDTOs = getMentorsTasks.Select(t => t.Result);
var result = courses.Zip(mentorDTOs, (course, mentors) =>
new CoursePreviewView
{
Id = course.Id,
Name = course.Name,
GroupName = course.GroupName,
IsCompleted = course.IsCompleted,
Mentors = mentors.Where(t => t != null).ToArray()
}).ToArray();
return result;
}
}