Skip to content

Commit

Permalink
refactor: merge EnrollUtil into EnrollType
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzocorallo committed Jul 5, 2024
1 parent 8da77db commit ab1033f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 41 deletions.
26 changes: 24 additions & 2 deletions PoliNetwork.Graduatorie.Common/Objects/EnrollType.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#region

using System.Security.Cryptography;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

Expand All @@ -11,7 +12,7 @@ namespace PoliNetwork.Graduatorie.Common.Objects;
[JsonObject(MemberSerialization.Fields, NamingStrategyType = typeof(CamelCaseNamingStrategy))]
public class EnrollType
{
public bool? CanEnroll;
public bool CanEnroll;
public string? Course;
public string? Type;

Expand All @@ -20,8 +21,29 @@ public int GetHashWithoutLastUpdate()
var i = "EnrollTypeNotNull".GetHashCode();
i ^= Course?.GetHashCode() ?? "Course".GetHashCode();
i ^= Type?.GetHashCode() ?? "Type".GetHashCode();
i ^= CanEnroll?.GetHashCode() ?? "CanEnroll".GetHashCode();

return i;
}

public static EnrollType From(string? rowCanEnrollInto, bool rowCanEnroll)
{
if (rowCanEnroll == false)
return new EnrollType { CanEnroll = false, Course = null, Type = null };

if (string.IsNullOrEmpty(rowCanEnrollInto))
return new EnrollType { CanEnroll = true, Course = null, Type = null };

string[] tester = { "assegnato", "prenotato" };
const string sep = " - ";
if (!rowCanEnrollInto.Contains(sep) || !tester.Any(t => rowCanEnrollInto.ToLower().Contains(t)))
return new EnrollType { CanEnroll = true, Course = rowCanEnrollInto, Type = null };

var s = rowCanEnrollInto.Split(sep).ToList();
var type = s.FirstOrDefault(x => tester.Any(t => t == x.ToLower()));

if (type != null) s.Remove(type);

var course = string.Join(sep, s);
return new EnrollType { CanEnroll = true, Course = course, Type = type };
}
}
32 changes: 0 additions & 32 deletions PoliNetwork.Graduatorie.Common/Utils/EnrollUtil.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#region

using PoliNetwork.Graduatorie.Common.Utils;
using PoliNetwork.Graduatorie.Common.Objects;
using PoliNetwork.Graduatorie.Parser.Objects;
using PoliNetwork.Graduatorie.Parser.Objects.Tables.Course;
using PoliNetwork.Graduatorie.Parser.Objects.Tables.Merit;
Expand All @@ -25,7 +25,7 @@ public static StudentResult FromMeritTableToStudentResult(MeritTableRow row)
PositionCourse = null,
SectionsResults = null,
EnglishCorrectAnswers = null,
EnrollType = EnrollUtil.GetEnrollType(rowCanEnrollInto, rowCanEnroll)
EnrollType = EnrollType.From(rowCanEnrollInto, rowCanEnroll)
};
}

Expand All @@ -39,7 +39,7 @@ public static StudentResult FromCourseTableRowToStudentResult(CourseTableRow row
Ofa = row.Ofa,
Result = row.Result,
BirthDate = row.BirthDate,
EnrollType = EnrollUtil.GetEnrollType(course.CourseTitle, rowCanEnroll),
EnrollType = EnrollType.From(course.CourseTitle, rowCanEnroll),
PositionAbsolute = null,
PositionCourse = row.Position,
SectionsResults = row.SectionsResults,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using PoliNetwork.Graduatorie.Common.Extensions;
using PoliNetwork.Graduatorie.Common.Objects;
using PoliNetwork.Graduatorie.Common.Objects.RankingNS;
using PoliNetwork.Graduatorie.Common.Utils;
using PoliNetwork.Graduatorie.Common.Utils.HashNS;
using PoliNetwork.Graduatorie.Parser.Objects;
using PoliNetwork.Graduatorie.Parser.Objects.Json.Indexes.Specific;
Expand Down Expand Up @@ -606,7 +605,7 @@ Table<CourseTableRow> course
Ofa = row.Ofa,
Result = row.Result,
BirthDate = row.BirthDate,
EnrollType = EnrollUtil.GetEnrollType(course.CourseTitle, canEnroll),
EnrollType = EnrollType.From(course.CourseTitle, canEnroll),
PositionCourse = row.Position,
SectionsResults = row.SectionsResults,
EnglishCorrectAnswers = row.EnglishCorrectAnswers
Expand All @@ -620,7 +619,7 @@ Table<CourseTableRow> course
return student;

student.PositionAbsolute = meritRow.Position;
student.EnrollType = EnrollUtil.GetEnrollType(meritRow.CanEnrollInto, canEnroll);
student.EnrollType = EnrollType.From(meritRow.CanEnrollInto, canEnroll);
return student;
}

Expand All @@ -643,7 +642,7 @@ IEnumerable<CourseTable> courses
var canEnroll = row.CanEnroll ?? false;
var student = new StudentResult
{
EnrollType = EnrollUtil.GetEnrollType(row.CanEnrollInto, canEnroll),
EnrollType = EnrollType.From(row.CanEnrollInto, canEnroll),
Id = row.Id,
PositionAbsolute = row.Position,
Result = row.Result,
Expand Down

0 comments on commit ab1033f

Please sign in to comment.