target command & weather api

This commit is contained in:
rafi1212122
2023-05-31 16:33:25 +07:00
parent 3778da626c
commit ca4413c9ce
7 changed files with 102 additions and 2 deletions

View File

@@ -58,6 +58,30 @@ namespace HttpServer.Controllers
}
});
});
app.Map("/game_weather/weather/get_weather", (HttpContext ctx) =>
{
Weather weatherData = new()
{
Retcode = 0,
Message = "OK",
Data = new()
{
Timezone = 8,
Hourly = new()
}
};
Random random = new();
for (int i = 0; i < 24; i++)
{
DateTime time = DateTime.Now.Add(TimeSpan.FromHours(1) * i);
weatherData.Data.Hourly.Add(new() { Condition = 1, Date = time.ToString("yyyy-MM-dd"), Hour = time.Hour, Temp = random.Next(20, 30) });
}
ctx.Response.Headers.Add("Content-Type", "application/json");
return ctx.Response.WriteAsync(JsonConvert.SerializeObject(weatherData));
});
app.Map("/bh3_os/mdk/shield/api/loadConfig", (HttpContext ctx) =>
{

View File

@@ -20,5 +20,42 @@ namespace HttpServer.Models
[JsonProperty("minimum")]
public string Minimum { get; set; }
}
public partial class Weather
{
[JsonProperty("retcode")]
public int Retcode { get; set; }
[JsonProperty("message")]
public string Message { get; set; }
[JsonProperty("data")]
public WeatherData Data { get; set; }
}
public partial class WeatherData
{
[JsonProperty("timezone")]
public int Timezone { get; set; }
[JsonProperty("hourly")]
public List<HourlyData> Hourly { get; set; }
public partial class HourlyData
{
[JsonProperty("condition")]
public long Condition { get; set; }
[JsonProperty("hour")]
public long Hour { get; set; }
[JsonProperty("date")]
public string Date { get; set; }
[JsonProperty("temp")]
public long Temp { get; set; }
}
}
}
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.