From dbd21a699f2b3890bd1f2402b6d052249454fa10 Mon Sep 17 00:00:00 2001 From: Sergey Karmanov Date: Sat, 26 Aug 2023 13:38:12 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BE=D1=82=D0=B5=D0=BB=D0=B8=20=D0=B8=20=D0=B4=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D0=BF=D1=80=D0=B8=D0=BC=D0=B5=D1=87=D0=B0=D1=82?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BD=D0=BE=D1=81=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ FichaBackend/Controllers/AdminController.cs | 29 +++++++++++++-- FichaBackend/Controllers/MainController.cs | 28 ++++++++++++++- FichaBackend/DatabaseContext.cs | 2 ++ FichaBackend/Models/Attraction.cs | 13 +++++++ FichaBackend/Models/DTO/AttractionDto.cs | 9 +++++ FichaBackend/Models/DTO/HotelDto.cs | 10 ++++++ FichaBackend/Models/Hotel.cs | 14 ++++++++ FichaBackend/Services/IAdminService.cs | 40 +++++++++++++++++++-- FichaBackend/Services/IPublicDataService.cs | 32 +++++++++++------ FichaBackend/Utils/MappingProfiles.cs | 4 +++ FichaBackend/appsettings.Development.json | 11 ------ 12 files changed, 167 insertions(+), 27 deletions(-) create mode 100644 FichaBackend/Models/Attraction.cs create mode 100644 FichaBackend/Models/DTO/AttractionDto.cs create mode 100644 FichaBackend/Models/DTO/HotelDto.cs create mode 100644 FichaBackend/Models/Hotel.cs delete mode 100644 FichaBackend/appsettings.Development.json diff --git a/.gitignore b/.gitignore index fdbd58e..cb5049c 100644 --- a/.gitignore +++ b/.gitignore @@ -491,3 +491,5 @@ fabric.properties # Android studio 3.1+ serialized cache file .idea/caches/build_file_checksums.ser + +FichaBackend/appsettings.Development.json diff --git a/FichaBackend/Controllers/AdminController.cs b/FichaBackend/Controllers/AdminController.cs index eb4e428..12907d9 100644 --- a/FichaBackend/Controllers/AdminController.cs +++ b/FichaBackend/Controllers/AdminController.cs @@ -1,4 +1,5 @@ -using FichaBackend.Models.DTO; +using FichaBackend.Models; +using FichaBackend.Models.DTO; using FichaBackend.Services; using Microsoft.AspNetCore.Mvc; @@ -32,7 +33,7 @@ public class AdminController : ControllerBase } /// - /// Добавляет гида + /// Добавляем гида /// /// /// @@ -43,6 +44,30 @@ public class AdminController : ControllerBase return Ok(); } + /// + /// Добавляет достопримечательности + /// + /// + /// + [HttpPost("AddAttraction")] + public async Task AddAttraction(AttractionDto attractionDto) + { + await _adminService.AddAttraction(attractionDto); + return Ok(); + } + + /// + /// Добавляет отель + /// + /// + /// + [HttpPost("AddHotel")] + public async Task AddHotel(HotelDto hotelDto) + { + await _adminService.AddHotel(hotelDto); + return Ok(); + } + // GET /// diff --git a/FichaBackend/Controllers/MainController.cs b/FichaBackend/Controllers/MainController.cs index 4c150b6..411a4e0 100644 --- a/FichaBackend/Controllers/MainController.cs +++ b/FichaBackend/Controllers/MainController.cs @@ -45,7 +45,33 @@ public class MainController : ControllerBase if (!_publicDataService.CityExsist(cityName)) return BadRequest("City does not exsist"); - return Ok(await _publicDataService.GetAllFilmsInCity(cityName)); + return Ok(await _publicDataService.GetAllFilms(cityName)); + } + + /// + /// Получаем все отели в городе + /// + /// + [HttpGet("GetAllHotelsInCity/{cityName}")] + public async Task>> GetAllHotelsInCity(string cityName) + { + if (!_publicDataService.CityExsist(cityName)) + return BadRequest("City does not exsist"); + + return Ok(await _publicDataService.GetAllHotels(cityName)); + } + + /// + /// Получаем все достопримечательности в городе + /// + /// + [HttpGet("GetAllAttractionsInCity/{cityName}")] + public async Task>> GetAllAttractionsInCity(string cityName) + { + if (!_publicDataService.CityExsist(cityName)) + return BadRequest("City does not exsist"); + + return Ok(await _publicDataService.GetAllAttractions(cityName)); } /// diff --git a/FichaBackend/DatabaseContext.cs b/FichaBackend/DatabaseContext.cs index 8310569..e143ac3 100644 --- a/FichaBackend/DatabaseContext.cs +++ b/FichaBackend/DatabaseContext.cs @@ -10,6 +10,8 @@ namespace FichaBackend public DbSet CardQuestions { get; set; } = null!; public DbSet Museums { get; set; } = null!; public DbSet Guides { get; set; } = null!; + public DbSet Attractions { get; set; } = null!; + public DbSet Hotels { get; set; } = null!; protected override void OnModelCreating(ModelBuilder modelBuilder) { diff --git a/FichaBackend/Models/Attraction.cs b/FichaBackend/Models/Attraction.cs new file mode 100644 index 0000000..8553327 --- /dev/null +++ b/FichaBackend/Models/Attraction.cs @@ -0,0 +1,13 @@ +using System.ComponentModel.DataAnnotations; + +namespace FichaBackend.Models; + +public class Attraction +{ + [Key] + public long Id { get; set; } + public string City { get; set; } + public string Name { get; set; } + public string Address { get; set; } + public string ImageURL { get; set; } +} \ No newline at end of file diff --git a/FichaBackend/Models/DTO/AttractionDto.cs b/FichaBackend/Models/DTO/AttractionDto.cs new file mode 100644 index 0000000..8d4eceb --- /dev/null +++ b/FichaBackend/Models/DTO/AttractionDto.cs @@ -0,0 +1,9 @@ +namespace FichaBackend.Models; + +public class AttractionDto +{ + public string City { get; set; } + public string Name { get; set; } + public string Address { get; set; } + public string ImageURL { get; set; } +} \ No newline at end of file diff --git a/FichaBackend/Models/DTO/HotelDto.cs b/FichaBackend/Models/DTO/HotelDto.cs new file mode 100644 index 0000000..1670c1b --- /dev/null +++ b/FichaBackend/Models/DTO/HotelDto.cs @@ -0,0 +1,10 @@ +namespace FichaBackend.Models; + +public class HotelDto +{ + public string Name { get; set; } + public string City { get; set; } + public float Price { get; set; } + public string Address { get; set; } + public string ImageURL { get; set; } +} \ No newline at end of file diff --git a/FichaBackend/Models/Hotel.cs b/FichaBackend/Models/Hotel.cs new file mode 100644 index 0000000..f35a3e4 --- /dev/null +++ b/FichaBackend/Models/Hotel.cs @@ -0,0 +1,14 @@ +using System.ComponentModel.DataAnnotations; + +namespace FichaBackend.Models; + +public class Hotel +{ + [Key] + public long Id { get; set; } + public string Name { get; set; } + public string City { get; set; } + public float Price { get; set; } + public string Address { get; set; } + public string ImageURL { get; set; } +} \ No newline at end of file diff --git a/FichaBackend/Services/IAdminService.cs b/FichaBackend/Services/IAdminService.cs index 10c1370..f9442a2 100644 --- a/FichaBackend/Services/IAdminService.cs +++ b/FichaBackend/Services/IAdminService.cs @@ -9,6 +9,8 @@ public interface IAdminService { public Task AddMuseum(MuseumDto museumDto); public Task AddGuidePerson(GuideDto guideDto); + public Task AddHotel(HotelDto hotelDto); + public Task AddAttraction(AttractionDto attractionDto); } public class AdminService : IAdminService @@ -24,11 +26,12 @@ public class AdminService : IAdminService public async Task AddMuseum(MuseumDto museumDto) { - Museum m = new(); - m.Name = museumDto.Name; City c = await _databaseContext.Cities.FirstOrDefaultAsync(x => x.Name.ToLower() == museumDto.City.ToLower()); if (c==null) return; + + Museum m = new(); + m.Name = museumDto.Name; m.City = c; m.Price = museumDto.Price; m.Latitude = museumDto.Latitude; @@ -58,4 +61,37 @@ public class AdminService : IAdminService await _databaseContext.SaveChangesAsync(); return "OK"; } + + public async Task AddHotel(HotelDto hotelDto) + { + var c = await _databaseContext.Cities.FirstOrDefaultAsync(x => x.Name.ToLower() == hotelDto.City.ToLower()); + if (c==null) + return $"City {c} not exist"; + + Hotel h = new(); + h.Name = hotelDto.Name; + h.City = hotelDto.City; + h.Price = hotelDto.Price; + h.Address = hotelDto.Address; + h.ImageURL = hotelDto.ImageURL; + await _databaseContext.Hotels.AddAsync(h); + await _databaseContext.SaveChangesAsync(); + return "OK"; + } + + public async Task AddAttraction(AttractionDto attractionDto) + { + var c = await _databaseContext.Cities.FirstOrDefaultAsync(x => x.Name.ToLower() == attractionDto.City.ToLower()); + if (c==null) + return $"City {c} not exist"; + + Attraction h = new(); + h.Name = attractionDto.Name; + h.City = attractionDto.City; + h.Address = attractionDto.Address; + h.ImageURL = attractionDto.ImageURL; + await _databaseContext.Attractions.AddAsync(h); + await _databaseContext.SaveChangesAsync(); + return "OK"; + } } \ No newline at end of file diff --git a/FichaBackend/Services/IPublicDataService.cs b/FichaBackend/Services/IPublicDataService.cs index e309698..6707035 100644 --- a/FichaBackend/Services/IPublicDataService.cs +++ b/FichaBackend/Services/IPublicDataService.cs @@ -8,13 +8,14 @@ namespace FichaBackend.Services; public interface IPublicDataService { public Task> GetAllCity(); - public Task> GetAllFilmsInCity(string cityName); public Task> GetAllCards(); - public Task> GetAllMuseumsInCity(string cityName); public Task UpdateFilmsInCity(IEnumerable films); public bool CityExsist(string cityName); public Task> GetAllMuseum(string cityName = ""); public Task> GetAllGuides(string cityName = ""); + public Task> GetAllHotels(string cityName = ""); + public Task> GetAllFilms(string cityName); + public Task> GetAllAttractions(string cityName = ""); } public class PublicDataService : IPublicDataService @@ -33,11 +34,24 @@ public class PublicDataService : IPublicDataService return await _databaseContext.Cities.ToListAsync(); } - public async Task> GetAllFilmsInCity(string cityName) + public async Task> GetAllFilms(string cityName) { - var films = await _databaseContext.Films.Where(x => x.City.Name.ToLower() == cityName.ToLower()).ToListAsync(); - var destinations = _mapper.Map, List>(films); - return destinations; + IEnumerable films = cityName == "" ? await _databaseContext.Films.ToListAsync() : + _databaseContext.Films.Where(x => x.City.Name.ToLower() == cityName.ToLower()); + return _mapper.Map, IEnumerable>(films); + } + + public async Task> GetAllAttractions(string cityName = "") + { + IEnumerable attractions = cityName == "" ? await _databaseContext.Attractions.ToListAsync() : + _databaseContext.Attractions.Where(x => x.City.ToLower() == cityName.ToLower()); + return _mapper.Map, IEnumerable>(attractions); + } + public async Task> GetAllHotels(string cityName = "") + { + IEnumerable hotels = cityName == "" ? await _databaseContext.Hotels.ToListAsync() : + _databaseContext.Hotels.Where(x => x.City.ToLower() == cityName.ToLower()); + return _mapper.Map, IEnumerable>(hotels); } public async Task> GetAllCards() @@ -45,11 +59,6 @@ public class PublicDataService : IPublicDataService return await _databaseContext.CardQuestions.ToListAsync(); } - public async Task> GetAllMuseumsInCity(string cityName) - { - return await _databaseContext.Museums.Where(x => x.City.Name.ToLower() == cityName.ToLower()).ToListAsync(); - } - public async Task UpdateFilmsInCity(IEnumerable films) { await _databaseContext.Films.Where(x => x.City.Name == films.First().City).ForEachAsync(x => _databaseContext.Films.Remove(x)); @@ -89,4 +98,5 @@ public class PublicDataService : IPublicDataService _databaseContext.Guides.Where(x => x.City.Any(y => y.Name.ToLower() == cityName.ToLower())); return _mapper.Map, IEnumerable>(guides); } + } \ No newline at end of file diff --git a/FichaBackend/Utils/MappingProfiles.cs b/FichaBackend/Utils/MappingProfiles.cs index 7d7ba30..4a95f35 100644 --- a/FichaBackend/Utils/MappingProfiles.cs +++ b/FichaBackend/Utils/MappingProfiles.cs @@ -14,5 +14,9 @@ public class MappingProfiles : Profile CreateMap(); CreateMap(); CreateMap(); + CreateMap(); + CreateMap(); + CreateMap(); + CreateMap(); } } \ No newline at end of file diff --git a/FichaBackend/appsettings.Development.json b/FichaBackend/appsettings.Development.json deleted file mode 100644 index e167deb..0000000 --- a/FichaBackend/appsettings.Development.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "ConnectionStrings": { - "DefaultConnection": "Host=192.168.0.46;Port=5432;Database=backend;Username=prod;Password=" - }, - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft.AspNetCore": "Warning" - } - } -}