Compare commits
2 Commits
e5cc147bfa
...
577fa15fd7
Author | SHA1 | Date | |
---|---|---|---|
577fa15fd7 | |||
4d62eafccb |
@ -30,10 +30,22 @@ public class MainController : ControllerBase
|
||||
return await _publicDataService.GetAllCards();
|
||||
}
|
||||
|
||||
[HttpGet("GetAllMoviesInCity/{cityName}")]
|
||||
public async Task<IEnumerable<Film>> GetAllMoviesInCityWithPuskinCard(string cityName)
|
||||
[HttpGet("GetAllFilmsInCity/{cityName}")]
|
||||
public async Task<ActionResult<IEnumerable<FilmDto>>> GetAllFilmsInCityWithPuskinCard(string cityName)
|
||||
{
|
||||
return await _publicDataService.GetAllFilmsInCity(cityName);
|
||||
if (!_publicDataService.CityExsist(cityName))
|
||||
return BadRequest("City does not exsist");
|
||||
|
||||
return Ok(await _publicDataService.GetAllFilmsInCity(cityName));
|
||||
}
|
||||
|
||||
[HttpGet("GetAllMuseumsInCity/{cityName}")]
|
||||
public async Task<ActionResult<IEnumerable<Museum>>> GetAllMuseumsInCity(string cityName)
|
||||
{
|
||||
if (!_publicDataService.CityExsist(cityName))
|
||||
return BadRequest("City does not exsist");
|
||||
|
||||
return Ok(await _publicDataService.GetAllMuseumsInCity(cityName));
|
||||
}
|
||||
|
||||
}
|
@ -8,6 +8,7 @@ namespace FichaBackend
|
||||
public DbSet<City> Cities { get; set; } = null!;
|
||||
public DbSet<Film> Films { get; set; } = null!;
|
||||
public DbSet<CardQuestion> CardQuestions { get; set; } = null!;
|
||||
public DbSet<Museum> Museums { get; set; } = null!;
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
|
@ -18,6 +18,8 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" Version="6.0.2" />
|
||||
<PackageReference Include="AutoMapper" Version="12.0.1" />
|
||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.9" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.9">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
@ -37,4 +39,5 @@
|
||||
|
||||
|
||||
|
||||
|
||||
</Project>
|
||||
|
14
FichaBackend/Models/Museum.cs
Normal file
14
FichaBackend/Models/Museum.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace FichaBackend.Models;
|
||||
|
||||
public class Museum
|
||||
{
|
||||
[Key]
|
||||
public long Id { get; set; }
|
||||
public City City { get; set; }
|
||||
public string Name { get; set; }
|
||||
public double Longtitude { get; set; }
|
||||
public double Latitude { get; set; }
|
||||
public float? Price { get; set; }
|
||||
}
|
13
FichaBackend/Models/MuseumDto.cs
Normal file
13
FichaBackend/Models/MuseumDto.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace FichaBackend.Models;
|
||||
|
||||
public class MuseumDto
|
||||
{
|
||||
[Key]
|
||||
public string City { get; set; }
|
||||
public string Name { get; set; }
|
||||
public double Longtitude { get; set; }
|
||||
public double Latitude { get; set; }
|
||||
public float? Price { get; set; }
|
||||
}
|
@ -39,6 +39,9 @@ builder.Services.AddDbContext<DatabaseContext>(options =>
|
||||
builder.Services.AddHealthChecks()
|
||||
.AddNpgSql(dbConString);
|
||||
|
||||
// AutoMapper
|
||||
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
|
||||
|
||||
// Services
|
||||
builder.Services.AddScoped<IPublicDataService, PublicDataService>();
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using FichaBackend.Models;
|
||||
using AutoMapper;
|
||||
using FichaBackend.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FichaBackend.Services;
|
||||
@ -6,8 +7,9 @@ namespace FichaBackend.Services;
|
||||
public interface IPublicDataService
|
||||
{
|
||||
public Task<IEnumerable<City>> GetAllCity();
|
||||
public Task<IEnumerable<Film>> GetAllFilmsInCity(string cityName);
|
||||
public Task<IEnumerable<FilmDto>> GetAllFilmsInCity(string cityName);
|
||||
public Task<IEnumerable<CardQuestion>> GetAllCards();
|
||||
public Task<IEnumerable<Museum>> GetAllMuseumsInCity(string cityName);
|
||||
public Task UpdateFilmsInCity(IEnumerable<FilmDto> films);
|
||||
public bool CityExsist(string cityName);
|
||||
}
|
||||
@ -15,10 +17,12 @@ public interface IPublicDataService
|
||||
public class PublicDataService : IPublicDataService
|
||||
{
|
||||
private readonly DatabaseContext _databaseContext;
|
||||
public readonly IMapper _mapper;
|
||||
|
||||
public PublicDataService(DatabaseContext databaseContext)
|
||||
public PublicDataService(DatabaseContext databaseContext, IMapper mapper)
|
||||
{
|
||||
_databaseContext = databaseContext;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<City>> GetAllCity()
|
||||
@ -26,9 +30,11 @@ public class PublicDataService : IPublicDataService
|
||||
return await _databaseContext.Cities.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Film>> GetAllFilmsInCity(string cityName)
|
||||
public async Task<IEnumerable<FilmDto>> GetAllFilmsInCity(string cityName)
|
||||
{
|
||||
return await _databaseContext.Films.Where(x => x.City.Name.ToLower() == cityName.ToLower()).ToListAsync();
|
||||
var films = await _databaseContext.Films.Where(x => x.City.Name.ToLower() == cityName.ToLower()).ToListAsync();
|
||||
var destinations = _mapper.Map<List<Film>, List<FilmDto>>(films);
|
||||
return destinations;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<CardQuestion>> GetAllCards()
|
||||
@ -36,6 +42,11 @@ public class PublicDataService : IPublicDataService
|
||||
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)
|
||||
{
|
||||
await _databaseContext.Films.Where(x => x.City.Name == films.First().City).ForEachAsync(x => _databaseContext.Films.Remove(x));
|
||||
@ -50,7 +61,7 @@ public class PublicDataService : IPublicDataService
|
||||
film.Time = filmDto.Time;
|
||||
film.ImageURL = filmDto.ImageURL;
|
||||
film.Url = filmDto.Url;
|
||||
film.City = await _databaseContext.Cities.FirstOrDefaultAsync(x => x.Name == filmDto.City);
|
||||
film.City = await _databaseContext.Cities.FirstAsync(x => x.Name.ToLower() == filmDto.City.ToLower());
|
||||
await _databaseContext.Films.AddAsync(film);
|
||||
}
|
||||
|
||||
|
15
FichaBackend/Utils/MappingProfiles.cs
Normal file
15
FichaBackend/Utils/MappingProfiles.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using AutoMapper;
|
||||
using FichaBackend.Models;
|
||||
|
||||
namespace FichaBackend.Utils;
|
||||
|
||||
public class MappingProfiles : Profile
|
||||
{
|
||||
public MappingProfiles()
|
||||
{
|
||||
CreateMap<FilmDto, Film>();
|
||||
CreateMap<Film, FilmDto>();
|
||||
CreateMap<Museum, MuseumDto>();
|
||||
CreateMap<MuseumDto, Museum>();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user