MISC
This commit is contained in:
parent
4713bc14dc
commit
0229793c88
@ -132,23 +132,21 @@ namespace ManagerService.Controllers
|
||||
|
||||
try
|
||||
{
|
||||
//var weatherSections = _myInfoMateDbContext.Sections.Where(s => s.ConfigurationId == id && s.Type == SectionType.Weather && !s.IsSubSection).ToList(); // TODO TEST
|
||||
var weatherSections = _myInfoMateDbContext.Sections.OfType<SectionWeather>()
|
||||
.Where(s => s.ConfigurationId == id && !s.IsSubSection)
|
||||
.ToList();
|
||||
|
||||
foreach (var weatherSection in weatherSections)
|
||||
{
|
||||
WeatherDTO weatherDTO = weatherSection.ToDTO();//JsonConvert.DeserializeObject<WeatherDTO>(weatherSection.Data);
|
||||
if (weatherDTO.city != null && weatherDTO.city.Length >= 2 &&
|
||||
(weatherDTO.updatedDate == null || weatherDTO.updatedDate.Value.AddHours(3) < DateTimeOffset.Now)) // Update all 4 hours
|
||||
if (weatherSection.WeatherCity != null && weatherSection.WeatherCity.Length >= 2 &&
|
||||
(weatherSection.WeatherUpdatedDate == null || weatherSection.WeatherUpdatedDate.Value.AddHours(3) < DateTimeOffset.Now)) // Update all 4 hours
|
||||
{
|
||||
// Call Openweather api with token from appSettings and update result with json
|
||||
var apiKey = _configuration.GetSection("OpenWeatherApiKey").Get<string>();
|
||||
|
||||
if (apiKey != null && apiKey.Length > 0)
|
||||
{
|
||||
string url = $"http://api.openweathermap.org/geo/1.0/direct?q={weatherDTO.city}&limit=1&appid={apiKey}";
|
||||
string url = $"http://api.openweathermap.org/geo/1.0/direct?q={weatherSection.WeatherCity}&limit=1&appid={apiKey}";
|
||||
|
||||
using (HttpClient client = new HttpClient())
|
||||
{
|
||||
@ -172,12 +170,10 @@ namespace ManagerService.Controllers
|
||||
callResponse.EnsureSuccessStatusCode();
|
||||
string callResponseBody = await callResponse.Content.ReadAsStringAsync();
|
||||
|
||||
weatherDTO.updatedDate = DateTimeOffset.Now;
|
||||
weatherDTO.result = callResponseBody;
|
||||
//weatherSection.Data = JsonConvert.SerializeObject(weatherDTO); // TODO update
|
||||
|
||||
|
||||
weatherSection.WeatherUpdatedDate = DateTimeOffset.Now.ToUniversalTime(); ;
|
||||
weatherSection.WeatherResult = callResponseBody;
|
||||
_myInfoMateDbContext.SaveChanges();
|
||||
//_sectionService.Update(weatherSection.Id, weatherSection);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -672,6 +672,21 @@ namespace ManagerService.Controllers
|
||||
if (section == null)
|
||||
throw new KeyNotFoundException("Section does not exist");
|
||||
|
||||
|
||||
if (section.Type == SectionType.Map)
|
||||
{
|
||||
// REMOVE ALL POINTS
|
||||
var geoPoints = _myInfoMateDbContext.GeoPoints.Where(gp => gp.SectionMapId == section.Id).ToList();
|
||||
_myInfoMateDbContext.RemoveRange(geoPoints);
|
||||
}
|
||||
|
||||
if (section.Type == SectionType.Quiz)
|
||||
{
|
||||
// REMOVE ALL Questions
|
||||
var quizQuestions = _myInfoMateDbContext.QuizQuestions.Where(qq => qq.SectionQuizId == section.Id).ToList();
|
||||
_myInfoMateDbContext.RemoveRange(quizQuestions);
|
||||
}
|
||||
|
||||
_myInfoMateDbContext.Remove(section);
|
||||
//_sectionService.Remove(id);
|
||||
|
||||
|
||||
@ -95,7 +95,7 @@ namespace ManagerService.Controllers
|
||||
/// </summary>
|
||||
/// <param name="sectionId">Section Id</param>
|
||||
/// <param name="geoPointDTO">geoPoint</param>
|
||||
[ProducesResponseType(typeof(GeoPoint), 200)]
|
||||
[ProducesResponseType(typeof(GeoPointDTO), 200)]
|
||||
[ProducesResponseType(typeof(string), 400)]
|
||||
[ProducesResponseType(typeof(string), 409)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
@ -138,7 +138,25 @@ namespace ManagerService.Controllers
|
||||
|
||||
_myInfoMateDbContext.SaveChanges();
|
||||
|
||||
return new OkObjectResult(geoPoint);
|
||||
var geoPointDto = new GeoPointDTO()
|
||||
{
|
||||
id = geoPoint.Id,
|
||||
title = geoPoint.Title,
|
||||
description = geoPoint.Description,
|
||||
contents = geoPoint.Contents,
|
||||
categorieId = geoPoint.CategorieId,
|
||||
latitude = geoPoint.Latitude,
|
||||
longitude = geoPoint.Longitude,
|
||||
imageResourceId = geoPoint.ImageResourceId,
|
||||
imageUrl = geoPoint.ImageUrl,
|
||||
schedules = geoPoint.Schedules,
|
||||
prices = geoPoint.Prices,
|
||||
phone = geoPoint.Phone,
|
||||
email = geoPoint.Email,
|
||||
site = geoPoint.Site
|
||||
};
|
||||
|
||||
return new OkObjectResult(geoPointDto);
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
|
||||
@ -135,7 +135,7 @@ namespace ManagerService.Controllers
|
||||
/// Update a quiz question
|
||||
/// </summary>
|
||||
/// <param name="updatedQuizQuestion">QuizQuestion to update</param>
|
||||
[ProducesResponseType(typeof(QuizQuestion), 200)]
|
||||
[ProducesResponseType(typeof(QuestionDTO), 200)]
|
||||
[ProducesResponseType(typeof(string), 400)]
|
||||
[ProducesResponseType(typeof(string), 404)]
|
||||
[ProducesResponseType(typeof(string), 500)]
|
||||
@ -158,7 +158,7 @@ namespace ManagerService.Controllers
|
||||
|
||||
_myInfoMateDbContext.SaveChanges();
|
||||
|
||||
return new OkObjectResult(existingQuestion);
|
||||
return new OkObjectResult(questionDTO);
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
|
||||
@ -7,7 +7,7 @@ namespace Manager.DTOs
|
||||
{
|
||||
public List<TranslationAndResourceDTO> messageDebut { get; set; }
|
||||
public List<TranslationAndResourceDTO> messageFin { get; set; }
|
||||
public ResourceDTO puzzleImage { get; set; } // But only image is possible
|
||||
public ResourceDTO? puzzleImage { get; set; } // But only image is possible
|
||||
public string puzzleImageId { get; set; } // But only image is possible
|
||||
public int rows { get; set; } = 3;
|
||||
public int cols { get; set; } = 3;
|
||||
|
||||
@ -20,7 +20,7 @@ namespace ManagerService.Data.SubSection
|
||||
|
||||
public string ResourceId { get; set; }
|
||||
|
||||
public Resource Resource { get; set; }
|
||||
public Resource? Resource { get; set; }
|
||||
|
||||
|
||||
public TranslationAndResourceDTO ToDTO()
|
||||
@ -30,7 +30,7 @@ namespace ManagerService.Data.SubSection
|
||||
language = Language,
|
||||
value = Value,
|
||||
resourceId = ResourceId,
|
||||
resource = Resource.ToDTO()
|
||||
resource = Resource?.ToDTO()
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user