-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(Program): Code refractor and cleanup
- Loading branch information
1 parent
e07f837
commit 0871cb1
Showing
5 changed files
with
93 additions
and
57 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
src/Server/StellarChat.Server.Api/Endpoints/WeatherForecastEndpoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using StellarChat.Shared.Abstractions.API.Endpoints; | ||
|
||
namespace StellarChat.Server.Api.Endpoints; | ||
|
||
internal sealed class WeatherForecastEndpoint : IEndpoint | ||
{ | ||
record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary) | ||
{ | ||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); | ||
} | ||
|
||
public void Expose(IEndpointRouteBuilder endpoints) | ||
{ | ||
var summaries = new[] | ||
{ | ||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" | ||
|
||
}; | ||
|
||
endpoints.MapGet("/weatherforecast", (ILogger<WeatherForecast> logger) => | ||
{ | ||
logger.LogInformation("test logginig"); | ||
var forecast = Enumerable.Range(1, 5).Select(index => | ||
new WeatherForecast | ||
( | ||
DateOnly.FromDateTime(DateTime.Now.AddDays(index)), | ||
Random.Shared.Next(-20, 55), | ||
summaries[Random.Shared.Next(summaries.Length)] | ||
)) | ||
.ToArray(); | ||
return forecast; | ||
}) | ||
.WithName("GetWeatherForecast") | ||
.WithOpenApi(); | ||
} | ||
|
||
public void Register(IServiceCollection services, IConfiguration configuration) | ||
{ | ||
} | ||
|
||
public void Use(IApplicationBuilder app) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,11 @@ | ||
using StellarChat.Shared.Infrastructure.Exceptions; | ||
using StellarChat.Shared.Infrastructure.Contexts; | ||
using StellarChat.Shared.Infrastructure.Observability.Logging; | ||
using StellarChat.Shared.Infrastructure.DAL.Mongo; | ||
using StellarChat.Shared.Infrastructure.API.CORS; | ||
using StellarChat.Shared.Infrastructure.API.Endpoints; | ||
using StellarChat.Shared.Infrastructure; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Add services to the container. | ||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle | ||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(); | ||
builder.Services.AddErrorHandling(); | ||
builder.Services.AddContext(); | ||
builder.Services.AddCorsPolicy(builder.Configuration); | ||
builder.Host.UseLogging(); | ||
builder.Services.AddMongo(builder.Configuration); | ||
builder.Services.RegisterEndpoints(builder.Configuration); | ||
builder.AddSharedInfrastructure(); | ||
|
||
var app = builder.Build(); | ||
|
||
// Configure the HTTP request pipeline. | ||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
app.UseCorsPolicy(); | ||
app.UseErrorHandling(); | ||
app.UseContext(); | ||
app.UseLogging(); | ||
app.UseEndpoints(); | ||
app.MapEndpoints(); | ||
|
||
var summaries = new[] | ||
{ | ||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" | ||
}; | ||
|
||
app.MapGet("/weatherforecast", (ILogger<WeatherForecast> logger) => | ||
{ | ||
logger.LogInformation("test logginig"); | ||
var forecast = Enumerable.Range(1, 5).Select(index => | ||
new WeatherForecast | ||
( | ||
DateOnly.FromDateTime(DateTime.Now.AddDays(index)), | ||
Random.Shared.Next(-20, 55), | ||
summaries[Random.Shared.Next(summaries.Length)] | ||
)) | ||
.ToArray(); | ||
return forecast; | ||
}) | ||
.WithName("GetWeatherForecast") | ||
.WithOpenApi(); | ||
app.UseSharedInfrastructure(); | ||
|
||
app.Run(); | ||
|
||
record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary) | ||
{ | ||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters