Skip to content

Commit 43fedf2

Browse files
committed
refactor
1 parent f13bceb commit 43fedf2

File tree

2 files changed

+6
-61
lines changed

2 files changed

+6
-61
lines changed

HwProj.APIGateway/HwProj.APIGateway.API/Controllers/SolutionsController.cs

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using HwProj.Models.CoursesService.ViewModels;
1212
using HwProj.Models.Roles;
1313
using HwProj.Models.SolutionsService;
14-
using HwProj.Models.StatisticsService;
1514
using HwProj.SolutionsService.Client;
1615
using Microsoft.AspNetCore.Authorization;
1716
using Microsoft.AspNetCore.Mvc;
@@ -136,47 +135,6 @@ public async Task<IActionResult> GetTaskSolutionsPageData(long taskId)
136135
return Ok(result);
137136
}
138137

139-
[Authorize]
140-
[HttpGet("tasks/{taskId}")]
141-
[ProducesResponseType(typeof(TaskSolutionStatisticsPageData), (int)HttpStatusCode.OK)]
142-
public async Task<IActionResult> GetTaskSolutionsPageData(long taskId)
143-
{
144-
var course = await _coursesServiceClient.GetCourseByTask(taskId);
145-
//TODO: CourseMentorOnlyAttribute
146-
if (course == null || !course.MentorIds.Contains(UserId)) return Forbid();
147-
148-
var studentIds = course.CourseMates
149-
.Where(t => t.IsAccepted)
150-
.Select(t => t.StudentId)
151-
.ToArray();
152-
153-
var getStudentsDataTask = AuthServiceClient.GetAccountsData(studentIds);
154-
var getStatisticsTask = _solutionsClient.GetTaskSolutionStatistics(taskId);
155-
156-
await Task.WhenAll(getStudentsDataTask, getStatisticsTask);
157-
158-
var usersData = getStudentsDataTask.Result;
159-
var statistics = getStatisticsTask.Result;
160-
var statisticsDict = statistics.ToDictionary(t => t.StudentId);
161-
162-
var result = new TaskSolutionStatisticsPageData()
163-
{
164-
CourseId = course.Id,
165-
StudentsSolutions = studentIds.Zip(usersData, (studentId, accountData) => new UserTaskSolutions
166-
{
167-
Solutions = statisticsDict.TryGetValue(studentId, out var studentSolutions)
168-
? studentSolutions.Solutions
169-
: Array.Empty<Solution>(),
170-
User = accountData
171-
})
172-
.OrderBy(t => t.User.Surname)
173-
.ThenBy(t => t.User.Name)
174-
.ToArray()
175-
};
176-
177-
return Ok(result);
178-
}
179-
180138
[HttpPost("{taskId}")]
181139
[Authorize(Roles = Roles.StudentRole)]
182140
[ProducesResponseType(typeof(long), (int)HttpStatusCode.OK)]
@@ -233,19 +191,6 @@ public async Task<IActionResult> PostEmptySolutionWithRate(long taskId, Solution
233191
return Ok();
234192
}
235193

236-
[HttpPost("rateEmptySolution/{taskId}")]
237-
[Authorize(Roles = Roles.LecturerRole)]
238-
public async Task<IActionResult> PostEmptySolutionWithRate(long taskId, SolutionViewModel model)
239-
{
240-
var course = await _coursesServiceClient.GetCourseByTask(taskId);
241-
if (course == null || !course.MentorIds.Contains(UserId)) return Forbid();
242-
if (course.CourseMates.All(t => t.StudentId != model.StudentId))
243-
return BadRequest($"Студента с id {model.StudentId} не существует");
244-
245-
await _solutionsClient.PostEmptySolutionWithRate(taskId, model);
246-
return Ok();
247-
}
248-
249194
[HttpPost("rateSolution/{solutionId}/{newRating}")]
250195
[Authorize(Roles = Roles.LecturerRole)]
251196
public async Task<IActionResult> RateSolution(long solutionId, int newRating,
@@ -329,4 +274,4 @@ public async Task<UnratedSolutionPreviews> GetUnratedSolutions(long? taskId)
329274
}
330275
}
331276
}
332-
}
277+
}

HwProj.SolutionsService/HwProj.SolutionsService.IntegrationTests/SolutionsStatsDomainTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ private List<Solution> GenerateTestSolutionsForTask(int amount, long taskId) =>
5858
})
5959
.ToList();
6060

61-
private GroupViewModel GenerateGroupViewModel(long id, string[] studentIds) => new()
61+
private GroupViewModel GenerateGroupViewModel(long id, string[] studentIds) => new GroupViewModel
6262
{
6363
Id = id,
6464
StudentsIds = studentIds
6565
};
6666

67-
private HomeworkViewModel GenerateHomeworkViewModel(long id, long courseId, int taskAmount) => new()
67+
private HomeworkViewModel GenerateHomeworkViewModel(long id, long courseId, int taskAmount) => new HomeworkViewModel
6868
{
6969
Id = id,
7070
Title = "Test",
@@ -82,7 +82,7 @@ private List<Solution> MakeTestSolutions(CourseMateViewModel[] courseMates, Grou
8282
solutions[2].StudentId = courseMates[1].StudentId;
8383
solutions[0].GroupId = groups[0].Id;
8484
solutions[1].GroupId = groups[1].Id;
85-
85+
8686
return solutions;
8787
}
8888

@@ -127,15 +127,15 @@ public async Task GetCourseStatisticsTest()
127127
thirdStudentSolutions.Should().HaveCount(1);
128128
thirdStudentSolutions[0].Id.Should().Be(1);
129129
}
130-
130+
131131
[Test]
132132
public async Task GetCourseTaskStatisticsTest()
133133
{
134134
var courseMates = GenerateCourseMatesViewModels(3).ToArray();
135135
var group1 = GenerateGroupViewModel(1, new[] { courseMates[0].StudentId, courseMates[1].StudentId });
136136
var group2 = GenerateGroupViewModel(2, new[] { courseMates[1].StudentId, courseMates[2].StudentId });
137137
var groups = new[] { group1, group2 };
138-
138+
139139
var solutions = GenerateTestSolutionsForTask(3, 1);
140140
solutions[0].StudentId = courseMates[0].StudentId;
141141
solutions[0].GroupId = group1.Id;

0 commit comments

Comments
 (0)