Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
4c2aaec
Merge pull request #1 from wer3454/dev1
wer3454 Apr 23, 2025
d9a0d52
Add migrations
wer3454 Apr 23, 2025
f12b699
Rename Db Context
wer3454 Apr 23, 2025
582a882
Fix Team Repository to include team members
wer3454 Apr 23, 2025
5d73235
Make General Repository async
wer3454 Apr 23, 2025
33c99d7
Add Update to Team Service
wer3454 Apr 23, 2025
9d56364
Add User Controller
wer3454 Apr 23, 2025
9bde8f6
Add mapper config
wer3454 Apr 23, 2025
b03a7cd
Update Properties
wer3454 Apr 23, 2025
35d89b6
Add for debug
wer3454 Apr 23, 2025
840b493
Add docker compose
wer3454 Apr 23, 2025
a4aeb6a
Merge dev1 to dev
wer3454 Apr 23, 2025
7dce081
Fix log service in User Controller
wer3454 Apr 23, 2025
ae5a032
Fix GenericRepository
wer3454 Apr 24, 2025
8e03f38
Add Update to Team Controller
wer3454 Apr 24, 2025
1678df6
Fix Program
wer3454 Apr 24, 2025
04bc5f9
Update Team to return dto
wer3454 Apr 26, 2025
4d6ef4a
Update UserMainEntity
wer3454 Apr 26, 2025
a6c37c6
Fix UserRepository and add UserInfoDto
wer3454 Apr 26, 2025
d58a362
Change Logic
wer3454 Apr 26, 2025
d346949
Add DTO
wer3454 Apr 26, 2025
e8c4a55
Add cancelationtoken for HackathonRepository
wer3454 Apr 27, 2025
20852a5
Fix Entities
wer3454 Apr 27, 2025
39a91cd
Fix HackathonFilter Dto
wer3454 Apr 27, 2025
924b0ff
Add new migrations
wer3454 Apr 27, 2025
977f8b4
Update Dto
wer3454 Apr 27, 2025
8d318b3
Update Entity with migration
wer3454 Apr 27, 2025
b2fbad5
Fix TeamRepository access and add getTeamByHackathon
wer3454 Apr 27, 2025
e5336ca
Rework teamController to send new Dto
wer3454 Apr 27, 2025
caded37
Add TagRepository for teamService
wer3454 Apr 27, 2025
5358603
Add automapper for new teamDto
wer3454 Apr 27, 2025
4ac819c
Fix not implemented controller to send nothing
wer3454 Apr 27, 2025
7b506c7
Merge pull request #4 from wer3454/master
wer3454 Apr 27, 2025
65edb4c
Update dotnet-desktop.yml
wer3454 Apr 27, 2025
499ef83
Update dotnet-desktop.yml
wer3454 Apr 27, 2025
0b8da26
Important! Change controller route
BelugaChan Apr 28, 2025
f599146
Update class libs
BelugaChan Apr 28, 2025
5b2258b
Provide new property
BelugaChan Apr 28, 2025
0b42806
Add new prop username
BelugaChan Apr 28, 2025
91e2032
Add new prop email
BelugaChan Apr 28, 2025
ee39f6f
Minor fixes
BelugaChan Apr 28, 2025
5485d65
add new prop (Email)
BelugaChan Apr 28, 2025
ba5e2c9
Add email to UserEntity
wer3454 Apr 28, 2025
aaca34e
Add tagRepository method for user and hackathon
wer3454 Apr 28, 2025
8194a4c
Rework TeamController and add GetTeamForHackathon
wer3454 Apr 28, 2025
0b6b348
Rework TeamController
wer3454 Apr 28, 2025
fd840f3
Add UserController
wer3454 Apr 28, 2025
88755e0
Merge branch 'wip/connect' of https://github.com/wer3454/MethodTeams …
wer3454 Apr 28, 2025
794f39a
Merge dev1 branch
wer3454 Apr 28, 2025
e7260c6
Minor fixes
BelugaChan Apr 29, 2025
03474fc
Change controller routing path
BelugaChan Apr 29, 2025
c592e57
Add new folders to ignore
BelugaChan Apr 29, 2025
13d61bc
Minor fixes
BelugaChan Apr 29, 2025
b3c882a
Merge stuff
BelugaChan Apr 29, 2025
f18f9f4
Fix message content in log props
BelugaChan Apr 30, 2025
29072f7
Specify route attribute for id in GetUserById method and fix log mess…
BelugaChan Apr 30, 2025
9f1a942
Add new config to specify cross origin resource sharing
BelugaChan Apr 30, 2025
779e36a
Add config for console logging using serilog
BelugaChan Apr 30, 2025
daac19b
Add new nuget packages (serilog)
BelugaChan Apr 30, 2025
7bfe7b7
New Folder section in ItemGroup
BelugaChan Apr 30, 2025
0b05343
Add an attribute to enable cors
BelugaChan Apr 30, 2025
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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,8 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd

