Skip to content

Commit

Permalink
Cleanup Api code (#5)
Browse files Browse the repository at this point in the history
- file store loading bug fix
- Added comments for methods
- Improved import tool,
- Updated CAEN codes
  • Loading branch information
twentytwokhz authored Feb 5, 2022
1 parent 4608b13 commit 1fcc9ab
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 95 deletions.
37 changes: 2 additions & 35 deletions src/CAEN.Api/Controllers/CaenController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,6 @@ public CaenController(ICaenService caenService)
this.caenService = caenService;
}

[HttpGet()]
public IActionResult GetAllCodes()
{
var result = caenService.GetCodesByFilter();
if (result.Count == 0)
{
return NotFound();
}
return Ok(result);
}

[HttpGet("search/{query}")]
public IActionResult SearchCodes(string query)
{
Expand All @@ -39,30 +28,8 @@ public IActionResult SearchCodes(string query)
return Ok(result);
}

[HttpGet("{sectionId}")]
public IActionResult GetCodesBySection(string sectionId)
{
var result = caenService.GetCodesByFilter(sectionId);
if (result.Count == 0)
{
return NotFound();
}
return Ok(result);
}

[HttpGet("{sectionId}/{divisionId}")]
public IActionResult GetCodesByDivision(string sectionId, string divisionId)
{
var result = caenService.GetCodesByFilter(sectionId, divisionId);
if (result.Count == 0)
{
return NotFound();
}
return Ok(result);
}

[HttpGet("{sectionId}/{divisionId}/{groupId}")]
public IActionResult GetCodesByGroup(string sectionId, string divisionId, string groupId)
[HttpGet("{sectionId?}/{divisionId?}/{groupId?}")]
public IActionResult GetCodesByFilter(string sectionId, string divisionId, string groupId)
{
var result = caenService.GetCodesByFilter(sectionId, divisionId, groupId);
if (result.Count == 0)
Expand Down
2 changes: 1 addition & 1 deletion src/CAEN.Import/CaenDataImportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void ConvertXlsToJson(string fileName, string outputFileName)
else if (isClass)
{
writer.WriteStartObject();
writer.WriteString("CAENRev2", col3);
writer.WriteString("CAENRev2", col3.PadLeft(4, '0'));
writer.WriteString("Denumire", col4);
writer.WriteString("CAENRev1", col5);
writer.WriteString("ISICRev4", col6);
Expand Down
6 changes: 3 additions & 3 deletions src/CAEN.Library/Models/CaenCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Section : ISearchableCaen
[JsonPropertyName("Denumire")]
public string Name { get; set; }
[JsonPropertyName("Diviziuni")]
public List<Division> Divisions { get; set; }
public List<Division> Divisions { get; set; } = new List<Division>();

public bool Search(string query)
{
Expand All @@ -27,7 +27,7 @@ public class Division : ISearchableCaen
[JsonPropertyName("Denumire")]
public string Name { get; set; }
[JsonPropertyName("Grupe")]
public List<Group> Groups { get; set; }
public List<Group> Groups { get; set; } = new List<Group>();

public bool Search(string query)
{
Expand All @@ -43,7 +43,7 @@ public class Group : ISearchableCaen
[JsonPropertyName("Denumire")]
public string Name { get; set; }
[JsonPropertyName("Clase")]
public List<CaenCode> Codes { get; set; }
public List<CaenCode> Codes { get; set; } = new List<CaenCode>();

public bool Search(string query)
{
Expand Down
3 changes: 2 additions & 1 deletion src/CAEN.Library/Services/CaenService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public class CaenService : ICaenService

public CaenService()
{
caenStore = JsonDocument.Parse(File.ReadAllText(storePath));
var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, storePath);
caenStore = JsonDocument.Parse(File.ReadAllText(filePath));
list = caenStore.Deserialize<List<Section>>();
}

Expand Down
16 changes: 15 additions & 1 deletion src/CAEN.Library/Services/ICaenService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,21 @@ namespace CAEN.Library.Services
{
public interface ICaenService
{
List<CaenCode> GetCodesByFilter(string sectionId = null, string divisionId = null, string groupId = null);
/// <summary>
/// Aduce codurile caen in functie
/// de parametrii oferiti
/// </summary>
/// <param name="sectionId"></param>
/// <param name="divisionId"></param>
/// <param name="groupId"></param>
/// <returns></returns>
List<CaenCode> GetCodesByFilter(string sectionId, string divisionId, string groupId);
/// <summary>
/// Cauta coduri caen corespunzatoare
/// criteriului de cautare
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
List<CaenCode> SearchCode(string query);
}
}
Loading

0 comments on commit 1fcc9ab

Please sign in to comment.