Skip to content

Commit

Permalink
WEB - improved view pages and enable ApiUser search by Role
Browse files Browse the repository at this point in the history
  • Loading branch information
crni99 committed Oct 3, 2024
1 parent 5dd7c42 commit 0a41bed
Show file tree
Hide file tree
Showing 27 changed files with 116 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ public async Task<IActionResult> Details(int id)


[HttpGet]
[Route("GetApiUsersByName/{name}")]
public async Task<IActionResult> GetApiUsersByName(string name)
[Route("GetApiUsersByRole/{role}")]
public async Task<IActionResult> GetApiUsersByName(string role)
{
if (string.IsNullOrEmpty(name))
if (string.IsNullOrEmpty(role))
{
_alertService.SetAlertMessage(TempData, "missing_field", false);
return RedirectToAction("Index");
}
var response = await _httpCallService.GetDataByName<ApiUserEntity>(name);
var response = await _httpCallService.GetDataByRole<ApiUserEntity>(role);
return Json(response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public interface IHttpCallService
Task<string> GetDataForPrice<T>(int? minPrice, int? maxPrice);
Task<string> GetDataBetweenDates<T>(string? startDate, string? endDate);
Task<string> GetDataByCityOrAirport<T>(string? city, string? airport);
Task<string> GetDataByRole<T>(string role);
Task<T> GetHealthCheck<T>();
string GetModelName<T>();
}
Expand Down
41 changes: 41 additions & 0 deletions AirportAutomation/AirportAutomationWeb/Services/HttpCallService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,47 @@ public async Task<string> GetDataByCityOrAirport<T>(string city, string airport)
return null;
}

/// <summary>
/// Gets data of a specified type by role in JSON format.
/// </summary>
/// <typeparam name="T">The type of data to retrieve.</typeparam>
/// <param name="role">The role used to filter the data.</param>
/// <returns>
/// Returns a JSON string containing the data of type <typeparamref name="T"/> filtered by the specified role.
/// If the retrieval fails, returns null with an error logged.
/// </returns>
public async Task<string> GetDataByRole<T>(string role)
{
var modelName = GetModelName<T>();

string requestUri = $"{apiURL}/{modelName}";
if (modelName.Equals("TravelClass"))
{
requestUri += $"es/byRole/{role}";
}
else
{
requestUri += $"s/byRole/{role}";
}

var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, requestUri);

using var httpClient = _httpClientFactory.CreateClient("AirportAutomationApi");
ConfigureHttpClient(httpClient);

var response = await httpClient.SendAsync(httpRequestMessage);

if (response.IsSuccessStatusCode)
{
return await response.Content.ReadAsStringAsync();
}
else
{
_logger.LogInformation("Failed to retrieve data. Status code: {StatusCode}", response.StatusCode);
}
return null;
}

/// <summary>
/// Creates a new data entry of a specified type.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
@model AirportAutomation.Web.Models.Airline.AirlineCreateViewModel;

@{
ViewData["Title"] = "View";
}
@{
ViewBag.Title = "Create Airline";
}

@Html.AntiForgeryToken()