docker-compose/

postgres-data/
324 changes: 120 additions & 204 deletions MethodologyMain.API/Controllers/TeamController.cs

Large diffs are not rendered by default.

83 changes: 83 additions & 0 deletions MethodologyMain.API/Controllers/UserController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using MethodologyMain.Application.DTO;
using Microsoft.AspNetCore.Mvc;
using MethodologyMain.Application.Interface;
using AuthMetodology.Infrastructure.Models;
using Serilog.Events;
using RabbitMqPublisher.Interface;
using Microsoft.AspNetCore.Cors;

namespace MethodologyMain.API.Controllers
{
[ApiController]
[EnableCors("AllowFrontend")]
[Route("api/main/[controller]")]
public class UserController : ControllerBase
{
private readonly IUserService userService;
private readonly IRabbitMqPublisherBase<RabbitMqLogPublish> logPublishService;
public UserController(IUserService userService, IRabbitMqPublisherBase<RabbitMqLogPublish> logPublishService)
{
this.userService = userService;
this.logPublishService = logPublishService;
}

[HttpGet]
public async Task<ActionResult<List<GetUserDto>>> GetUsers(CancellationToken token)
{
_ = logPublishService.SendEventAsync(new RabbitMqLogPublish
{
ServiceName = "Main service",
LogLevel = LogEventLevel.Information,
Message = "GET api/main/User was called",
TimeStamp = DateTime.UtcNow
});
var users = await userService.GetUsersAllAsync(token);
//var team = await teamService.CreateTeamAsync(dto.Name, dto.Description, currentUserId, dto.EventId, token);
return Ok(users);
}

[HttpGet("{id}")]
public async Task<ActionResult<GetUserDto>> GetUsersById([FromRoute] Guid id, CancellationToken token)
{
_ = logPublishService.SendEventAsync(new RabbitMqLogPublish
{
ServiceName = "Main service",
LogLevel = LogEventLevel.Information,
Message = "GET api/main/User was called",
TimeStamp = DateTime.UtcNow
});
var user = await userService.GetUserByIdAsync(id, token);
//var team = await teamService.CreateTeamAsync(dto.Name, dto.Description, currentUserId, dto.EventId, token);
return Ok(user);
}
[HttpPost]
public async Task<ActionResult<GetUserDto>> CreateUser([FromBody] GetUserDto dto, CancellationToken token)
{
_ = logPublishService.SendEventAsync(new RabbitMqLogPublish
{
ServiceName = "Main service",
LogLevel = LogEventLevel.Information,
Message = "POST api/main/User was called",
TimeStamp = DateTime.UtcNow
});
var user = await userService.CreateUserAsync(dto, token);
//var team = await teamService.CreateTeamAsync(dto.Name, dto.Description, currentUserId, dto.EventId, token);
return Ok(user);
}

[HttpPut]
public async Task<ActionResult> UpdateUser([FromBody] GetUserDto dto, CancellationToken token)
{
_ = logPublishService.SendEventAsync(new RabbitMqLogPublish
{
ServiceName = "Main service",
LogLevel = LogEventLevel.Information,
Message = "PUT api/main/User was called",
TimeStamp = DateTime.UtcNow
});
await userService.UpdateUserAsync(dto, token);
//var team = await teamService.CreateTeamAsync(dto.Name, dto.Description, currentUserId, dto.EventId, token);
return Ok();
}
}
}
30 changes: 30 additions & 0 deletions MethodologyMain.API/Dockerfile.original
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# См. статью по ссылке https://aka.ms/customizecontainer, чтобы узнать как настроить контейнер отладки и как Visual Studio использует этот Dockerfile для создания образов для ускорения отладки.

