mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
optimization sql
This commit is contained in:
@@ -52,13 +52,13 @@ public class InviteUserController : Controller
|
||||
_logger.LogInformation("Getting all active invitations by administrator");
|
||||
|
||||
var read = await _repository.GetAllAsync();
|
||||
var result = read.Where(x => x.IsActive == true).ToList();
|
||||
var result = read.Where(x => x.IsActive).ToList();
|
||||
|
||||
List<InvitationDto> dtos = new List<InvitationDto>();
|
||||
List<InvitationResponses> dtos = new List<InvitationResponses>();
|
||||
|
||||
foreach (var inv in result)
|
||||
{
|
||||
dtos.Add(new InvitationDto(){
|
||||
dtos.Add(new InvitationResponses(){
|
||||
Id = inv.Id,
|
||||
Description = inv.Description,
|
||||
IsAdmin = inv.IsAdmin,
|
||||
@@ -67,6 +67,7 @@ public class InviteUserController : Controller
|
||||
CreatedAt = inv.DateCreated,
|
||||
EndAt = inv.EndDate,
|
||||
IsActive = inv.IsActive,
|
||||
ParticipantCount = inv.Users.Count,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -87,11 +88,11 @@ public class InviteUserController : Controller
|
||||
_logger.LogInformation("Getting all invitations by administrator");
|
||||
var read = await _repository.GetAllAsync();
|
||||
|
||||
List<InvitationDto> dtos = new List<InvitationDto>();
|
||||
List<InvitationResponses> dtos = new List<InvitationResponses>();
|
||||
|
||||
foreach (var inv in read)
|
||||
{
|
||||
dtos.Add(new InvitationDto(){
|
||||
dtos.Add(new InvitationResponses(){
|
||||
Id = inv.Id,
|
||||
Description = inv.Description,
|
||||
IsAdmin = inv.IsAdmin,
|
||||
@@ -100,6 +101,7 @@ public class InviteUserController : Controller
|
||||
CreatedAt = inv.DateCreated,
|
||||
EndAt = inv.EndDate,
|
||||
IsActive = inv.IsActive,
|
||||
ParticipantCount = inv.Users.Count,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -120,18 +122,18 @@ public class InviteUserController : Controller
|
||||
_logger.LogInformation("Getting invitations {id} by administrator");
|
||||
var read = await _repository.FindByIdAsync(id);
|
||||
|
||||
var response = new InvitationDto(){
|
||||
Id = read.Id,
|
||||
Description = read.Description,
|
||||
IsAdmin = read.IsAdmin,
|
||||
MaxParticipants = read.MaxParticipants,
|
||||
Code = read.Code,
|
||||
CreatedAt = read.DateCreated,
|
||||
EndAt = read.EndDate,
|
||||
IsActive = read.IsActive,
|
||||
var response = new InvitationResponses(){
|
||||
Id = read.Id,
|
||||
Description = read.Description,
|
||||
IsAdmin = read.IsAdmin,
|
||||
MaxParticipants = read.MaxParticipants,
|
||||
Code = read.Code,
|
||||
CreatedAt = read.DateCreated,
|
||||
EndAt = read.EndDate,
|
||||
IsActive = read.IsActive,
|
||||
ParticipantCount = read.Users.Count,
|
||||
};
|
||||
|
||||
|
||||
return Ok(response);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@@ -67,19 +67,29 @@ public static class ConfigurationProgramExtensions
|
||||
|
||||
public static void AddGovorDbContext(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
var useMySql = configuration.GetValue<bool>("UseMySql"); // Получаем значение из конфигурации
|
||||
var useMySql = configuration.GetValue<bool>("UseMySql");
|
||||
|
||||
if (useMySql)
|
||||
{
|
||||
services.AddDbContext<GovorDbContext>(options =>
|
||||
options.UseMySql(configuration.GetConnectionString(nameof(GovorDbContext)),
|
||||
new MySqlServerVersion(new Version(8, 0, 21))));
|
||||
{
|
||||
options
|
||||
.UseMySql(
|
||||
configuration.GetConnectionString(nameof(GovorDbContext)),
|
||||
new MySqlServerVersion(new Version(8, 0, 21))
|
||||
);
|
||||
options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
services.AddDbContext<GovorDbContext>(options =>
|
||||
options.UseNpgsql(configuration.GetConnectionString(nameof(GovorDbContext))));
|
||||
{
|
||||
options.UseNpgsql(configuration.GetConnectionString(nameof(GovorDbContext)));
|
||||
options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user