Добавил отели и достопримечательности
This commit is contained in:
parent
5c22d34125
commit
dbd21a699f
2
.gitignore
vendored
2
.gitignore
vendored
@ -491,3 +491,5 @@ fabric.properties
|
|||||||
# Android studio 3.1+ serialized cache file
|
# Android studio 3.1+ serialized cache file
|
||||||
.idea/caches/build_file_checksums.ser
|
.idea/caches/build_file_checksums.ser
|
||||||
|
|
||||||
|
|
||||||
|
FichaBackend/appsettings.Development.json
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using FichaBackend.Models.DTO;
|
using FichaBackend.Models;
|
||||||
|
using FichaBackend.Models.DTO;
|
||||||
using FichaBackend.Services;
|
using FichaBackend.Services;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
@ -32,7 +33,7 @@ public class AdminController : ControllerBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавляет гида
|
/// Добавляем гида
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="guideDto"></param>
|
/// <param name="guideDto"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
@ -43,6 +44,30 @@ public class AdminController : ControllerBase
|
|||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавляет достопримечательности
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="attractionDto"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("AddAttraction")]
|
||||||
|
public async Task<ActionResult> AddAttraction(AttractionDto attractionDto)
|
||||||
|
{
|
||||||
|
await _adminService.AddAttraction(attractionDto);
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавляет отель
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="hotelDto"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("AddHotel")]
|
||||||
|
public async Task<ActionResult> AddHotel(HotelDto hotelDto)
|
||||||
|
{
|
||||||
|
await _adminService.AddHotel(hotelDto);
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
// GET
|
// GET
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -45,7 +45,33 @@ public class MainController : ControllerBase
|
|||||||
if (!_publicDataService.CityExsist(cityName))
|
if (!_publicDataService.CityExsist(cityName))
|
||||||
return BadRequest("City does not exsist");
|
return BadRequest("City does not exsist");
|
||||||
|
|
||||||
return Ok(await _publicDataService.GetAllFilmsInCity(cityName));
|
return Ok(await _publicDataService.GetAllFilms(cityName));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получаем все отели в городе
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("GetAllHotelsInCity/{cityName}")]
|
||||||
|
public async Task<ActionResult<IEnumerable<HotelDto>>> GetAllHotelsInCity(string cityName)
|
||||||
|
{
|
||||||
|
if (!_publicDataService.CityExsist(cityName))
|
||||||
|
return BadRequest("City does not exsist");
|
||||||
|
|
||||||
|
return Ok(await _publicDataService.GetAllHotels(cityName));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получаем все достопримечательности в городе
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("GetAllAttractionsInCity/{cityName}")]
|
||||||
|
public async Task<ActionResult<IEnumerable<AttractionDto>>> GetAllAttractionsInCity(string cityName)
|
||||||
|
{
|
||||||
|
if (!_publicDataService.CityExsist(cityName))
|
||||||
|
return BadRequest("City does not exsist");
|
||||||
|
|
||||||
|
return Ok(await _publicDataService.GetAllAttractions(cityName));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -10,6 +10,8 @@ namespace FichaBackend
|
|||||||
public DbSet<CardQuestion> CardQuestions { get; set; } = null!;
|
public DbSet<CardQuestion> CardQuestions { get; set; } = null!;
|
||||||
public DbSet<Museum> Museums { get; set; } = null!;
|
public DbSet<Museum> Museums { get; set; } = null!;
|
||||||
public DbSet<Guide> Guides { get; set; } = null!;
|
public DbSet<Guide> Guides { get; set; } = null!;
|
||||||
|
public DbSet<Attraction> Attractions { get; set; } = null!;
|
||||||
|
public DbSet<Hotel> Hotels { get; set; } = null!;
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
13
FichaBackend/Models/Attraction.cs
Normal file
13
FichaBackend/Models/Attraction.cs
Normal file
@ -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; }
|
||||||
|
}
|
9
FichaBackend/Models/DTO/AttractionDto.cs
Normal file
9
FichaBackend/Models/DTO/AttractionDto.cs
Normal file
@ -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; }
|
||||||
|
}
|
10
FichaBackend/Models/DTO/HotelDto.cs
Normal file
10
FichaBackend/Models/DTO/HotelDto.cs
Normal file
@ -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; }
|
||||||
|
}
|
14
FichaBackend/Models/Hotel.cs
Normal file
14
FichaBackend/Models/Hotel.cs
Normal file
@ -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; }
|
||||||
|
}
|
@ -9,6 +9,8 @@ public interface IAdminService
|
|||||||
{
|
{
|
||||||
public Task AddMuseum(MuseumDto museumDto);
|
public Task AddMuseum(MuseumDto museumDto);
|
||||||
public Task<string> AddGuidePerson(GuideDto guideDto);
|
public Task<string> AddGuidePerson(GuideDto guideDto);
|
||||||
|
public Task<string> AddHotel(HotelDto hotelDto);
|
||||||
|
public Task<string> AddAttraction(AttractionDto attractionDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AdminService : IAdminService
|
public class AdminService : IAdminService
|
||||||
@ -24,11 +26,12 @@ public class AdminService : IAdminService
|
|||||||
|
|
||||||
public async Task AddMuseum(MuseumDto museumDto)
|
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());
|
City c = await _databaseContext.Cities.FirstOrDefaultAsync(x => x.Name.ToLower() == museumDto.City.ToLower());
|
||||||
if (c==null)
|
if (c==null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Museum m = new();
|
||||||
|
m.Name = museumDto.Name;
|
||||||
m.City = c;
|
m.City = c;
|
||||||
m.Price = museumDto.Price;
|
m.Price = museumDto.Price;
|
||||||
m.Latitude = museumDto.Latitude;
|
m.Latitude = museumDto.Latitude;
|
||||||
@ -58,4 +61,37 @@ public class AdminService : IAdminService
|
|||||||
await _databaseContext.SaveChangesAsync();
|
await _databaseContext.SaveChangesAsync();
|
||||||
return "OK";
|
return "OK";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<string> 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<string> 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";
|
||||||
|
}
|
||||||
}
|
}
|
@ -8,13 +8,14 @@ namespace FichaBackend.Services;
|
|||||||
public interface IPublicDataService
|
public interface IPublicDataService
|
||||||
{
|
{
|
||||||
public Task<IEnumerable<City>> GetAllCity();
|
public Task<IEnumerable<City>> GetAllCity();
|
||||||
public Task<IEnumerable<FilmDto>> GetAllFilmsInCity(string cityName);
|
|
||||||
public Task<IEnumerable<CardQuestion>> GetAllCards();
|
public Task<IEnumerable<CardQuestion>> GetAllCards();
|
||||||
public Task<IEnumerable<Museum>> GetAllMuseumsInCity(string cityName);
|
|
||||||
public Task UpdateFilmsInCity(IEnumerable<FilmDto> films);
|
public Task UpdateFilmsInCity(IEnumerable<FilmDto> films);
|
||||||
public bool CityExsist(string cityName);
|
public bool CityExsist(string cityName);
|
||||||
public Task<IEnumerable<MuseumDto>> GetAllMuseum(string cityName = "");
|
public Task<IEnumerable<MuseumDto>> GetAllMuseum(string cityName = "");
|
||||||
public Task<IEnumerable<GuideDto>> GetAllGuides(string cityName = "");
|
public Task<IEnumerable<GuideDto>> GetAllGuides(string cityName = "");
|
||||||
|
public Task<IEnumerable<HotelDto>> GetAllHotels(string cityName = "");
|
||||||
|
public Task<IEnumerable<FilmDto>> GetAllFilms(string cityName);
|
||||||
|
public Task<IEnumerable<AttractionDto>> GetAllAttractions(string cityName = "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PublicDataService : IPublicDataService
|
public class PublicDataService : IPublicDataService
|
||||||
@ -33,11 +34,24 @@ public class PublicDataService : IPublicDataService
|
|||||||
return await _databaseContext.Cities.ToListAsync();
|
return await _databaseContext.Cities.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<FilmDto>> GetAllFilmsInCity(string cityName)
|
public async Task<IEnumerable<FilmDto>> GetAllFilms(string cityName)
|
||||||
{
|
{
|
||||||
var films = await _databaseContext.Films.Where(x => x.City.Name.ToLower() == cityName.ToLower()).ToListAsync();
|
IEnumerable<Film> films = cityName == "" ? await _databaseContext.Films.ToListAsync() :
|
||||||
var destinations = _mapper.Map<List<Film>, List<FilmDto>>(films);
|
_databaseContext.Films.Where(x => x.City.Name.ToLower() == cityName.ToLower());
|
||||||
return destinations;
|
return _mapper.Map<IEnumerable<Film>, IEnumerable<FilmDto>>(films);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<AttractionDto>> GetAllAttractions(string cityName = "")
|
||||||
|
{
|
||||||
|
IEnumerable<Attraction> attractions = cityName == "" ? await _databaseContext.Attractions.ToListAsync() :
|
||||||
|
_databaseContext.Attractions.Where(x => x.City.ToLower() == cityName.ToLower());
|
||||||
|
return _mapper.Map<IEnumerable<Attraction>, IEnumerable<AttractionDto>>(attractions);
|
||||||
|
}
|
||||||
|
public async Task<IEnumerable<HotelDto>> GetAllHotels(string cityName = "")
|
||||||
|
{
|
||||||
|
IEnumerable<Hotel> hotels = cityName == "" ? await _databaseContext.Hotels.ToListAsync() :
|
||||||
|
_databaseContext.Hotels.Where(x => x.City.ToLower() == cityName.ToLower());
|
||||||
|
return _mapper.Map<IEnumerable<Hotel>, IEnumerable<HotelDto>>(hotels);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<CardQuestion>> GetAllCards()
|
public async Task<IEnumerable<CardQuestion>> GetAllCards()
|
||||||
@ -45,11 +59,6 @@ public class PublicDataService : IPublicDataService
|
|||||||
return await _databaseContext.CardQuestions.ToListAsync();
|
return await _databaseContext.CardQuestions.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<Museum>> GetAllMuseumsInCity(string cityName)
|
|
||||||
{
|
|
||||||
return await _databaseContext.Museums.Where(x => x.City.Name.ToLower() == cityName.ToLower()).ToListAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task UpdateFilmsInCity(IEnumerable<FilmDto> films)
|
public async Task UpdateFilmsInCity(IEnumerable<FilmDto> films)
|
||||||
{
|
{
|
||||||
await _databaseContext.Films.Where(x => x.City.Name == films.First().City).ForEachAsync(x => _databaseContext.Films.Remove(x));
|
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()));
|
_databaseContext.Guides.Where(x => x.City.Any(y => y.Name.ToLower() == cityName.ToLower()));
|
||||||
return _mapper.Map<IEnumerable<Guide>, IEnumerable<GuideDto>>(guides);
|
return _mapper.Map<IEnumerable<Guide>, IEnumerable<GuideDto>>(guides);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -14,5 +14,9 @@ public class MappingProfiles : Profile
|
|||||||
CreateMap<MuseumDto, Museum>();
|
CreateMap<MuseumDto, Museum>();
|
||||||
CreateMap<Guide, GuideDto>();
|
CreateMap<Guide, GuideDto>();
|
||||||
CreateMap<GuideDto, Guide>();
|
CreateMap<GuideDto, Guide>();
|
||||||
|
CreateMap<Hotel, HotelDto>();
|
||||||
|
CreateMap<HotelDto, Hotel>();
|
||||||
|
CreateMap<Attraction, AttractionDto>();
|
||||||
|
CreateMap<AttractionDto, Attraction>();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user