@if (ViewBag.ApiUserRole != "User")
{
<h4>Create Airline</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="CreateAirline" method="post">
@Html.AntiForgeryToken()
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group pb-4">
<label asp-for="Name" class="control-label"></label>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
@model AirportAutomation.Web.Models.Airline.AirlineViewModel;

@{
ViewData["Title"] = "View";
}
@{
ViewBag.Title = "Airline Details";
}

@Html.AntiForgeryToken()

<div>
<h4>Airline Details</h4>
<hr />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
@model AirportAutomation.Web.Models.Airline.AirlineViewModel;

@{
ViewData["Title"] = "Edit";
ViewBag.Title = "Edit Airline";
}

@Html.AntiForgeryToken()

@if (ViewBag.ApiUserRole != "User")
{
<h4>Edit Airline</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="EditAirline" method="post">
@Html.AntiForgeryToken()
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Id" class="control-label"></label>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
@model AirportAutomation.Web.Models.ApiUser.ApiUserViewModel;

@{
ViewData["Title"] = "View";
}
@{
ViewBag.Title = "Api User Details";
}

@Html.AntiForgeryToken()

@if (ViewBag.ApiUserRole == "SuperAdmin")
{
<div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
@model AirportAutomation.Web.Models.ApiUser.ApiUserViewModel;

@{
ViewData["Title"] = "Edit";
ViewBag.Title = "Edit Api User";
}

@Html.AntiForgeryToken()
@if (ViewBag.ApiUserRole == "SuperAdmin")
{
<h4>Edit Api User</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="EditApiUser" method="post">
@Html.AntiForgeryToken()
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Id" class="control-label"></label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
@if (Model != null)
{
<div class="input-group mb-3" style="width: 70%;">
<label for="searchInput" class="input-group-text">Search by Role:</label>
<input type="text" id="searchInput" class="form-control" required />
<label for="roleSelect" class="input-group-text">Search by Role:</label>
<select id="roleSelect" class="form-control" required>
<option value="" disabled selected>Select a role</option>
<option value="User">User</option>
<option value="Admin">Admin</option>
<option value="SuperAdmin">Super Admin</option>
</select>
<button id="searchButton" class="btn btn-primary">Search</button>
</div>
}
Expand Down Expand Up @@ -89,7 +94,7 @@ else
$(document).ready(function () {
var searchUrl = '@Url.Action("GetApiUsersByRole", "ApiUser", new { area = "", name = "" })';
var tableBody = $('#tableBody');
searchByName(searchUrl, tableBody, 'ApiUser');
searchByRole(searchUrl, tableBody, 'ApiUser');
});
</script>
<script src="~/js/AlertHelper.js"></script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
@model AirportAutomation.Web.Models.Destination.DestinationCreateViewModel;

@{
ViewData["Title"] = "View";
}
@{
ViewBag.Title = "Create Destination";
}

@Html.AntiForgeryToken()

@if (ViewBag.ApiUserRole != "User")
{
<h4>Create Destination</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="CreateDestination" method="post">
@Html.AntiForgeryToken()
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group pb-3">
<label asp-for="City" class="control-label"></label>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
@model AirportAutomation.Web.Models.Destination.DestinationViewModel;

@{
ViewData["Title"] = "View";
}
@{
ViewBag.Title = "Destination Details";
}

@Html.AntiForgeryToken()

<div>
<h4>Destination Details</h4>
<hr />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
@model AirportAutomation.Web.Models.Destination.DestinationViewModel;

@{
ViewData["Title"] = "Edit";
ViewBag.Title = "Edit Destination";
}

@Html.AntiForgeryToken()

@if (ViewBag.ApiUserRole != "User")
{
<h4>Edit Destination</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="EditDestination" method="post">
@Html.AntiForgeryToken()
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Id" class="control-label"></label>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
@model AirportAutomation.Web.Models.Flight.FlightCreateViewModel;

@{
ViewData["Title"] = "View";
}
@{
ViewBag.Title = "Create Flight";
}

@Html.AntiForgeryToken()

@if (ViewBag.ApiUserRole != "User")
{
<h4>Create Flight</h4>
<hr />
<form asp-action="CreateFlight">
@Html.AntiForgeryToken()
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="row">
<div class="col-md-4">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
@model AirportAutomation.Web.Models.Flight.FlightViewModel;

@{
ViewData["Title"] = "View";
}
@{
ViewBag.Title = "Flight Details";
}

@Html.AntiForgeryToken()

<div>
<h4>Flight Details</h4>
<hr />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
@model AirportAutomation.Web.Models.Flight.FlightViewModel;

@{
ViewData["Title"] = "Edit";
ViewBag.Title = "Edit Flight";
}

@Html.AntiForgeryToken()

@if (ViewBag.ApiUserRole != "User")
{
<h4>Edit Flight</h4>
<hr />
<form asp-action="EditFlight" method="post">
@Html.AntiForgeryToken()
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="row">
<div class="col-md-4">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@model AirportAutomation.Web.Models.HealthCheck.HealthCheckViewModel;

@{
ViewBag.Title = "Health Check";
ViewBag.Title = "Health Checks";
}

<div class="container mt-5">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
@model AirportAutomation.Web.Models.Passenger.PassengerCreateViewModel;

@{
ViewData["Title"] = "View";
}
@{
ViewBag.Title = "Create Passenger";
}

@Html.AntiForgeryToken()

@if (ViewBag.ApiUserRole != "User")
{
<h4>Create Passenger</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="CreatePassenger" method="post">
@Html.AntiForgeryToken()
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group pb-3">
<label asp-for="FirstName" class="control-label"></label>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
@model AirportAutomation.Web.Models.Passenger.PassengerViewModel;
@{
ViewData["Title"] = "View";
}

@{
ViewBag.Title = "Passenger Details";
}

@Html.AntiForgeryToken()

<div>
<h4>Passenger Details</h4>
<hr />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
@model AirportAutomation.Web.Models.Passenger.PassengerViewModel;

@{
ViewData["Title"] = "Edit";
ViewBag.Title = "Edit Passenger";
}

@Html.AntiForgeryToken()

@if (ViewBag.ApiUserRole != "User")
{
<h4>Edit Passenger</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="EditPassenger" method="post">
@Html.AntiForgeryToken()
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Id" class="control-label"></label>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
@model AirportAutomation.Web.Models.Pilot.PilotCreateViewModel;

@{
ViewData["Title"] = "View";
}
@{
ViewBag.Title = "Create Pilot";
}

@Html.AntiForgeryToken()

@if (ViewBag.ApiUserRole != "User")
{
<h4>Create Pilot</h4>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="CreatePilot" method="post">
@Html.AntiForgeryToken()
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group pb-3">
<label asp-for="FirstName" class="control-label"></label>
Expand Down
Loading

0 comments on commit 0a41bed

Please sign in to comment.