Skip to content

Commit

Permalink
lots of stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
fixterjake committed Apr 11, 2024
1 parent 197d69c commit 191f898
Show file tree
Hide file tree
Showing 17 changed files with 193 additions and 33 deletions.
22 changes: 11 additions & 11 deletions Memphis.API/Controllers/AirportsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public async Task<ActionResult<Response<Airport>>> CreateAirport(AirportDto payl
if (!await redisService.ValidateRoles(Request.HttpContext.User, Constants.CanAirportsList))
return StatusCode(401);

var validation = await validator.ValidateAsync(payload);
ValidationResult validation = await validator.ValidateAsync(payload);
if (!validation.IsValid)
{
return BadRequest(new Response<IList<ValidationFailure>>
Expand All @@ -47,13 +47,13 @@ public async Task<ActionResult<Response<Airport>>> CreateAirport(AirportDto payl
});
}

var result = await context.Airports.AddAsync(new Airport
Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry<Airport> result = await context.Airports.AddAsync(new Airport
{
Name = payload.Name,
Icao = payload.Icao,
});
await context.SaveChangesAsync();
var newData = JsonConvert.SerializeObject(result.Entity);
string newData = JsonConvert.SerializeObject(result.Entity);
await loggingService.AddWebsiteLog(Request, $"Created airport {result.Entity.Id}", string.Empty, newData);

return StatusCode(201, new Response<Airport>
Expand All @@ -77,7 +77,7 @@ public async Task<ActionResult<Response<IList<Airport>>>> GetAirports()
{
try
{
var result = await context.Airports.ToListAsync();
List<Airport> result = await context.Airports.ToListAsync();
return Ok(new Response<IList<Airport>>
{
StatusCode = 200,
Expand All @@ -100,7 +100,7 @@ public async Task<ActionResult<Response<IList<Airport>>>> GetAirport(int airport
{
try
{
var result = await context.Airports.FindAsync(airportId);
Airport? result = await context.Airports.FindAsync(airportId);
if (result == null)
{
return NotFound(new Response<int>
Expand Down Expand Up @@ -140,7 +140,7 @@ public async Task<ActionResult<Response<Airport>>> UpdateAirport(AirportDto payl
if (!await redisService.ValidateRoles(Request.HttpContext.User, Constants.CanAirportsList))
return StatusCode(401);

var validation = await validator.ValidateAsync(payload);
ValidationResult validation = await validator.ValidateAsync(payload);
if (!validation.IsValid)
{
return BadRequest(new Response<IList<ValidationFailure>>
Expand All @@ -151,7 +151,7 @@ public async Task<ActionResult<Response<Airport>>> UpdateAirport(AirportDto payl
});
}

var airport = await context.Airports.FindAsync();
Airport? airport = await context.Airports.FindAsync();
if (airport == null)
{
return NotFound(new Response<string?>
Expand All @@ -161,12 +161,12 @@ public async Task<ActionResult<Response<Airport>>> UpdateAirport(AirportDto payl
});
}

var oldData = JsonConvert.SerializeObject(airport);
string oldData = JsonConvert.SerializeObject(airport);
airport.Name = payload.Name;
airport.Icao = payload.Icao;
airport.Updated = DateTimeOffset.UtcNow;
await context.SaveChangesAsync();
var newData = JsonConvert.SerializeObject(airport);
string newData = JsonConvert.SerializeObject(airport);

await loggingService.AddWebsiteLog(Request, $"Updated airport '{airport.Id}'", oldData, newData);

Expand Down Expand Up @@ -198,7 +198,7 @@ public async Task<ActionResult<Response<string>>> DeleteAirport(int airportId)
if (!await redisService.ValidateRoles(Request.HttpContext.User, Constants.CanAirportsList))
return StatusCode(401);

var airport = await context.Airports.FindAsync(airportId);
Airport? airport = await context.Airports.FindAsync(airportId);
if (airport == null)
{
return NotFound(new Response<int>
Expand All @@ -209,7 +209,7 @@ public async Task<ActionResult<Response<string>>> DeleteAirport(int airportId)
});
}

var oldData = JsonConvert.SerializeObject(airport);
string oldData = JsonConvert.SerializeObject(airport);
context.Airports.Remove(airport);
await context.SaveChangesAsync();

Expand Down
9 changes: 7 additions & 2 deletions Memphis.API/Controllers/EventPositionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ namespace Memphis.API.Controllers;
[ApiController]
[Route("[controller]")]
[Produces("application/json")]
public class EventPositionsController(DatabaseContext context, RedisService redisService, LoggingService loggingService,
IValidator<EventPositionDto> validator, ISentryClient sentryHub, ILogger<EventPositionsController> logger)
public class EventPositionsController(
DatabaseContext context,
RedisService redisService,
LoggingService loggingService,
IValidator<EventPositionDto> validator,
ISentryClient sentryHub,
ILogger<EventPositionsController> logger)
: ControllerBase
{
[HttpPost]
Expand Down
9 changes: 3 additions & 6 deletions Memphis.API/Controllers/TrainingSchedulesController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#region

using FluentValidation;
using FluentValidation;
using FluentValidation.Results;
using Memphis.API.Data;
using Memphis.API.Extensions;
Expand All @@ -14,7 +12,6 @@
using Sentry;
using Constants = Memphis.Shared.Utils.Constants;

#endregion

namespace Memphis.API.Controllers;

Expand Down Expand Up @@ -44,7 +41,7 @@ public async Task<ActionResult<Response<TrainingSchedule>>> CreateTrainingSchedu
if (!await redisService.ValidateRoles(Request.HttpContext.User, Constants.CanTrainingMilestonesList))
return StatusCode(401);

ValidationResult validation = await validator.ValidateAsync(payload);
var validation = await validator.ValidateAsync(payload);
if (!validation.IsValid)
{
return BadRequest(new Response<IList<ValidationFailure>>
Expand All @@ -65,7 +62,7 @@ public async Task<ActionResult<Response<TrainingSchedule>>> CreateTrainingSchedu
});
}

List<TrainingType> trainingTypes = new List<TrainingType>();
List<TrainingType> trainingTypes = [];
foreach (int entry in payload.TrainingTypes)
{
TrainingType? trainingType = await context.TrainingTypes.FindAsync(entry);
Expand Down
22 changes: 11 additions & 11 deletions Memphis.API/Memphis.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.S3" Version="3.7.304.1" />
<PackageReference Include="AWSSDK.S3" Version="3.7.307.14" />
<PackageReference Include="dotenv.net" Version="3.1.3" />
<PackageReference Include="FluentValidation" Version="11.8.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.0">
<PackageReference Include="FluentValidation" Version="11.9.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.4" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
<PackageReference Include="prometheus-net.AspNetCore" Version="8.1.1" />
<PackageReference Include="Sentry.AspNetCore" Version="3.41.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" />
<PackageReference Include="prometheus-net.AspNetCore" Version="8.2.1" />
<PackageReference Include="Sentry.AspNetCore" Version="4.3.0" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
<PackageReference Include="StackExchange.Redis" Version="2.7.4" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="StackExchange.Redis" Version="2.7.33" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

Expand Down
5 changes: 3 additions & 2 deletions Memphis.API/Services/LoggingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ public LoggingService(DatabaseContext context)

public async Task AddWebsiteLog(HttpRequest request, string action, string oldData, string newData)
{
var ip = request.Headers["CF-Connecting-IP"].ToString() ??
request.HttpContext.Connection?.RemoteIpAddress?.ToString() ?? "Not Found";
var ip = request.Headers["CF-Connecting-IP"].ToString() == string.Empty
? "Not Found"
: request.Headers["CF-Connecting-IP"].ToString();
var cid = request.HttpContext.User.Claims.FirstOrDefault(x => x.Type == "cid")?.Value ?? "Not Found";
var name = request.HttpContext.User.Claims.FirstOrDefault(x => x.Type == "fullName")?.Value ?? "Not Found";
await _context.WebsiteLogs.AddAsync(new WebsiteLog
Expand Down
3 changes: 2 additions & 1 deletion Memphis.Shared/Memphis.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="8.0.0" />
<PackageReference Include="FluentValidation" Version="11.9.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="8.0.4" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

Expand Down
13 changes: 13 additions & 0 deletions Memphis.Shared/Validators/AirportValidator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using FluentValidation;
using Memphis.Shared.Dtos;

namespace Memphis.Shared.Validators;

public class AirportValidator : AbstractValidator<AirportDto>
{
public AirportValidator()
{
RuleFor(x => x.Icao).NotEmpty().Length(4);
RuleFor(x => x.Name).NotEmpty();
}
}
14 changes: 14 additions & 0 deletions Memphis.Shared/Validators/CommentValidator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using FluentValidation;
using Memphis.Shared.Dtos;

namespace Memphis.Shared.Validators;

public class CommentValidator : AbstractValidator<CommentDto>
{
public CommentValidator()
{
RuleFor(x => x.UserId).NotEmpty().GreaterThan(0);
RuleFor(x => x.Title).NotEmpty();
RuleFor(x => x.Description).NotEmpty();
}
}
14 changes: 14 additions & 0 deletions Memphis.Shared/Validators/EventPositionValidator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using FluentValidation;
using Memphis.Shared.Dtos;

namespace Memphis.Shared.Validators;

public class EventPositionValidator : AbstractValidator<EventPositionDto>
{
public EventPositionValidator()
{
RuleFor(x => x.EventId).NotEmpty();
RuleFor(x => x.Name).NotEmpty();
RuleFor(x => x.MinRating).NotEmpty();
}
}
15 changes: 15 additions & 0 deletions Memphis.Shared/Validators/EventRegistrationValidator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using FluentValidation;
using Memphis.Shared.Dtos;

namespace Memphis.Shared.Validators;

public class EventRegistrationValidator : AbstractValidator<EventRegistrationDto>
{
public EventRegistrationValidator()
{
RuleFor(x => x.EventId).NotEmpty();
RuleFor(x => x.EventPositionId).NotEmpty();
RuleFor(x => x.Start).NotEmpty();
RuleFor(x => x.End).NotEmpty();
}
}
14 changes: 14 additions & 0 deletions Memphis.Shared/Validators/EventValidator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using FluentValidation;
using Memphis.Shared.Dtos;

namespace Memphis.Shared.Validators;

public class EventValidator : AbstractValidator<EventDto>
{
public EventValidator()
{
RuleFor(x => x.Title).NotEmpty();
RuleFor(x => x.Description).NotEmpty();
RuleFor(x => x.Host).NotEmpty();
}
}
14 changes: 14 additions & 0 deletions Memphis.Shared/Validators/FaqValidator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using FluentValidation;
using Memphis.Shared.Dtos;

namespace Memphis.Shared.Validators;

public class FaqValidator : AbstractValidator<FaqDto>
{
public FaqValidator()
{
RuleFor(x => x.Question).NotEmpty();
RuleFor(x => x.Answer).NotEmpty();
RuleFor(x => x.Order).NotEmpty();
}
}
15 changes: 15 additions & 0 deletions Memphis.Shared/Validators/FeedbackValidator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using FluentValidation;
using Memphis.Shared.Dtos;

namespace Memphis.Shared.Validators;

public class FeedbackValidator : AbstractValidator<FeedbackDto>
{
public FeedbackValidator()
{
RuleFor(x => x.ControllerId).NotEmpty().GreaterThan(0);
RuleFor(x => x.ControllerCallsign).NotEmpty();
RuleFor(x => x.Description).NotEmpty();
RuleFor(x => x.Level).NotEmpty();
}
}
15 changes: 15 additions & 0 deletions Memphis.Shared/Validators/FileValidator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using FluentValidation;
using Memphis.Shared.Dtos;

namespace Memphis.Shared.Validators;

public class FileValidator : AbstractValidator<FileDto>
{
public FileValidator()
{
RuleFor(x => x.Title).NotEmpty();
RuleFor(x => x.Description).NotEmpty();
RuleFor(x => x.Version).NotEmpty();
RuleFor(x => x.Type).NotEmpty();
}
}
15 changes: 15 additions & 0 deletions Memphis.Shared/Validators/OtsValidator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using FluentValidation;
using Memphis.Shared.Dtos;

namespace Memphis.Shared.Validators;

public class OtsValidator : AbstractValidator<OtsDto>
{
public OtsValidator()
{
RuleFor(x => x.Submitter).NotEmpty();
RuleFor(x => x.User).NotEmpty();
RuleFor(x => x.Milestone).NotEmpty();
RuleFor(x => x.Facility).NotEmpty();
}
}
14 changes: 14 additions & 0 deletions Memphis.Shared/Validators/TrainingMilestoneValidator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using FluentValidation;
using Memphis.Shared.Models;

namespace Memphis.Shared.Validators;

public class TrainingMilestoneValidator : AbstractValidator<TrainingMilestone>
{
public TrainingMilestoneValidator()
{
RuleFor(x => x.Code).NotEmpty();
RuleFor(x => x.Name).NotEmpty();
RuleFor(x => x.Facility).NotEmpty();
}
}
13 changes: 13 additions & 0 deletions Memphis.Shared/Validators/TrainingScheduleValidator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using FluentValidation;
using Memphis.Shared.Dtos;

namespace Memphis.Shared.Validators;

public class TrainingScheduleValidator : AbstractValidator<TrainingScheduleDto>
{
public TrainingScheduleValidator()
{
RuleFor(x => x.TrainingTypes).NotEmpty();
RuleFor(x => x.Start).NotEmpty();
}
}

0 comments on commit 191f898

Please sign in to comment.