Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions FinancialTracker.API.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AOpenApiInfo_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E2_003Fresharper_002Dhost_003FSourcesCache_003Ffcedb617b237dc31e998d31e01f101e8441948433938518c5f20cec1a845c1_003FOpenApiInfo_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=c3e35030_002D771d_002D4674_002D85e8_002D2b16dd384d0f/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
&lt;Solution /&gt;&#xD;
&lt;/SessionState&gt;</s:String></wpf:ResourceDictionary>
4 changes: 2 additions & 2 deletions FinancialTracker/Data/Entities/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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!;
}
1 change: 1 addition & 0 deletions FinancialTracker/FinancialTracker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.4" />
</ItemGroup>

<ItemGroup>
Expand Down
22 changes: 22 additions & 0 deletions FinancialTracker/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using FinancialTracker.Interfaces;
using FinancialTracker.Services;
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;

var builder = WebApplication.CreateBuilder(args);

Expand All @@ -15,6 +16,17 @@
builder.Services.AddDbContext<FinancialDbContext>(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())
Expand All @@ -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();

Expand Down
10 changes: 10 additions & 0 deletions FinancialTracker/Services/TransactionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public async Task<List<TransactionResponseDto>> GetAllAsync()

public async Task<TransactionResponseDto> AddAsync(TransactionCreateDto createDto)
{
if (createDto.Amount <= 0)
{
throw new InvalidOperationException("Сумма транзакции должна быть положительной");
}

var category = await categoryRepository.GetByIdAsync(createDto.CategoryId);
if (category == null)
{
Expand All @@ -42,6 +47,11 @@ public async Task<TransactionResponseDto> AddAsync(TransactionCreateDto createDt

public async Task<TransactionResponseDto?> UpdateAsync(TransactionUpdateDto updateDto)
{
if (updateDto.Amount <= 0)
{
throw new InvalidOperationException("Сумма транзакции должна быть положительной");
}

var existingTransaction = await transactionRepository.GetByIdAsync(updateDto.Id);
if (existingTransaction == null)
return null;
Expand Down