Skip to content

Commit 5c0188b

Browse files
committed
refactor: create courseUnitType constans
1 parent bef638b commit 5c0188b

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

HwProj.APIGateway/HwProj.APIGateway.API/Filters/FilesCountLimit.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Threading.Tasks;
33
using HwProj.ContentService.Client;
44
using HwProj.Models.ContentService.DTO;
5-
using HwProj.Models.Result;
5+
using HwProj.Models.CourseUnitType;
66

77
namespace HwProj.APIGateway.API.Filters;
88

@@ -18,10 +18,10 @@ public FilesCountLimit(IContentServiceClient contentServiceClient)
1818

1919
public async Task<bool> CheckCountLimit(ProcessFilesDTO processFilesDto)
2020
{
21-
if(processFilesDto.FilesScope.CourseUnitType == "Homework") return true;
21+
if (processFilesDto.FilesScope.CourseUnitType == CourseUnitType.Homework) return true;
2222

2323
var existingStatuses = await _contentServiceClient.GetFilesStatuses(processFilesDto.FilesScope);
24-
if(!existingStatuses.Succeeded) return false;
24+
if (!existingStatuses.Succeeded) return false;
2525

2626
var existingIds = existingStatuses.Value.Select(f => f.Id);
2727
if (processFilesDto.DeletingFileIds.Any(id => !existingIds.Contains(id)))

HwProj.APIGateway/HwProj.APIGateway.API/Filters/FilesPrivacyFilter.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Threading.Tasks;
44
using HwProj.CoursesService.Client;
55
using HwProj.Models.ContentService.DTO;
6+
using HwProj.Models.CourseUnitType;
67
using HwProj.SolutionsService.Client;
78

89
namespace HwProj.APIGateway.API.Filters;
@@ -20,10 +21,10 @@ public FilesPrivacyFilter(ICoursesServiceClient coursesServiceClient, ISolutions
2021

2122
public async Task<bool> CheckDownloadRights(string? userId, ScopeDTO fileScope)
2223
{
23-
if (fileScope.CourseUnitType == "Homework") return true;
24-
if (fileScope.CourseUnitType == "Solution")
24+
if (fileScope.CourseUnitType == CourseUnitType.Homework) return true;
25+
if (fileScope.CourseUnitType == CourseUnitType.Solution)
2526
{
26-
if(userId == null) return false;
27+
if (userId == null) return false;
2728
var studentIds = new HashSet<string>();
2829
var solution = await _solutionsServiceClient.GetSolutionById(fileScope.CourseUnitId);
2930
studentIds.Add(solution.StudentId);
@@ -40,17 +41,17 @@ public async Task<bool> CheckDownloadRights(string? userId, ScopeDTO fileScope)
4041

4142
return false;
4243
}
43-
44+
4445
public async Task<bool> CheckUploadRights(string? userId, ScopeDTO fileScope)
4546
{
46-
if(userId == null) return false;
47-
if (fileScope.CourseUnitType == "Homework")
47+
if (userId == null) return false;
48+
if (fileScope.CourseUnitType == CourseUnitType.Homework)
4849
{
4950
var mentorIds = await _coursesServiceClient.GetCourseLecturersIds(fileScope.CourseId);
5051
if (!mentorIds.Contains(userId)) return false;
5152
return true;
52-
}
53-
if (fileScope.CourseUnitType == "Solution")
53+
}
54+
if (fileScope.CourseUnitType == CourseUnitType.Solution)
5455
{
5556
var studentIds = new HashSet<string>();
5657
var solution = await _solutionsServiceClient.GetSolutionById(fileScope.CourseUnitId);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace HwProj.Models.CourseUnitType
2+
{
3+
public static class CourseUnitType
4+
{
5+
public const string Homework = "Homework";
6+
public const string Solution = "Solution";
7+
public const string Task = "Task";
8+
};
9+
};

0 commit comments

Comments
 (0)