diff --git a/PaydayFrontend/Controllers/HomeController.cs b/PaydayFrontend/Controllers/HomeController.cs index c3e111f..7c20518 100644 --- a/PaydayFrontend/Controllers/HomeController.cs +++ b/PaydayFrontend/Controllers/HomeController.cs @@ -1,33 +1,34 @@ using System.Diagnostics; using Microsoft.AspNetCore.Mvc; -using Newtonsoft.Json; using PaydayFrontend.Models; +using PaydayFrontend.Services; namespace PaydayFrontend.Controllers; public class HomeController : Controller { private readonly ILogger _logger; + private readonly IUniversityService _universityService; - public HomeController(ILogger logger) + public HomeController(ILogger logger, IUniversityService universityService) { _logger = logger; + _universityService = universityService; } - - - public async Task Index() + + public async Task Index(string searchString) { - using HttpClient client = new(); + IEnumerable universities = await _universityService.GetAllUniversity(); - string json = await client.GetStringAsync( - "https://payday.zetcraft.ru/v1/public/university"); + if (!String.IsNullOrEmpty(searchString)) + { + universities = universities.Where(s => s.Name!.ToLower().Contains(searchString.ToLower())); + } - List universities = JsonConvert.DeserializeObject>(json); - - return View(universities); + return View(universities.ToList()); } - public IActionResult SecondPage() + public IActionResult SecondPage([FromQuery] long universityId) { return View(); } diff --git a/PaydayFrontend/Program.cs b/PaydayFrontend/Program.cs index 509110a..36138ce 100644 --- a/PaydayFrontend/Program.cs +++ b/PaydayFrontend/Program.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using PaydayFrontend.Data; +using PaydayFrontend.Services; var builder = WebApplication.CreateBuilder(args); @@ -15,6 +16,12 @@ builder.Services.AddDefaultIdentity(options => options.SignIn.Requ .AddEntityFrameworkStores(); builder.Services.AddControllersWithViews(); +builder.Services.AddHttpClient("backend", client => +{ + client.DefaultRequestHeaders.Add("Accept", "application/json"); +}); +builder.Services.AddTransient(); + var app = builder.Build(); // Configure the HTTP request pipeline. diff --git a/PaydayFrontend/Services/IUniversityService.cs b/PaydayFrontend/Services/IUniversityService.cs new file mode 100644 index 0000000..aecf0ef --- /dev/null +++ b/PaydayFrontend/Services/IUniversityService.cs @@ -0,0 +1,31 @@ +using System.Text.Json; +using PaydayFrontend.Models; + +namespace PaydayFrontend.Services; + +public interface IUniversityService +{ + public Task> GetAllUniversity(); +} + +public class UniversityService : IUniversityService +{ + private readonly HttpClient _httpClient; + + public UniversityService(HttpClient httpClient) + { + _httpClient = httpClient; + _httpClient.BaseAddress = new Uri("https://payday.zetcraft.ru"); + } + + public async Task> GetAllUniversity() + { + var response = await _httpClient.GetAsync("v1/public/university"); + var result = await response.Content.ReadAsStringAsync(); + var university = JsonSerializer.Deserialize>(result, new JsonSerializerOptions + { + PropertyNameCaseInsensitive = true + }); + return university; + } +} \ No newline at end of file diff --git a/PaydayFrontend/Views/Home/Index.cshtml b/PaydayFrontend/Views/Home/Index.cshtml index 1666d60..922aaf0 100644 --- a/PaydayFrontend/Views/Home/Index.cshtml +++ b/PaydayFrontend/Views/Home/Index.cshtml @@ -7,9 +7,10 @@
-
- search -
+
+ + +
@{ foreach (var university in Model) { diff --git a/PaydayFrontend/wwwroot/favicon.ico b/PaydayFrontend/wwwroot/favicon.ico deleted file mode 100644 index 63e859b..0000000 Binary files a/PaydayFrontend/wwwroot/favicon.ico and /dev/null differ diff --git a/PaydayFrontend/wwwroot/img/favicon.png b/PaydayFrontend/wwwroot/favicon.png similarity index 100% rename from PaydayFrontend/wwwroot/img/favicon.png rename to PaydayFrontend/wwwroot/favicon.png diff --git a/PaydayFrontend/wwwroot/img/icons/kubgu.jpg b/PaydayFrontend/wwwroot/img/icons/kubgu.jpg deleted file mode 100644 index f084176..0000000 Binary files a/PaydayFrontend/wwwroot/img/icons/kubgu.jpg and /dev/null differ diff --git a/PaydayFrontend/wwwroot/img/icons/vshe.png b/PaydayFrontend/wwwroot/img/icons/vshe.png deleted file mode 100644 index 1ce8069..0000000 Binary files a/PaydayFrontend/wwwroot/img/icons/vshe.png and /dev/null differ