# Этот этап используется при запуске из VS в быстром режиме (по умолчанию для конфигурации отладки)
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER $APP_UID
WORKDIR /app
EXPOSE 8080
EXPOSE 8081


# Этот этап используется для сборки проекта службы
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["MethodTeams1/MethodTeams1.csproj", "MethodTeams1/"]
RUN dotnet restore "./MethodTeams1/MethodTeams1.csproj"
COPY . .
WORKDIR "/src/MethodTeams1"
RUN dotnet build "./MethodTeams1.csproj" -c $BUILD_CONFIGURATION -o /app/build

# Этот этап используется для публикации проекта службы, который будет скопирован на последний этап
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./MethodTeams1.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

# Этот этап используется в рабочей среде или при запуске из VS в обычном режиме (по умолчанию, когда конфигурация отладки не используется)
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MethodTeams1.dll"]
11 changes: 11 additions & 0 deletions MethodologyMain.API/Extensions/AuthExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ public static void AddApiAuthentication(
}
};
});
services.AddCors(options =>
{
options.AddPolicy("AllowFrontend", builder =>
{
builder.WithOrigins("http://localhost:8083")
.AllowCredentials()
.AllowAnyHeader()
.AllowAnyMethod()
.WithExposedHeaders("Set-Cookie");
});
});
services.AddAuthorizationBuilder()
//.AddPolicy("AdminOnly", policy => policy.RequireRole(nameof(UserRole.Admin)))
.AddPolicy("BearerOnly", policy => { policy.AuthenticationSchemes.Add(JwtBearerDefaults.AuthenticationScheme); policy.RequireAuthenticatedUser(); });
Expand Down
2 changes: 2 additions & 0 deletions MethodologyMain.API/MethodologyMain.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.11" />
<PackageReference Include="Serilog" Version="4.2.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.0" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion MethodologyMain.API/Middleware/ExceptionMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task InvokeAsync(HttpContext context)
{
ServiceName = "Main service",
LogLevel = LogEventLevel.Error,
Message = $"Exception was thrown.\nMessage: {ex.Message}\nSource: {ex.Source}",
Message = $"Exception was thrown.\nMessage: {ex.Message}, {ex.InnerException}\nSource: {ex.Source}",
TimeStamp = DateTime.UtcNow
});

Expand Down
26 changes: 25 additions & 1 deletion MethodologyMain.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using MethodologyMain.Infrastructure.Services;
using MethodologyMain.Persistence.Interfaces;
using MethodologyMain.Persistence.Repository;
using MethodTeams.DTO;
using System.Reflection;
using MethodologyMain.Application.Profiles;
using Microsoft.EntityFrameworkCore;
Expand All @@ -20,9 +19,19 @@
using Microsoft.Extensions.Options;
using RabbitMqListener.Interfaces;
using MethodologyMain.Infrastructure.Listeners;
using MethodologyMain.Application.DTO;
using MethodologyMain.Logic.Entities;
using Serilog;

var builder = WebApplication.CreateBuilder(args);

var logger = new LoggerConfiguration()
.WriteTo.Console()
.CreateLogger();

