MISC
This commit is contained in:
parent
4713bc14dc
commit
0229793c88
@ -132,23 +132,21 @@ namespace ManagerService.Controllers
|
|||||||
|
|
||||||
try
|
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>()
|
var weatherSections = _myInfoMateDbContext.Sections.OfType<SectionWeather>()
|
||||||
.Where(s => s.ConfigurationId == id && !s.IsSubSection)
|
.Where(s => s.ConfigurationId == id && !s.IsSubSection)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
foreach (var weatherSection in weatherSections)
|
foreach (var weatherSection in weatherSections)
|
||||||
{
|
{
|
||||||
WeatherDTO weatherDTO = weatherSection.ToDTO();//JsonConvert.DeserializeObject<WeatherDTO>(weatherSection.Data);
|
if (weatherSection.WeatherCity != null && weatherSection.WeatherCity.Length >= 2 &&
|
||||||
if (weatherDTO.city != null && weatherDTO.city.Length >= 2 &&
|
(weatherSection.WeatherUpdatedDate == null || weatherSection.WeatherUpdatedDate.Value.AddHours(3) < DateTimeOffset.Now)) // Update all 4 hours
|
||||||
(weatherDTO.updatedDate == null || weatherDTO.updatedDate.Value.AddHours(3) < DateTimeOffset.Now)) // Update all 4 hours
|
|
||||||
{
|
{
|
||||||
// Call Openweather api with token from appSettings and update result with json
|
// Call Openweather api with token from appSettings and update result with json
|
||||||
var apiKey = _configuration.GetSection("OpenWeatherApiKey").Get<string>();
|
var apiKey = _configuration.GetSection("OpenWeatherApiKey").Get<string>();
|
||||||
|
|
||||||
if (apiKey != null && apiKey.Length > 0)
|
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())
|
using (HttpClient client = new HttpClient())
|
||||||
{
|
{
|
||||||
@ -172,12 +170,10 @@ namespace ManagerService.Controllers
|
|||||||
callResponse.EnsureSuccessStatusCode();
|
callResponse.EnsureSuccessStatusCode();
|
||||||
string callResponseBody = await callResponse.Content.ReadAsStringAsync();
|
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();
|
_myInfoMateDbContext.SaveChanges();
|
||||||
//_sectionService.Update(weatherSection.Id, weatherSection);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -672,6 +672,21 @@ namespace ManagerService.Controllers
|
|||||||
if (section == null)
|
if (section == null)
|
||||||
throw new KeyNotFoundException("Section does not exist");
|
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);
|
_myInfoMateDbContext.Remove(section);
|
||||||
//_sectionService.Remove(id);
|
//_sectionService.Remove(id);
|
||||||
|
|
||||||
|
|||||||
@ -95,7 +95,7 @@ namespace ManagerService.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sectionId">Section Id</param>
|
/// <param name="sectionId">Section Id</param>
|
||||||
/// <param name="geoPointDTO">geoPoint</param>
|
/// <param name="geoPointDTO">geoPoint</param>
|
||||||
[ProducesResponseType(typeof(GeoPoint), 200)]
|
[ProducesResponseType(typeof(GeoPointDTO), 200)]
|
||||||
[ProducesResponseType(typeof(string), 400)]
|
[ProducesResponseType(typeof(string), 400)]
|
||||||
[ProducesResponseType(typeof(string), 409)]
|
[ProducesResponseType(typeof(string), 409)]
|
||||||
[ProducesResponseType(typeof(string), 500)]
|
[ProducesResponseType(typeof(string), 500)]
|
||||||
@ -138,7 +138,25 @@ namespace ManagerService.Controllers
|
|||||||
|
|
||||||
_myInfoMateDbContext.SaveChanges();
|
_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)
|
catch (ArgumentNullException ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -135,7 +135,7 @@ namespace ManagerService.Controllers
|
|||||||
/// Update a quiz question
|
/// Update a quiz question
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="updatedQuizQuestion">QuizQuestion to update</param>
|
/// <param name="updatedQuizQuestion">QuizQuestion to update</param>
|
||||||
[ProducesResponseType(typeof(QuizQuestion), 200)]
|
[ProducesResponseType(typeof(QuestionDTO), 200)]
|
||||||
[ProducesResponseType(typeof(string), 400)]
|
[ProducesResponseType(typeof(string), 400)]
|
||||||
[ProducesResponseType(typeof(string), 404)]
|
[ProducesResponseType(typeof(string), 404)]
|
||||||
[ProducesResponseType(typeof(string), 500)]
|
[ProducesResponseType(typeof(string), 500)]
|
||||||
@ -158,7 +158,7 @@ namespace ManagerService.Controllers
|
|||||||
|
|
||||||
_myInfoMateDbContext.SaveChanges();
|
_myInfoMateDbContext.SaveChanges();
|
||||||
|
|
||||||
return new OkObjectResult(existingQuestion);
|
return new OkObjectResult(questionDTO);
|
||||||
}
|
}
|
||||||
catch (ArgumentNullException ex)
|
catch (ArgumentNullException ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -7,7 +7,7 @@ namespace Manager.DTOs
|
|||||||
{
|
{
|
||||||
public List<TranslationAndResourceDTO> messageDebut { get; set; }
|
public List<TranslationAndResourceDTO> messageDebut { get; set; }
|
||||||
public List<TranslationAndResourceDTO> messageFin { 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 string puzzleImageId { get; set; } // But only image is possible
|
||||||
public int rows { get; set; } = 3;
|
public int rows { get; set; } = 3;
|
||||||
public int cols { get; set; } = 3;
|
public int cols { get; set; } = 3;
|
||||||
|
|||||||
@ -20,7 +20,7 @@ namespace ManagerService.Data.SubSection
|
|||||||
|
|
||||||
public string ResourceId { get; set; }
|
public string ResourceId { get; set; }
|
||||||
|
|
||||||
public Resource Resource { get; set; }
|
public Resource? Resource { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public TranslationAndResourceDTO ToDTO()
|
public TranslationAndResourceDTO ToDTO()
|
||||||
@ -30,7 +30,7 @@ namespace ManagerService.Data.SubSection
|
|||||||
language = Language,
|
language = Language,
|
||||||
value = Value,
|
value = Value,
|
||||||
resourceId = ResourceId,
|
resourceId = ResourceId,
|
||||||
resource = Resource.ToDTO()
|
resource = Resource?.ToDTO()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user