add architecture skeleton
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
namespace GymLogAI.API.Contracts;
|
||||
|
||||
public sealed record ImportTelegramMessageRequest(
|
||||
Guid UserId,
|
||||
long TelegramUserId,
|
||||
long TelegramChatId,
|
||||
int TelegramMessageId,
|
||||
string Text,
|
||||
DateTime SentAtUtc,
|
||||
string? Username,
|
||||
string? FirstName,
|
||||
string? LastName);
|
||||
|
||||
public sealed record ImportTelegramMessageResponse(Guid MessageId);
|
||||
@@ -0,0 +1,8 @@
|
||||
using GymLogAI.Core.Enums;
|
||||
|
||||
namespace GymLogAI.API.Contracts;
|
||||
|
||||
public sealed record RecommendWorkoutRequest(
|
||||
Guid UserId,
|
||||
GoalType GoalType,
|
||||
string? AdditionalContext);
|
||||
@@ -0,0 +1,23 @@
|
||||
namespace GymLogAI.API.Contracts;
|
||||
|
||||
public sealed record WorkoutHistoryItemResponse(
|
||||
Guid Id,
|
||||
DateTime PerformedAtUtc,
|
||||
string? Title,
|
||||
string? Notes,
|
||||
IReadOnlyCollection<WorkoutHistoryExerciseResponse> Exercises);
|
||||
|
||||
public sealed record WorkoutHistoryExerciseResponse(
|
||||
Guid ExerciseId,
|
||||
string Name,
|
||||
int Order,
|
||||
string? Notes,
|
||||
IReadOnlyCollection<WorkoutHistorySetResponse> Sets);
|
||||
|
||||
public sealed record WorkoutHistorySetResponse(
|
||||
int Order,
|
||||
int? Repetitions,
|
||||
decimal? WeightKg,
|
||||
int? DurationSeconds,
|
||||
decimal? DistanceMeters,
|
||||
string? Notes);
|
||||
@@ -8,6 +8,10 @@ FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
WORKDIR /src
|
||||
COPY ["GymLogAI.API/GymLogAI.API.csproj", "GymLogAI.API/"]
|
||||
COPY ["GymLogAI.Application/GymLogAI.Application.csproj", "GymLogAI.Application/"]
|
||||
COPY ["GymLogAI.AI/GymLogAI.AI.csproj", "GymLogAI.AI/"]
|
||||
COPY ["GymLogAI.Core/GymLogAI.Core.csproj", "GymLogAI.Core/"]
|
||||
COPY ["GymLogAI.Persistence/GymLogAI.Persistence.csproj", "GymLogAI.Persistence/"]
|
||||
RUN dotnet restore "GymLogAI.API/GymLogAI.API.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/GymLogAI.API"
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.6" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="10.1.7" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -18,7 +19,10 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\GymLogAI.TgBot\GymLogAI.TgBot.csproj" />
|
||||
<ProjectReference Include="..\GymLogAI.Application\GymLogAI.Application.csproj" />
|
||||
<ProjectReference Include="..\GymLogAI.AI\GymLogAI.AI.csproj" />
|
||||
<ProjectReference Include="..\GymLogAI.Core\GymLogAI.Core.csproj" />
|
||||
<ProjectReference Include="..\GymLogAI.Persistence\GymLogAI.Persistence.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
+94
-25
@@ -1,51 +1,120 @@
|
||||
using GymLogAI.TgBot;
|
||||
using GymLogAI.AI;
|
||||
using GymLogAI.API.Contracts;
|
||||
using GymLogAI.Application.Handlers;
|
||||
using GymLogAI.Application.Interfaces;
|
||||
using GymLogAI.Persistence;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace GymLogAI.API;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddProblemDetails();
|
||||
builder.Services.AddAuthorization();
|
||||
builder.Services.AddTgBot(builder.Configuration);
|
||||
|
||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||
builder.Services.AddOpenApi();
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
builder.Services.AddPersistence(builder.Configuration);
|
||||
builder.Services.AddAiServices(builder.Configuration);
|
||||
builder.Services.AddScoped<ImportTelegramMessageHandler>();
|
||||
builder.Services.AddScoped<ParseTelegramMessageHandler>();
|
||||
builder.Services.AddScoped<RecommendWorkoutHandler>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
await using (var scope = app.Services.CreateAsyncScope())
|
||||
{
|
||||
var dbContext = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
await dbContext.Database.MigrateAsync();
|
||||
}
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.MapOpenApi();
|
||||
}
|
||||
|
||||
app.UseExceptionHandler();
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
var summaries = new[]
|
||||
{
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
};
|
||||
var api = app.MapGroup("/api");
|
||||
|
||||
app.MapGet("/weatherforecast", (HttpContext httpContext) =>
|
||||
api.MapPost("/messages/import", async (
|
||||
ImportTelegramMessageRequest request,
|
||||
ImportTelegramMessageHandler handler,
|
||||
CancellationToken cancellationToken) =>
|
||||
{
|
||||
var forecast = Enumerable.Range(1, 5).Select(index =>
|
||||
new WeatherForecast
|
||||
{
|
||||
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
||||
TemperatureC = Random.Shared.Next(-20, 55),
|
||||
Summary = summaries[Random.Shared.Next(summaries.Length)]
|
||||
})
|
||||
.ToArray();
|
||||
return forecast;
|
||||
})
|
||||
.WithName("GetWeatherForecast");
|
||||
var id = await handler.HandleAsync(
|
||||
new ImportTelegramMessageCommand(
|
||||
request.UserId,
|
||||
request.TelegramUserId,
|
||||
request.TelegramChatId,
|
||||
request.TelegramMessageId,
|
||||
request.Text,
|
||||
request.SentAtUtc,
|
||||
request.Username,
|
||||
request.FirstName,
|
||||
request.LastName),
|
||||
cancellationToken);
|
||||
|
||||
app.Run();
|
||||
return TypedResults.Accepted($"/api/messages/{id}", new ImportTelegramMessageResponse(id));
|
||||
})
|
||||
.WithName("ImportTelegramMessage");
|
||||
|
||||
api.MapPost("/workouts/recommend", async (
|
||||
RecommendWorkoutRequest request,
|
||||
RecommendWorkoutHandler handler,
|
||||
CancellationToken cancellationToken) =>
|
||||
{
|
||||
var result = await handler.HandleAsync(
|
||||
new RecommendWorkoutCommand(request.UserId, request.GoalType, request.AdditionalContext),
|
||||
cancellationToken);
|
||||
|
||||
return TypedResults.Ok(result);
|
||||
})
|
||||
.WithName("RecommendWorkout");
|
||||
|
||||
api.MapGet("/workouts/history", async (
|
||||
Guid userId,
|
||||
IWorkoutRepository workoutRepository,
|
||||
CancellationToken cancellationToken) =>
|
||||
{
|
||||
var history = await workoutRepository.GetHistoryAsync(userId, cancellationToken);
|
||||
|
||||
var response = history.Select(workout => new WorkoutHistoryItemResponse(
|
||||
workout.Id,
|
||||
workout.PerformedAtUtc,
|
||||
workout.Title,
|
||||
workout.Notes,
|
||||
workout.WorkoutExercises
|
||||
.OrderBy(x => x.Order)
|
||||
.Select(x => new WorkoutHistoryExerciseResponse(
|
||||
x.ExerciseId,
|
||||
x.Exercise?.Name ?? "Unknown exercise",
|
||||
x.Order,
|
||||
x.Notes,
|
||||
x.Sets.OrderBy(s => s.Order)
|
||||
.Select(s => new WorkoutHistorySetResponse(
|
||||
s.Order,
|
||||
s.Repetitions,
|
||||
s.WeightKg,
|
||||
s.DurationSeconds,
|
||||
s.DistanceMeters,
|
||||
s.Notes))
|
||||
.ToArray()))
|
||||
.ToArray()))
|
||||
.ToArray();
|
||||
|
||||
return TypedResults.Ok(response);
|
||||
})
|
||||
.WithName("GetWorkoutHistory");
|
||||
|
||||
await app.RunAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
namespace GymLogAI.API;
|
||||
|
||||
public class WeatherForecast
|
||||
{
|
||||
public DateOnly Date { get; set; }
|
||||
|
||||
public int TemperatureC { get; set; }
|
||||
|
||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||
|
||||
public string? Summary { get; set; }
|
||||
}
|
||||
@@ -5,7 +5,13 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"TelegramBot": {
|
||||
"BotToken": ""
|
||||
"ConnectionStrings": {
|
||||
"Postgres": "Host=localhost;Port=5432;Database=gymlogai;Username=postgres;Password=postgres"
|
||||
},
|
||||
"OpenRouter": {
|
||||
"BaseUrl": "https://openrouter.ai/api/v1/",
|
||||
"ApiKey": "",
|
||||
"ChatModel": "openai/gpt-4.1-mini",
|
||||
"EmbeddingModel": "text-embedding-3-small"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,14 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"TelegramBot": {
|
||||
"BotToken": ""
|
||||
"ConnectionStrings": {
|
||||
"Postgres": "Host=localhost;Port=5432;Database=gymlogai;Username=postgres;Password=postgres"
|
||||
},
|
||||
"OpenRouter": {
|
||||
"BaseUrl": "https://openrouter.ai/api/v1/",
|
||||
"ApiKey": "",
|
||||
"ChatModel": "openai/gpt-4.1-mini",
|
||||
"EmbeddingModel": "text-embedding-3-small"
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user