Skip to content

Commit

Permalink
rbiyovskiy/785 codeficator add ordering and city districts to the res…
Browse files Browse the repository at this point in the history
…ult of the search request (#787)

* CodeficatorCategory moved to the Common project

* Model, DTO and filter changes

* service and repository changes

* test changes

* Codeficator Order update script

* Migration

* sonar bugs fixed

* review remarks fixed

* Migration CodeficatorAddOrder deleted
  • Loading branch information
RBiyovskiy authored Aug 8, 2022
1 parent de85a0a commit f40c2ed
Show file tree
Hide file tree
Showing 15 changed files with 159 additions and 78 deletions.
2 changes: 2 additions & 0 deletions OutOfSchool/OutOfSchool.Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ public static class Constants
{
public const int UnifiedUrlLength = 256;

public const long DefaultCityCodeficatorId = 31737;

public const string BearerScheme = "Bearer";

public const string PhoneNumberFormat = "{0:+380 XX-XXX-XX-XX}";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Ardalis.SmartEnum;

namespace OutOfSchool.Services.Enums;
namespace OutOfSchool.Common.Enums;

public abstract class CodeficatorCategory : SmartEnum<CodeficatorCategory>
{
Expand Down Expand Up @@ -128,7 +128,6 @@ public CityDistrictCategory()
}

// Group (flag) values

private sealed class Level1Category : CodeficatorCategory
{
public Level1Category()
Expand All @@ -152,7 +151,7 @@ public Level2Category()
private sealed class Level4Category : CodeficatorCategory
{
public Level4Category()
: base("MTCX", 208)
: base("MTCXK", 210)
{
}

Expand All @@ -162,7 +161,7 @@ public Level4Category()
private sealed class SearchableCategoriesCategory : CodeficatorCategory
{
public SearchableCategoriesCategory()
: base("MTCXK", 210)
: base("MTCXKB", 210)
{
}

Expand Down
26 changes: 18 additions & 8 deletions OutOfSchool/OutOfSchool.Common/Models/CodeficatorAddressDto.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace OutOfSchool.Common.Models;
using System.Text;
using OutOfSchool.Common.Enums;

namespace OutOfSchool.Common.Models;

public class CodeficatorAddressDto
{
Expand All @@ -20,35 +23,42 @@ public class CodeficatorAddressDto

public double Longitude { get; set; }

public int Order { get; set; }

public string FullName
{
get
{
string addr = CityDistrict;
StringBuilder fullName = new StringBuilder();

if (!string.IsNullOrEmpty(CityDistrict))
{
fullName.Append($"{CityDistrict} {CodeficatorCategory.CityDistrict.Abbrivation}");
}

if (!string.IsNullOrEmpty(Settlement))
{
addr += GetSplitter(addr) + Settlement;
fullName.Append($"{GetSplitter(fullName)}{Settlement}");
}

if (!string.IsNullOrEmpty(TerritorialCommunity))
{
addr += GetSplitter(addr) + TerritorialCommunity;
fullName.Append($"{GetSplitter(fullName)}{TerritorialCommunity} {CodeficatorCategory.TerritorialCommunity.Abbrivation}");
}

if (!string.IsNullOrEmpty(District))
{
addr += GetSplitter(addr) + District;
fullName.Append($"{GetSplitter(fullName)}{District} {CodeficatorCategory.District.Abbrivation}");
}

if (!string.IsNullOrEmpty(Region))
{
addr += GetSplitter(addr) + Region;
fullName.Append($"{GetSplitter(fullName)}{Region} {CodeficatorCategory.Region.Abbrivation}");
}

return addr;
return fullName.ToString();
}
}

private string GetSplitter(string addr) => string.IsNullOrEmpty(addr) ? string.Empty : Constants.AddressSeparator;
private static string GetSplitter(StringBuilder address) => address.Length == 0 ? string.Empty : Constants.AddressSeparator;
}
1 change: 1 addition & 0 deletions OutOfSchool/OutOfSchool.Common/OutOfSchool.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Ardalis.SmartEnum" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="6.0.0" />
<FrameworkReference Include="Microsoft.AspNetCore.App" />
Expand Down
7 changes: 4 additions & 3 deletions OutOfSchool/OutOfSchool.DataAccess/Models/Codeficator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;

namespace OutOfSchool.Services.Models;

Expand All @@ -26,5 +25,7 @@ public class CATOTTG : IKeyedEntity<long>

public bool NeedCheck { get; set; } = default;

public int Order { get; set; } = default;

public virtual CATOTTG Parent { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Ardalis.SmartEnum" Version="2.1.0" />
<PackageReference Include="Google.Cloud.Storage.V1" Version="3.7.0" />
<PackageReference Include="H3Lib" Version="3.7.2" />
<PackageReference Include="Microsoft.AspNetCore.DataProtection.EntityFrameworkCore" Version="6.0.6" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq.Expressions;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using OutOfSchool.Common.Enums;
using OutOfSchool.Common.Models;
using OutOfSchool.Services.Models;

Expand Down Expand Up @@ -33,23 +34,26 @@ public async Task<IEnumerable<KeyValuePair<long, string>>> GetNamesByFilter(Expr
/// <inheritdoc/>
public async Task<List<CodeficatorAddressDto>> GetFullAddressesByPartOfName(string namePart, string categories = default)
{
var query2 = from e in db.CATOTTGs
var query = from e in db.CATOTTGs
from p in db.CATOTTGs.Where(x1 => e.ParentId == x1.Id).DefaultIfEmpty()
from pp in db.CATOTTGs.Where(x2 => p.ParentId == x2.Id).DefaultIfEmpty()
from ppp in db.CATOTTGs.Where(x3 => pp.ParentId == x3.Id).DefaultIfEmpty()
where e.Name.StartsWith(namePart) && categories.Contains(e.Category)
from pppp in db.CATOTTGs.Where(x4 => ppp.ParentId == x4.Id).DefaultIfEmpty()
where ((CodeficatorCategory.Level4.Name.Contains(e.Category) && e.Name.StartsWith(namePart)) || (e.Category == CodeficatorCategory.CityDistrict.Name && p.Name.StartsWith(namePart))) && categories.Contains(e.Category)
select new CodeficatorAddressDto
{
Id = e.Id,
Category = e.Category,
Settlement = e.Name,
Settlement = e.Category == CodeficatorCategory.CityDistrict.Name ? p.Name : e.Name,
Latitude = e.Latitude,
Longitude = e.Longitude,
TerritorialCommunity = p.Name,
District = pp.Name,
Region = ppp.Name,
Order = e.Order,
TerritorialCommunity = e.Category == CodeficatorCategory.CityDistrict.Name ? pp.Name : p.Name,
District = e.Category == CodeficatorCategory.CityDistrict.Name ? ppp.Name : pp.Name,
Region = e.Category == CodeficatorCategory.CityDistrict.Name ? pppp.Name : ppp.Name,
CityDistrict = e.Category == CodeficatorCategory.CityDistrict.Name ? e.Name : null,
};

return await query2.ToListAsync();
return await query.OrderBy(x => x.Order).ToListAsync();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
USE out_of_school;

SET SQL_SAFE_UPDATES = 0;

UPDATE `codeficators` SET `Order` = 120 WHERE `Category` = 'O';
UPDATE `codeficators` SET `Order` = 110 WHERE `Category` = 'P';
UPDATE `codeficators` SET `Order` = 100 WHERE `Category` = 'H';
UPDATE `codeficators` SET `Order` = 80 WHERE `Category` = 'X';
UPDATE `codeficators` SET `Order` = 70 WHERE `Category` = 'C';
UPDATE `codeficators` SET `Order` = 60 WHERE `Category` = 'T';
UPDATE `codeficators` SET `Order` = 50 WHERE `Category` = 'M';
UPDATE `codeficators` SET `Order` = 40 WHERE `Category` = 'B';

UPDATE `codeficators` SET `Order` = 30 WHERE Id in (4506,4791,6006,6240,6752,19191,31748) AND `Category` IN ('M','K');
UPDATE `codeficators` SET `Order` = 20 WHERE Id in (1378,3917,9335,10720,21800,24274,28289,30145) AND `Category` = 'M';
UPDATE `codeficators` SET `Order` = 10 WHERE Id in (1099,4090,6193,7385,9793,13117,13960,15447,17423,18415,20675,23241,26238,27209,29660,31734,31737) AND `Category` IN ('M','K');

SELECT * FROM `out_of_school`.`codeficators` WHERE `Order` = 0;

SET SQL_SAFE_UPDATES = 1;
Loading

0 comments on commit f40c2ed

Please sign in to comment.