Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Optimises Project/GetProject #793

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions src/BL/Models/SubmissionGetProjectModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using BL.Models.Enums;
using BL.Models.Helpers;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -27,13 +28,17 @@ public class SubmissionGetProjectModel

public virtual List<TreGetProjectModel> Tres { get; set; }

public virtual List<UserGetProjectModel> UsersNotInProject { get; set; }

public virtual List<TreGetProjectModel> TresNotInProject { get; set; }

public virtual List<SubmissionsGetProjectModel> Submissions { get; set; }
public SubmissionGetProjectModel()
{

}

public SubmissionGetProjectModel(Project Project)
public SubmissionGetProjectModel(Project Project, DbSet<User> UsersAll, DbSet<BL.Models.Tre> TREsALL)
{
Id = Project.Id;
FormData = Project.FormData;
Expand All @@ -46,17 +51,38 @@ public SubmissionGetProjectModel(Project Project)
SubmissionBucket = Project.SubmissionBucket;
OutputBucket = Project.OutputBucket;
Users = new List<UserGetProjectModel>();
foreach (var item in Project.Users)
UsersNotInProject = new List<UserGetProjectModel>();


foreach (var user in UsersAll.ToArray())
{
Users.Add(new UserGetProjectModel(item));
if (Project.Users.Contains(user))
{
Users.Add(new UserGetProjectModel(user));
}
else
{
UsersNotInProject.Add(new UserGetProjectModel(user));
}
}


Tres = new List<TreGetProjectModel>();
foreach (var item in Project.Tres)
TresNotInProject = new List<TreGetProjectModel>();


foreach (var tre in TREsALL.ToArray())
{
Tres.Add(new TreGetProjectModel(item, Id));
if (Project.Tres.Contains(tre))
{
Tres.Add(new TreGetProjectModel(tre, Id));
}
else
{
TresNotInProject.Add(new TreGetProjectModel(tre, Id));
}
}

Submissions = new List<SubmissionsGetProjectModel>();
foreach (var item in Project.Submissions)
{
Expand Down
4 changes: 3 additions & 1 deletion src/DARE-API/Controllers/ProjectController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,9 @@ public ProjectController(ApplicationDbContext applicationDbContext, MinioSetting
}

Log.Information("{Function} Project retrieved successfully", "GetProject");
return new SubmissionGetProjectModel(returned);
var Users = _DbContext.Users.ToList();
_DbContext.Tres.ToList();
return new SubmissionGetProjectModel(returned, _DbContext.Users, _DbContext.Tres);
}
catch (Exception ex)
{
Expand Down
8 changes: 3 additions & 5 deletions src/DARE-FrontEnd/Controllers/ProjectController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,9 @@ public async Task<IActionResult> GetProject(int id)
//Log.Error("minioEndpoint took ElapsedMilliseconds" + stopwatch.ElapsedMilliseconds);
stopwatch.Stop();
var project = projectawait.Result;
var users = _clientHelper.CallAPIWithoutModel<List<BL.Models.User>>("/api/User/GetAllUsers/").Result;
var tres = _clientHelper.CallAPIWithoutModel<List<Tre>>("/api/Tre/GetAllTres/").Result;

var userItems2 = users.Where(p => !project.Users.Select(x => x.Id).Contains(p.Id)).ToList();
var treItems2 = tres.Where(p => !project.Tres.Select(x => x.Id).Contains(p.Id)).ToList();

var userItems2 = project.UsersNotInProject;
var treItems2 = project.TresNotInProject;

var userItems = userItems2
.Select(p => new SelectListItem { Value = p.Id.ToString(), Text = p.FullName != "" ? p.FullName : p.Name })
Expand Down
Loading