From 6fc58b72c39608d5025decc8e66fe086eee14bef Mon Sep 17 00:00:00 2001 From: Ezequiel Urbina Date: Sun, 21 Jul 2024 21:40:44 -0600 Subject: [PATCH] Create New Dto for CU-05 --- Controllers/AcademyController.cs | 5 +- Controllers/ApiResponse.cs | 7 + Controllers/SecretaryController.cs | 72 +++++-- Controllers/TariffCollectionController.cs | 3 + Controllers/URL.cs | 8 + Dockerfile | 9 +- Secretary/Components/EditTariff.razor | 2 + .../SchoolYears/ListSchoolYears.razor.cs | 25 +-- Secretary/SchoolYears/NewSchoolYear.razor | 184 ++++++++++++++---- Secretary/SchoolYears/NewSchoolYear.razor.cs | 129 ++++++++++-- dto/Output/NewSchoolYearDto.cs | 13 ++ dto/Output/NewTariffDto.cs | 22 +++ dto/input/Date.cs | 15 ++ dto/input/GradeDto.cs | 18 ++ dto/input/SchoolYearDto.cs | 21 ++ dto/input/SchoolYearTariffs.cs | 24 +++ dto/input/SubjectDto.cs | 15 ++ model/Secretary/Input/GradeEntity.cs | 5 +- model/Secretary/Input/SchoolYearEntity.cs | 17 +- wsmcbl.front.csproj | 1 - 20 files changed, 507 insertions(+), 88 deletions(-) create mode 100644 Controllers/ApiResponse.cs create mode 100644 Secretary/Components/EditTariff.razor create mode 100644 dto/Output/NewSchoolYearDto.cs create mode 100644 dto/Output/NewTariffDto.cs create mode 100644 dto/input/Date.cs create mode 100644 dto/input/GradeDto.cs create mode 100644 dto/input/SchoolYearDto.cs create mode 100644 dto/input/SchoolYearTariffs.cs create mode 100644 dto/input/SubjectDto.cs diff --git a/Controllers/AcademyController.cs b/Controllers/AcademyController.cs index 404a05f..7043dab 100644 --- a/Controllers/AcademyController.cs +++ b/Controllers/AcademyController.cs @@ -1,5 +1,6 @@ using System.Text; using Newtonsoft.Json; +using wsmcbl.front.model.Secretary.Input; using wsmcbl.front.model.Secretary.Output; @@ -7,7 +8,7 @@ namespace wsmcbl.front.Controllers; public class AcademyController(HttpClient httpClient) { - public async Task?> GetStudents() + public async Task?> GetStudents() { var response = await httpClient.GetAsync(URL.secretary + "students"); @@ -36,6 +37,4 @@ public async Task PostNewStudent(StudentEntityDto student) return true; } - - } diff --git a/Controllers/ApiResponse.cs b/Controllers/ApiResponse.cs new file mode 100644 index 0000000..51d7816 --- /dev/null +++ b/Controllers/ApiResponse.cs @@ -0,0 +1,7 @@ +namespace wsmcbl.front.Controllers; + +public class ApiResponse +{ + public bool Success { get; set; } + public string Message { get; set; } +} \ No newline at end of file diff --git a/Controllers/SecretaryController.cs b/Controllers/SecretaryController.cs index ab7ad14..7403696 100644 --- a/Controllers/SecretaryController.cs +++ b/Controllers/SecretaryController.cs @@ -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; @@ -10,25 +14,71 @@ public SecretaryController(HttpClient httpClient) _httpClient = httpClient; } - public async Task> GetGrades() + public async Task> 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>(); } - return await response.Content.ReadFromJsonAsync>(); + + throw new Exception($"Error al obtener los datos de la API: {response.ReasonPhrase}"); } - public async Task> GetSubjects() + public async Task 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(); + } - if (response.IsSuccessStatusCode is false) + throw new Exception($"Error al obtener los datos de la API: {response.ReasonPhrase}"); + } + + public async Task 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 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>(); } + + + } diff --git a/Controllers/TariffCollectionController.cs b/Controllers/TariffCollectionController.cs index a19e57b..7a6cbeb 100644 --- a/Controllers/TariffCollectionController.cs +++ b/Controllers/TariffCollectionController.cs @@ -125,4 +125,7 @@ public void setStudent(StudentEntity studentEntity) { cashier.setStudent(studentEntity); } + + + } \ No newline at end of file diff --git a/Controllers/URL.cs b/Controllers/URL.cs index 41490ab..352063d 100644 --- a/Controllers/URL.cs +++ b/Controllers/URL.cs @@ -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"; + + + } \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 9d903ba..e6124ca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -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"] + diff --git a/Secretary/Components/EditTariff.razor b/Secretary/Components/EditTariff.razor new file mode 100644 index 0000000..1f65635 --- /dev/null +++ b/Secretary/Components/EditTariff.razor @@ -0,0 +1,2 @@ +@inherits wsmcbl.front.Secretary.SchoolYears.NewSchoolYear_razor; + diff --git a/Secretary/SchoolYears/ListSchoolYears.razor.cs b/Secretary/SchoolYears/ListSchoolYears.razor.cs index 4e871bc..26ff0fa 100644 --- a/Secretary/SchoolYears/ListSchoolYears.razor.cs +++ b/Secretary/SchoolYears/ListSchoolYears.razor.cs @@ -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? SchoolYear; - - protected override async void OnInitialized() - { - SchoolYear = await GetSchoolYear(); - } - - private Task> GetSchoolYear() + protected List? 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 { years }); + SchoolYear = await controller.GetSchoolYears(); } } \ No newline at end of file diff --git a/Secretary/SchoolYears/NewSchoolYear.razor b/Secretary/SchoolYears/NewSchoolYear.razor index 79723b3..f36c84c 100644 --- a/Secretary/SchoolYears/NewSchoolYear.razor +++ b/Secretary/SchoolYears/NewSchoolYear.razor @@ -1,5 +1,6 @@ @page "/secretary/schoolyear/new" @inherits NewSchoolYear_razor; +@using wsmcbl.front.Secretary.Components; -@if (ListGrade == null) +@if (SchoolYearEntity == null) {
} @@ -20,8 +21,8 @@ else {
-
Configurar Año Lectivo 2024
- Guardar +
Configurar Año Lectivo @SchoolYearEntity.SchoolYearId
+ Guardar
@@ -42,7 +43,6 @@ else - @@ -50,17 +50,15 @@ else - - @foreach (var item in ListGrade) + @foreach (var item in SchoolYearEntity.Grades) { - @@ -80,53 +78,48 @@ else Listado de tarifas y aranceles - Nuevo +
-
-

Aqui va estar

-
-
- - -
-
-

- -

- Nuevo -
-
Id Año Lectivo Nombre Modalidad
Id Año Lectivo Nombre Modalidad
@item.GradeId @item.SchoolYear @item.Label @item.Modality
- - - + + + + + + - - + + + + + - @foreach (var item in ListSubject) + @foreach (var item in SchoolYearEntity.Tariffs) { - - - - - - + + + + + + + + + }
IdGradoNombreAño LectivoConceptoPrecioVencimientoTipo ModalidadEditar
Id Año LectivoNombreConceptoPrecioVencimientoTipo ModalidadEditar
@item.SubjectID@item.Description@item.Name@item.Modality
@item.SchoolYear@item.Concept@item.Amount@(item.DueDate?.Year ?? 0)/@(item.DueDate?.Month ?? 0)/@(item.DueDate?.Day ?? 0)@item.Type@item.Modality + +
@@ -135,9 +128,128 @@ else
+
+
+

+ +

+ Nuevo +
+
+
+

Detalles del Año Escolar

+ @foreach (var grade in SchoolYearEntity.Grades) + { +

@grade.Label - @grade.Modality

+
    + @foreach (var subject in grade.Subjects) + { +
  • + @subject.Name - Obligatorio: @subject.IsMandatory - Semestre: @subject.Semester +
  • + } +
+ } +
+
+
+ + + + @if (SelectedTariff != null) + { + + } + + @if (NewTariffItem != null) +{ + } +} + diff --git a/Secretary/SchoolYears/NewSchoolYear.razor.cs b/Secretary/SchoolYears/NewSchoolYear.razor.cs index 3676ed9..19ed5c2 100644 --- a/Secretary/SchoolYears/NewSchoolYear.razor.cs +++ b/Secretary/SchoolYears/NewSchoolYear.razor.cs @@ -1,24 +1,131 @@ using Microsoft.AspNetCore.Components; +using wsmcbl.front.Accounting; using wsmcbl.front.Controllers; +using wsmcbl.front.dto.input; +using wsmcbl.front.dto.Output; using wsmcbl.front.model.Secretary.Input; namespace wsmcbl.front.Secretary.SchoolYears; public class NewSchoolYear_razor : ComponentBase { - [Inject] protected SecretaryController Controller { get; set; } = null!; - [Parameter] public string? SchoolYearId { get; set; } - - protected List? ListGrade; - protected List? ListSubject; + [Inject] protected SecretaryController SController { get; set; } = null!; + [Inject] protected AlertService AlertService { get; set; } = null!; + protected SchoolYearEntity SchoolYearEntity; + protected SchoolYearTariffs? SelectedTariff; + protected NewTariffDto? NewTariffItem; + protected override async Task OnParametersSetAsync() { - - //Generar logica para al consultar la api con el parametro "new" - //obtener el objeto SchoolYear con el Id generado y la lista de - //Grade y Subject - ListGrade = await Controller.GetGrades(); - ListSubject = await Controller.GetSubjects(); + try + { + SchoolYearEntity = await SController.NewSchoolYears(); + if (SchoolYearEntity != null) + { + if (SchoolYearEntity.Tariffs != null) + { + foreach (var tariff in SchoolYearEntity.Tariffs.Where(tariff => tariff.DueDate == null)) + { + tariff.DueDate = new Date() + { + Year = 0, + Month = 0, + Day = 0 + }; + } + } + } + } + catch (Exception ex) + { + AlertService.AlertError("Error", $"Error al obtener los datos: {ex.Message}"); + } + } + protected async Task SaveSchoolYear(SchoolYearEntity schoolYearEntity) + { + if (schoolYearEntity != null && schoolYearEntity.Tariffs != null) + { + foreach (var tariff in schoolYearEntity.Tariffs) + { + if (tariff.DueDate != null && + tariff.DueDate.Year == 0 && + tariff.DueDate.Month == 0 && + tariff.DueDate.Day == 0) + { + tariff.DueDate = null; + } + } + } + var obj = ConvertToNewSchoolYear(schoolYearEntity); + var sending = await SController.SaveSchoolYear(obj); + } + public NewSchoolYearDto ConvertToNewSchoolYear(SchoolYearEntity schoolYearEntity) + { + return new NewSchoolYearDto() + { + Grades = schoolYearEntity.Grades, + Tariffs = schoolYearEntity.Tariffs + }; + } + protected void NewTariff() + { + NewTariffItem = new NewTariffDto + { + Concept = string.Empty, + Amount = 0, + Type = 0, + Modality = 0, + DueDate = new Date() + { + Year = 0, + Month = 0, + Day = 0 + } + }; + } + + protected async Task SaveNewTariff(NewTariffDto tariffs) + { + if (tariffs?.DueDate != null && + tariffs.DueDate.Year == 0 && + tariffs.DueDate.Month == 0 && + tariffs.DueDate.Day == 0) + { + tariffs.DueDate = null; + } + + var response = await SController.NewTariff(tariffs); + + if (response?.Success == true) + { + NewTariffItem = null; + StateHasChanged(); + await AlertService.AlertSuccess("Éxito", response.Message); + } + else + { + await AlertService.AlertError("Error", response?.Message ?? "Error desconocido"); + } + } + + protected void EditTariff(SchoolYearTariffs tariff) + { + SelectedTariff = tariff; + } + + protected Task SaveEdit() + { + if (SelectedTariff != null) + { + SelectedTariff = null; + } + return Task.CompletedTask; + } + + protected void Cancel() + { + SelectedTariff = null; + NewTariffItem = null; } } \ No newline at end of file diff --git a/dto/Output/NewSchoolYearDto.cs b/dto/Output/NewSchoolYearDto.cs new file mode 100644 index 0000000..e5bf091 --- /dev/null +++ b/dto/Output/NewSchoolYearDto.cs @@ -0,0 +1,13 @@ +using Newtonsoft.Json; +using wsmcbl.front.dto.input; + +namespace wsmcbl.front.dto.Output; + +public class NewSchoolYearDto +{ + [JsonProperty("grades")] + public List? Grades { get; set; } + + [JsonProperty("tariffs")] + public List? Tariffs { get; set; } +} \ No newline at end of file diff --git a/dto/Output/NewTariffDto.cs b/dto/Output/NewTariffDto.cs new file mode 100644 index 0000000..eafb3db --- /dev/null +++ b/dto/Output/NewTariffDto.cs @@ -0,0 +1,22 @@ +using Newtonsoft.Json; +using wsmcbl.front.dto.input; + +namespace wsmcbl.front.dto.Output; + +public class NewTariffDto +{ + [JsonProperty("concept")] + public string? Concept { get; set; } + + [JsonProperty("amount")] + public double Amount { get; set; } + + [JsonProperty("dueDate")] + public Date? DueDate { get; set; } + + [JsonProperty("typeId")] + public int Type { get; set; } + + [JsonProperty("modality")] + public int Modality { get; set; } +} \ No newline at end of file diff --git a/dto/input/Date.cs b/dto/input/Date.cs new file mode 100644 index 0000000..9c6c345 --- /dev/null +++ b/dto/input/Date.cs @@ -0,0 +1,15 @@ +using Newtonsoft.Json; + +namespace wsmcbl.front.dto.input; + +public class Date +{ + [JsonProperty("year")] + public int Year { get; set; } + + [JsonProperty("month")] + public int Month { get; set; } + + [JsonProperty("day")] + public int Day { get; set; } +} \ No newline at end of file diff --git a/dto/input/GradeDto.cs b/dto/input/GradeDto.cs new file mode 100644 index 0000000..c564b4f --- /dev/null +++ b/dto/input/GradeDto.cs @@ -0,0 +1,18 @@ +using Newtonsoft.Json; + +namespace wsmcbl.front.dto.input; + +public class GradeDto +{ + [JsonProperty("label")] + public string Label { get; set; } = null!; + + [JsonProperty("schoolYear")] + public string SchoolYear { get; set; } = null!; + + [JsonProperty("modality")] + public string Modality { get; set; } = null!; + + [JsonProperty("subjects")] + public List Subjects { get; set; } = null!; +} \ No newline at end of file diff --git a/dto/input/SchoolYearDto.cs b/dto/input/SchoolYearDto.cs new file mode 100644 index 0000000..180ea9a --- /dev/null +++ b/dto/input/SchoolYearDto.cs @@ -0,0 +1,21 @@ +using Newtonsoft.Json; + +namespace wsmcbl.front.dto.input; + +public class SchoolYearDto +{ + [JsonProperty("schoolYearId")] + public string SchoolYearId { get; set; } = null!; + + [JsonProperty("label")] + public string Label { get; set; } = null!; + + [JsonProperty("startDate")] + public string StartDate { get; set; } + + [JsonProperty("deadLine")] + public string DeadLine { get; set; } + + [JsonProperty("isActive")] + public bool IsActive { get; set; } +} \ No newline at end of file diff --git a/dto/input/SchoolYearTariffs.cs b/dto/input/SchoolYearTariffs.cs new file mode 100644 index 0000000..dfc4f89 --- /dev/null +++ b/dto/input/SchoolYearTariffs.cs @@ -0,0 +1,24 @@ +using Newtonsoft.Json; + +namespace wsmcbl.front.dto.input; + +public class SchoolYearTariffs +{ + [JsonProperty("schoolYear")] + public string? SchoolYear { get; set; } + + [JsonProperty("concept")] + public string? Concept { get; set; } + + [JsonProperty("amount")] + public double Amount { get; set; } + + [JsonProperty("dueDate")] + public Date? DueDate { get; set; } + + [JsonProperty("type")] + public int Type { get; set; } + + [JsonProperty("modality")] + public int Modality { get; set; } +} \ No newline at end of file diff --git a/dto/input/SubjectDto.cs b/dto/input/SubjectDto.cs new file mode 100644 index 0000000..8d859bf --- /dev/null +++ b/dto/input/SubjectDto.cs @@ -0,0 +1,15 @@ +using Newtonsoft.Json; + +namespace wsmcbl.front.dto.input; + +public class SubjectDto +{ + [JsonProperty("name")] + public string Name { get; set; } = null!; + + [JsonProperty("isMandatory")] + public bool IsMandatory { get; set; } + + [JsonProperty("semester")] + public int Semester { get; set; } +} \ No newline at end of file diff --git a/model/Secretary/Input/GradeEntity.cs b/model/Secretary/Input/GradeEntity.cs index 730e50d..d26a039 100644 --- a/model/Secretary/Input/GradeEntity.cs +++ b/model/Secretary/Input/GradeEntity.cs @@ -1,5 +1,5 @@ using Newtonsoft.Json; -using wsmcbl.front.model.Academy.Input; +using wsmcbl.front.dto.input; namespace wsmcbl.front.model.Secretary.Input; @@ -22,5 +22,8 @@ public class GradeEntity [JsonProperty("sections")] public List Sections { get; set; } = null!; + + [JsonProperty("subjects")] + public List? Subjects { get; set; } } \ No newline at end of file diff --git a/model/Secretary/Input/SchoolYearEntity.cs b/model/Secretary/Input/SchoolYearEntity.cs index 5060fef..6eddf89 100644 --- a/model/Secretary/Input/SchoolYearEntity.cs +++ b/model/Secretary/Input/SchoolYearEntity.cs @@ -1,21 +1,28 @@ using Newtonsoft.Json; +using wsmcbl.front.dto.input; namespace wsmcbl.front.model.Secretary.Input; public class SchoolYearEntity { - [JsonProperty("schoolYearId")] - public string SchoolYearId { get; set; } = null!; + [JsonProperty("id")] + public string? SchoolYearId { get; set; } [JsonProperty("label")] - public string Label { get; set; } = null!; + public string? Label { get; set; } [JsonProperty("startDate")] - public DateOnly StartDate { get; set; } + public string? StartDate { get; set; } [JsonProperty("deadLine")] - public DateOnly DeadLine { get; set; } + public string? DeadLine { get; set; } [JsonProperty("isActive")] public bool IsActive { get; set; } + + [JsonProperty("grades")] + public List? Grades { get; set; } + + [JsonProperty("tariffs")] + public List? Tariffs { get; set; } } \ No newline at end of file diff --git a/wsmcbl.front.csproj b/wsmcbl.front.csproj index d6f1b54..5fa750f 100644 --- a/wsmcbl.front.csproj +++ b/wsmcbl.front.csproj @@ -35,7 +35,6 @@ -