Kitty
Kitty
CC#
Created by Kitty on 5/13/2023 in #help
❔ Swagger does not generate schemas
C#
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> Get(double latitude, double longitude)
{
// Create a HttpClient instance
var client = _clientFactory.CreateClient();

// Make a GET request to the external API
var response = await client.GetAsync($"https://api.open-meteo.com/v1/forecast?latitude={latitude}&longitude={longitude}&current_weather=true");

// If the request is successful
if (response.IsSuccessStatusCode)
{
// Read the response content as a JSON string
var json = await response.Content.ReadAsStringAsync();

// Deserialize the JSON string into a WeatherForecastClass object
var weatherForecast = JsonSerializer.Deserialize<WeatherForecastClass>(json);

// Return the weather forecast with a 200 OK status
return Ok(weatherForecast);
}

// If the request is not successful, log an error and return the status code from the external API
_logger.LogError("Failed to retrieve weather forecast. Status Code: {ResponseStatusCode}", response.StatusCode);
return StatusCode((int)response.StatusCode);
}
}
C#
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> Get(double latitude, double longitude)
{
// Create a HttpClient instance
var client = _clientFactory.CreateClient();

// Make a GET request to the external API
var response = await client.GetAsync($"https://api.open-meteo.com/v1/forecast?latitude={latitude}&longitude={longitude}&current_weather=true");

// If the request is successful
if (response.IsSuccessStatusCode)
{
// Read the response content as a JSON string
var json = await response.Content.ReadAsStringAsync();

// Deserialize the JSON string into a WeatherForecastClass object
var weatherForecast = JsonSerializer.Deserialize<WeatherForecastClass>(json);

// Return the weather forecast with a 200 OK status
return Ok(weatherForecast);
}

// If the request is not successful, log an error and return the status code from the external API
_logger.LogError("Failed to retrieve weather forecast. Status Code: {ResponseStatusCode}", response.StatusCode);
return StatusCode((int)response.StatusCode);
}
}
Swagger does not generate schema for WeatherForecastClass
4 replies
CC#
Created by Kitty on 3/9/2023 in #help
❔ PostgresSQL how to do couple hundred inserts per second
Hi, I am currently working on a mqtt->DB project for the first time. I am having problems with the DB part as the way I am currently doing it I quickly run out of connection slots (to the DB, using Npgsql), I thought of doing a buffer but the messages have to be in the database more or less in the same second.
10 replies