diff --git a/FinancialTracker.API.sln.DotSettings.user b/FinancialTracker.API.sln.DotSettings.user
index 642f398..e1c0ea2 100644
--- a/FinancialTracker.API.sln.DotSettings.user
+++ b/FinancialTracker.API.sln.DotSettings.user
@@ -1,4 +1,5 @@
+ ForceIncluded
<SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
<Solution />
</SessionState>
\ No newline at end of file
diff --git a/FinancialTracker/Data/Entities/Transaction.cs b/FinancialTracker/Data/Entities/Transaction.cs
index 69e9b64..69615ea 100644
--- a/FinancialTracker/Data/Entities/Transaction.cs
+++ b/FinancialTracker/Data/Entities/Transaction.cs
@@ -8,9 +8,9 @@ public class Transaction
public required string Description { get; set; }
[Column(TypeName = "decimal(18,2)")]
- public decimal Amount { get; set; }
+ public required decimal Amount { get; set; }
public DateTime Date { get; set; } = DateTime.UtcNow;
- public int CategoryId { get; set; }
+ public required int CategoryId { get; set; }
public Category Category { get; set; } = null!;
}
\ No newline at end of file
diff --git a/FinancialTracker/FinancialTracker.csproj b/FinancialTracker/FinancialTracker.csproj
index 3e830d5..ca3bed5 100644
--- a/FinancialTracker/FinancialTracker.csproj
+++ b/FinancialTracker/FinancialTracker.csproj
@@ -11,6 +11,7 @@
+
diff --git a/FinancialTracker/Program.cs b/FinancialTracker/Program.cs
index 49dafdf..d5687b6 100644
--- a/FinancialTracker/Program.cs
+++ b/FinancialTracker/Program.cs
@@ -3,6 +3,7 @@
using FinancialTracker.Interfaces;
using FinancialTracker.Services;
using Microsoft.EntityFrameworkCore;
+using Microsoft.OpenApi.Models;
var builder = WebApplication.CreateBuilder(args);
@@ -15,6 +16,17 @@
builder.Services.AddDbContext(options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
+builder.Services.AddEndpointsApiExplorer();
+builder.Services.AddSwaggerGen(c =>
+{
+ c.SwaggerDoc("v1", new OpenApiInfo
+ {
+ Title = "Financial Tracker API",
+ Version = "v1",
+ Description = "API для управления личными финансами",
+ });
+});
+
var app = builder.Build();
using (var scope = app.Services.CreateScope())
@@ -23,6 +35,16 @@
dbContext.Database.Migrate();
}
+if (app.Environment.IsDevelopment())
+{
+ app.UseSwagger();
+ app.UseSwaggerUI(c =>
+ {
+ c.SwaggerEndpoint("/swagger/v1/swagger.json", "Financial Tracker API v1");
+ c.RoutePrefix = "swagger";
+ });
+}
+
app.UseRouting();
app.MapControllers();
diff --git a/FinancialTracker/Services/TransactionService.cs b/FinancialTracker/Services/TransactionService.cs
index 7254e7d..0196238 100644
--- a/FinancialTracker/Services/TransactionService.cs
+++ b/FinancialTracker/Services/TransactionService.cs
@@ -22,6 +22,11 @@ public async Task> GetAllAsync()
public async Task AddAsync(TransactionCreateDto createDto)
{
+ if (createDto.Amount <= 0)
+ {
+ throw new InvalidOperationException("Сумма транзакции должна быть положительной");
+ }
+
var category = await categoryRepository.GetByIdAsync(createDto.CategoryId);
if (category == null)
{
@@ -42,6 +47,11 @@ public async Task AddAsync(TransactionCreateDto createDt
public async Task UpdateAsync(TransactionUpdateDto updateDto)
{
+ if (updateDto.Amount <= 0)
+ {
+ throw new InvalidOperationException("Сумма транзакции должна быть положительной");
+ }
+
var existingTransaction = await transactionRepository.GetByIdAsync(updateDto.Id);
if (existingTransaction == null)
return null;