Skip to content

Commit

Permalink
Create New Dto for CU-05
Browse files Browse the repository at this point in the history
  • Loading branch information
EzequielUrbina committed Jul 22, 2024
1 parent f2eccbe commit 6fc58b7
Show file tree
Hide file tree
Showing 20 changed files with 507 additions and 88 deletions.
5 changes: 2 additions & 3 deletions Controllers/AcademyController.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System.Text;
using Newtonsoft.Json;
using wsmcbl.front.model.Secretary.Input;
using wsmcbl.front.model.Secretary.Output;


namespace wsmcbl.front.Controllers;

public class AcademyController(HttpClient httpClient)
{
public async Task<List<model.Secretary.Input.StudentEntity>?> GetStudents()
public async Task<List<StudentEntity>?> GetStudents()
{
var response = await httpClient.GetAsync(URL.secretary + "students");

Expand Down Expand Up @@ -36,6 +37,4 @@ public async Task<bool> PostNewStudent(StudentEntityDto student)

return true;
}


}
7 changes: 7 additions & 0 deletions Controllers/ApiResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace wsmcbl.front.Controllers;

public class ApiResponse
{
public bool Success { get; set; }
public string Message { get; set; }
}
72 changes: 61 additions & 11 deletions Controllers/SecretaryController.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
using System.Text;
using Newtonsoft.Json;
using wsmcbl.front.dto.input;
using wsmcbl.front.dto.Output;
using wsmcbl.front.model.Secretary.Input;

namespace wsmcbl.front.Controllers;
Expand All @@ -10,25 +14,71 @@ public SecretaryController(HttpClient httpClient)
_httpClient = httpClient;
}

public async Task<List<GradeEntity?>> GetGrades()
public async Task<List<SchoolYearDto>> GetSchoolYears()
{
var response = await _httpClient.GetAsync(URL.secretary + "grades");
if (response.IsSuccessStatusCode is false)
var response = await _httpClient.GetAsync(URL.ListSchoolYears);

if (response.IsSuccessStatusCode)
{
throw new Exception($"Error al obtener los datos de la API: {response.ReasonPhrase}");
return await response.Content.ReadFromJsonAsync<List<SchoolYearDto>>();
}
return await response.Content.ReadFromJsonAsync<List<GradeEntity>>();

throw new Exception($"Error al obtener los datos de la API: {response.ReasonPhrase}");
}

public async Task<List<Subject?>> GetSubjects()
public async Task <SchoolYearEntity> NewSchoolYears()
{
var response = await _httpClient.GetAsync(URL.secretary + "grades/subjects");
var response = await _httpClient.GetAsync(URL.NewSchoolYear);

if (response.IsSuccessStatusCode)
{
return await response.Content.ReadFromJsonAsync<SchoolYearEntity>();
}

if (response.IsSuccessStatusCode is false)
throw new Exception($"Error al obtener los datos de la API: {response.ReasonPhrase}");
}

public async Task<bool> SaveSchoolYear(NewSchoolYearDto schoolYearEntity)
{
var url = URL.PostSchoolYear; // Asumiendo que URL.PostSchoolYear es la URL base correcta

// Serializar el objeto SchoolYearEntity usando Newtonsoft.Json
var json = JsonConvert.SerializeObject(schoolYearEntity);

var contenido = new StringContent(json, Encoding.UTF8, "application/json");

var respuesta = await _httpClient.PostAsync(url, contenido);

// Devolver true si la respuesta fue exitosa, false en caso contrario
return respuesta.IsSuccessStatusCode;
}

public async Task<ApiResponse> NewTariff(NewTariffDto tariffs)
{
try
{
throw new Exception($"Error al obtener los datos de la API: {response.ReasonPhrase}");
var url = URL.NewSchoolYearTariff;
var json = JsonConvert.SerializeObject(tariffs);
var contenido = new StringContent(json, Encoding.UTF8, "application/json");

var respuesta = await _httpClient.PostAsync(url, contenido);

if (respuesta.IsSuccessStatusCode)
{
return new ApiResponse { Success = true, Message = "La tarifa fue guardada correctamente" };
}
else
{
var errorContent = await respuesta.Content.ReadAsStringAsync();
return new ApiResponse { Success = false, Message = $"Error del servidor: {errorContent}" };
}
}
catch (Exception ex)
{
return new ApiResponse { Success = false, Message = $"An error occurred: {ex.Message}" };
}
return await response.Content.ReadFromJsonAsync<List<Subject>>();
}



}
3 changes: 3 additions & 0 deletions Controllers/TariffCollectionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,7 @@ public void setStudent(StudentEntity studentEntity)
{
cashier.setStudent(studentEntity);
}



}
8 changes: 8 additions & 0 deletions Controllers/URL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ public static class URL

public static string TRANSACTION = $"{accounting}transactions/invoices/";
public static string APPLYARREARS = $"{api}/accounting/arrears/";

public static string ListSchoolYears = $"{secretary}configurations/schoolyears?q=all";
public static string NewSchoolYear = $"{secretary}configurations/schoolyears?q=new";
public static string PostSchoolYear = $"{secretary}configurations/schoolyears";
public static string NewSchoolYearTariff = $"{secretary}configurations/schoolyears/tariffs";



}
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /FrontCbl

EXPOSE 80
EXPOSE 5050

# Copiamos los archivos del proyecto
COPY ./*.csproj ./
RUN dotnet restore
Expand All @@ -16,7 +13,13 @@ RUN dotnet publish -c Release -o out
# Fase final
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /FrontCbl

# Exponemos los puertos necesarios
EXPOSE 80
EXPOSE 8080

COPY --from=build /FrontCbl/out .
ENTRYPOINT ["dotnet", "wsmcbl.front.dll"]



2 changes: 2 additions & 0 deletions Secretary/Components/EditTariff.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@inherits wsmcbl.front.Secretary.SchoolYears.NewSchoolYear_razor;

25 changes: 8 additions & 17 deletions Secretary/SchoolYears/ListSchoolYears.razor.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
using System.Runtime.InteropServices;
using Microsoft.AspNetCore.Components;
using wsmcbl.front.Controllers;
using wsmcbl.front.dto.input;
using wsmcbl.front.model.Secretary.Input;

namespace wsmcbl.front.Secretary.SchoolYears;

public class ListSchoolYears_razor : ComponentBase
{
protected List<SchoolYearEntity>? SchoolYear;

protected override async void OnInitialized()
{
SchoolYear = await GetSchoolYear();
}

private Task<List<SchoolYearEntity>> GetSchoolYear()
protected List<SchoolYearDto>? SchoolYear;
[Inject] protected SecretaryController controller { get; set; } = null!;

protected override async Task OnParametersSetAsync()
{
var years = new SchoolYearEntity()
{
SchoolYearId = "001",
Label = "2023",
StartDate = new DateOnly(2023, 1, 1),
DeadLine = new DateOnly(2023,12,31),
IsActive = false,
};
return Task.FromResult(new List<SchoolYearEntity> { years });
SchoolYear = await controller.GetSchoolYears();
}
}
Loading

0 comments on commit 6fc58b7

Please sign in to comment.