builder.Logging.ClearProviders();
builder.Logging.AddSerilog(logger);

builder.Services.AddControllers();
builder.Services.AddControllers()
.AddJsonOptions(options =>
Expand All @@ -35,10 +44,21 @@
var configuration = new MapperConfiguration(static cfg =>
{
cfg.AddMaps(Assembly.GetExecutingAssembly());
cfg.CreateMap<TeamEntity, GetTeamDto>()
.ForMember(dto => dto.CreatedBy, conf => conf.MapFrom(t => t.CaptainId))
.ForMember(dto => dto.Members, conf => conf.MapFrom(t => t.Members.Select(s => s.User.UserName).ToList()))
.ForMember(dto => dto.Tags, conf => conf.MapFrom(t => t.Tags.Select(s => s.Tag.TagName).ToList()))
.ForMember(dto => dto.CreatedAt, conf => conf.MapFrom(t => t.TeamCreatedAt));
cfg.CreateMap<UserMainEntity, GetUserDto>()
.ForMember(dto => dto.Tags, conf => conf.MapFrom(t => t.Tags.Select(s => s.Tag.TagName).ToList()))
.ForMember(dto => dto.Name, conf => conf.MapFrom(t => t.UserName))
.ForMember(dto => dto.Bio, conf => conf.MapFrom(t => t.Education));

cfg.AllowNullCollections = true;
cfg.AddGlobalIgnore("Item");
}
);
configuration.AssertConfigurationIsValid();
IMapper mapper = configuration.CreateMapper();
builder.Services.AddSingleton(mapper);

Expand All @@ -48,9 +68,12 @@
builder.Services.AddApiAuthentication(builder.Services.BuildServiceProvider().GetRequiredService<IOptions<JWTOptions>>());

builder.Services.AddScoped<ITeamService, TeamService>();
builder.Services.AddScoped<IUserService, UserService>();
builder.Services.AddAutoMapper(typeof(TeamProfile).Assembly, typeof(TeamInfoDto).Assembly);
builder.Services.AddScoped<ITagRepository, TagRepository>();
builder.Services.AddScoped<ITeamRepository, TeamRepository>();
builder.Services.AddScoped<IUserRepository, UserRepository>();
builder.Services.AddScoped<IHackathonRepository, HackathonRepository>();
builder.Services.AddScoped<ITeamValidationService, TeamValidationService>();
builder.Services.AddSingleton<IRabbitMqPublisherBase<RabbitMqLogPublish>, LogQueueService>();

Expand All @@ -70,6 +93,7 @@

app.UseHttpsRedirection();

app.UseCors("AllowFrontend");
app.UseAuthorization();
app.UseAuthentication();

Expand Down
20 changes: 19 additions & 1 deletion MethodologyMain.API/Properties/serviceDependencies.local.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
{
"dependencies": {}
"dependencies": {
"rabbitmq1": {
"containerPorts": "5672:5672,15672:15672",
"secretStore": "LocalSecretsFile",
"containerName": "rabbitmq",
"containerImage": "rabbitmq:3-management-alpine",
"type": "rabbitmq.container",
"connectionId": "QueueConnection"
},
"postgresql1": {
"containerPorts": "5432:5432",
"secretStore": "LocalSecretsFile",
"containerName": "postgresql",
"containerImage": "postgres",
"resourceId": null,
"type": "postgresql.container",
"connectionId": "ConnectionStrings:DatabaseConnection"
}
}
}
8 changes: 6 additions & 2 deletions MethodologyMain.Application/DTO/CreateTeamDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
{
public class CreateTeamDto
{
public Guid HackathonId { get; set; }
public required string Name { get; set; }
public required string Description { get; set; }
public Guid EventId { get; set; }
public string Description { get; set; } = string.Empty;
public List<string> Tags { get; set; } = null!;
public List<string> Members { get; set; } = null!;
public required int MaxMembers { get; set; }
public Guid CreatedBy { get; set; }
}
}
23 changes: 23 additions & 0 deletions MethodologyMain.Application/DTO/GetHackathonDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using MethodologyMain.Logic.Models;

namespace MethodologyMain.Application.DTO
{
public class GetHackathonDto
{
public Guid Id { get; set; }
public required string Name { get; set; }
public string Description { get; set; } = string.Empty;
public required DateOnly StartDate { get; set; }
public required DateOnly EndDate { get; set; }
public string Location { get; set; } = string.Empty;
public List<string> Tags { get; set; } = null!;
public string ImageUrl { get; set; } = string.Empty;
public string OrganizerName { get; set; } = string.Empty;
public string OrganizerLogo { get; set; } = string.Empty;
public TeamSize TeamSize { get; set; } = null!;
public string Website { get; set; } = string.Empty;
public List<Prize> Prizes { get; set; } = null!;
public List<ScheduleItem> Schedule { get; set; } = null!;

}
}
15 changes: 15 additions & 0 deletions MethodologyMain.Application/DTO/GetTeamDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace MethodologyMain.Application.DTO
{
public class GetTeamDto
{
public Guid Id { get; set; }
public Guid HackathonId { get; set; }
public required string Name { get; set; }
public string Description { get; set; } = string.Empty;
public List<string> Tags { get; set; } = null!;
public List<string> Members { get; set; } = null!;
public int MaxMembers { get; set; }
public Guid CreatedBy { get; set; }
public DateTime CreatedAt { get; set; }
}
}
19 changes: 19 additions & 0 deletions MethodologyMain.Application/DTO/GetUserDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@


namespace MethodologyMain.Application.DTO
{
public class GetUserDto
{
public Guid Id { get; set; }
public required string Name { get; set; }
public string Email { get; set; } = string.Empty;
public string Bio { get; set; } = string.Empty;
public List<string> Tags { get; set; } = null!;
public string PhotoUrl { get; set; } = string.Empty;
public DateTime CreatedAt { get; set; }
public string Location { get; set; } = string.Empty;
public string Github { get; set; } = string.Empty;
public string Website { get; set; } = string.Empty;
public string Skills { get; set; } = string.Empty;
}
}
4 changes: 2 additions & 2 deletions MethodologyMain.Application/DTO/HackathonFilterDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public class HackathonFilterDto

public int? MaxTeamSize { get; set; }

public DateTime? StartDateFrom { get; set; }
public DateOnly? StartDateFrom { get; set; }

public DateTime? StartDateTo { get; set; }
public DateOnly? StartDateTo { get; set; }
public int Page { get; set; } = 1;
public int PageSize { get; set; } = 10;
}
Expand Down
4 changes: 2 additions & 2 deletions MethodologyMain.Application/DTO/TeamInfoDto.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
namespace MethodTeams.DTO
namespace MethodologyMain.Application.DTO
{

// DTO для информации о команде
public class TeamInfoDto
{
public Guid Id { get; set; }
public string Name { get; set; }
public required string Name { get; set; }
public string? Description { get; set; }
public Guid CaptainId { get; set; }
public Guid HackathonId { get; set; }
Expand Down
10 changes: 10 additions & 0 deletions MethodologyMain.Application/DTO/UpdateTeamDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace MethodologyMain.Application.DTO
{
public class UpdateTeamDto
{
public Guid Id { get; set; }
public string? Name { get; set; }
public string? Description { get; set; }
public Guid? HackathonId { get; set; }
}
}
17 changes: 17 additions & 0 deletions MethodologyMain.Application/DTO/UserInfoDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using MethodologyMain.Logic.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MethodologyMain.Application.DTO
{
public class UserInfoDto
{
public Guid Id { get; set; }
public required string UserName { get; set; }
public string? Education { get; set; }
public List<UserTagEntity>? Tags { get; set; }
}
}
Loading
Loading