From 0229793c8813798811ba2029144b565f90f18726 Mon Sep 17 00:00:00 2001 From: Thomas Fransolet Date: Thu, 15 May 2025 17:21:18 +0200 Subject: [PATCH] MISC --- .../Controllers/ConfigurationController.cs | 16 +++++--------- .../Controllers/SectionController.cs | 15 +++++++++++++ .../Controllers/SectionMapController.cs | 22 +++++++++++++++++-- .../Controllers/SectionQuizController.cs | 4 ++-- ManagerService/DTOs/SubSection/PuzzleDTO.cs | 2 +- .../Data/SubSection/TranslationAndResource.cs | 4 ++-- 6 files changed, 46 insertions(+), 17 deletions(-) diff --git a/ManagerService/Controllers/ConfigurationController.cs b/ManagerService/Controllers/ConfigurationController.cs index 4654b52..6d4e6d7 100644 --- a/ManagerService/Controllers/ConfigurationController.cs +++ b/ManagerService/Controllers/ConfigurationController.cs @@ -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() .Where(s => s.ConfigurationId == id && !s.IsSubSection) .ToList(); foreach (var weatherSection in weatherSections) { - WeatherDTO weatherDTO = weatherSection.ToDTO();//JsonConvert.DeserializeObject(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(); 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 { diff --git a/ManagerService/Controllers/SectionController.cs b/ManagerService/Controllers/SectionController.cs index bfbe297..3ffb6f1 100644 --- a/ManagerService/Controllers/SectionController.cs +++ b/ManagerService/Controllers/SectionController.cs @@ -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); diff --git a/ManagerService/Controllers/SectionMapController.cs b/ManagerService/Controllers/SectionMapController.cs index c876c7b..c326b08 100644 --- a/ManagerService/Controllers/SectionMapController.cs +++ b/ManagerService/Controllers/SectionMapController.cs @@ -95,7 +95,7 @@ namespace ManagerService.Controllers /// /// Section Id /// geoPoint - [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) { diff --git a/ManagerService/Controllers/SectionQuizController.cs b/ManagerService/Controllers/SectionQuizController.cs index d84c401..3209472 100644 --- a/ManagerService/Controllers/SectionQuizController.cs +++ b/ManagerService/Controllers/SectionQuizController.cs @@ -135,7 +135,7 @@ namespace ManagerService.Controllers /// Update a quiz question /// /// QuizQuestion to update - [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) { diff --git a/ManagerService/DTOs/SubSection/PuzzleDTO.cs b/ManagerService/DTOs/SubSection/PuzzleDTO.cs index 9c94ab9..fe6c8d0 100644 --- a/ManagerService/DTOs/SubSection/PuzzleDTO.cs +++ b/ManagerService/DTOs/SubSection/PuzzleDTO.cs @@ -7,7 +7,7 @@ namespace Manager.DTOs { public List messageDebut { get; set; } public List 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; diff --git a/ManagerService/Data/SubSection/TranslationAndResource.cs b/ManagerService/Data/SubSection/TranslationAndResource.cs index 4f14072..fed3086 100644 --- a/ManagerService/Data/SubSection/TranslationAndResource.cs +++ b/ManagerService/Data/SubSection/TranslationAndResource.cs @@ -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() }; }