Compare commits
No commits in common. "577fa15fd759cd069432377263ff1962ceb2ab87" and "e5cc147bfaf11a53312e637f7b39f2fb99029c62" have entirely different histories.
577fa15fd7
...
e5cc147bfa
@ -30,22 +30,10 @@ public class MainController : ControllerBase
|
|||||||
return await _publicDataService.GetAllCards();
|
return await _publicDataService.GetAllCards();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("GetAllFilmsInCity/{cityName}")]
|
[HttpGet("GetAllMoviesInCity/{cityName}")]
|
||||||
public async Task<ActionResult<IEnumerable<FilmDto>>> GetAllFilmsInCityWithPuskinCard(string cityName)
|
public async Task<IEnumerable<Film>> GetAllMoviesInCityWithPuskinCard(string cityName)
|
||||||
{
|
{
|
||||||
if (!_publicDataService.CityExsist(cityName))
|
return await _publicDataService.GetAllFilmsInCity(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,7 +8,6 @@ namespace FichaBackend
|
|||||||
public DbSet<City> Cities { get; set; } = null!;
|
public DbSet<City> Cities { get; set; } = null!;
|
||||||
public DbSet<Film> Films { get; set; } = null!;
|
public DbSet<Film> Films { get; set; } = null!;
|
||||||
public DbSet<CardQuestion> CardQuestions { get; set; } = null!;
|
public DbSet<CardQuestion> CardQuestions { get; set; } = null!;
|
||||||
public DbSet<Museum> Museums { get; set; } = null!;
|
|
||||||
|
|
||||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
{
|
{
|
||||||
|
@ -18,8 +18,6 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" Version="6.0.2" />
|
<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" Version="7.0.9" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.9">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.9">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
@ -39,5 +37,4 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
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; }
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
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,9 +39,6 @@ builder.Services.AddDbContext<DatabaseContext>(options =>
|
|||||||
builder.Services.AddHealthChecks()
|
builder.Services.AddHealthChecks()
|
||||||
.AddNpgSql(dbConString);
|
.AddNpgSql(dbConString);
|
||||||
|
|
||||||
// AutoMapper
|
|
||||||
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
|
|
||||||
|
|
||||||
// Services
|
// Services
|
||||||
builder.Services.AddScoped<IPublicDataService, PublicDataService>();
|
builder.Services.AddScoped<IPublicDataService, PublicDataService>();
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using AutoMapper;
|
using FichaBackend.Models;
|
||||||
using FichaBackend.Models;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace FichaBackend.Services;
|
namespace FichaBackend.Services;
|
||||||
@ -7,9 +6,8 @@ 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<Film>> 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);
|
||||||
}
|
}
|
||||||
@ -17,12 +15,10 @@ public interface IPublicDataService
|
|||||||
public class PublicDataService : IPublicDataService
|
public class PublicDataService : IPublicDataService
|
||||||
{
|
{
|
||||||
private readonly DatabaseContext _databaseContext;
|
private readonly DatabaseContext _databaseContext;
|
||||||
public readonly IMapper _mapper;
|
|
||||||
|
|
||||||
public PublicDataService(DatabaseContext databaseContext, IMapper mapper)
|
public PublicDataService(DatabaseContext databaseContext)
|
||||||
{
|
{
|
||||||
_databaseContext = databaseContext;
|
_databaseContext = databaseContext;
|
||||||
_mapper = mapper;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<City>> GetAllCity()
|
public async Task<IEnumerable<City>> GetAllCity()
|
||||||
@ -30,11 +26,9 @@ 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<Film>> GetAllFilmsInCity(string cityName)
|
||||||
{
|
{
|
||||||
var films = await _databaseContext.Films.Where(x => x.City.Name.ToLower() == cityName.ToLower()).ToListAsync();
|
return 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()
|
public async Task<IEnumerable<CardQuestion>> GetAllCards()
|
||||||
@ -42,11 +36,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));
|
||||||
@ -61,7 +50,7 @@ public class PublicDataService : IPublicDataService
|
|||||||
film.Time = filmDto.Time;
|
film.Time = filmDto.Time;
|
||||||
film.ImageURL = filmDto.ImageURL;
|
film.ImageURL = filmDto.ImageURL;
|
||||||
film.Url = filmDto.Url;
|
film.Url = filmDto.Url;
|
||||||
film.City = await _databaseContext.Cities.FirstAsync(x => x.Name.ToLower() == filmDto.City.ToLower());
|
film.City = await _databaseContext.Cities.FirstOrDefaultAsync(x => x.Name == filmDto.City);
|
||||||
await _databaseContext.Films.AddAsync(film);
|
await _databaseContext.Films.AddAsync(film);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
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