Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration #29

Merged
merged 20 commits into from
Dec 17, 2024
Merged
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 CheckDrive.Api/CheckDrive.Api/CheckDrive.Api.csproj
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@

<ItemGroup>
<PackageReference Include="Bogus" Version="35.6.1" />
<PackageReference Include="CsvHelper" Version="33.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.8" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.8" />
35 changes: 34 additions & 1 deletion CheckDrive.Api/CheckDrive.Api/Controllers/CarsController.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
using CheckDrive.Application.DTOs.Car;
using CheckDrive.Application.Interfaces;
using CheckDrive.Application.Mappings.CSV;
using CheckDrive.Application.QueryParameters;
using CheckDrive.Domain.Entities;
using CsvHelper;
using CsvHelper.Configuration;
using Microsoft.AspNetCore.Mvc;
using System.Globalization;

namespace CheckDrive.Api.Controllers;

@@ -17,7 +22,7 @@ public CarsController(ICarService carService)
}

[HttpGet]
public async Task<ActionResult<List<CarDto>>> GetAllAsync(CarQueryParameters queryParameters)
public async Task<ActionResult<List<CarDto>>> GetAllAsync([FromQuery] CarQueryParameters queryParameters)
{
var cars = await _carService.GetAllAsync(queryParameters);

@@ -40,6 +45,34 @@ public async Task<ActionResult<CarDto>> CreateAsync(CreateCarDto car)
return CreatedAtAction("GetCarByIdAsync", createdCar, new { id = createdCar.Id });
}

[HttpPost("upload")]
public IActionResult Upload(IFormFile file)
{
if (file == null || file.Length == 0)
return BadRequest("File not provided or empty");

if (!file.FileName.EndsWith(".csv"))
return BadRequest("Invalid file format. Please upload a CSV file.");

using var reader = new StreamReader(file.OpenReadStream());
using var csv = new CsvReader(reader, new CsvConfiguration(CultureInfo.InvariantCulture)
{
HasHeaderRecord = false,
});
csv.Context.RegisterClassMap<CarCsvMappings>();

try
{
var records = csv.GetRecords<Car>().ToList();

return Ok(new { Message = "CSV processed successfully", RecordCount = records.Count });
}
catch (Exception ex)
{
return BadRequest($"Error processing CSV: {ex.Message}");
}
}

[HttpPut("{id:int}")]
public async Task<ActionResult<CarDto>> UpdateAsync(int id, UpdateCarDto car)
{
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CheckDrive.Application.DTOs.Driver;
using CheckDrive.Application.Interfaces;
using CheckDrive.Application.QueryParameters;
using Microsoft.AspNetCore.Mvc;

namespace CheckDrive.Api.Controllers;
@@ -16,9 +17,9 @@ public DriversController(IDriverService driverService)
}

[HttpGet]
public async Task<ActionResult<List<DriverDto>>> GetAvailableDriversAsync()
public async Task<ActionResult<List<DriverDto>>> GetAvailableDriversAsync([FromQuery] DriverQueryParameters queryParameters)
{
var drivers = await _driverService.GetAvailableDriversAsync();
var drivers = await _driverService.GetAsync(queryParameters);

return Ok(drivers);
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
using CheckDrive.Application.Constants;
using CheckDrive.Application.DTOs.Account;
using CheckDrive.Application.DTOs.Employee;
using CheckDrive.Application.Interfaces;
using CheckDrive.Domain.Enums;
using CheckDrive.Application.QueryParameters;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace CheckDrive.Api.Controllers;

[Route("api/accounts")]
[Route("api/employees")]
[ApiController]
public class AccountsController : ControllerBase
public class EmployeesController : ControllerBase
{
private readonly IAccountService _service;
private readonly IEmployeeService _service;

public AccountsController(IAccountService service)
public EmployeesController(IEmployeeService service)
{
_service = service ?? throw new ArgumentNullException(nameof(service));
}

[HttpGet]
public async Task<ActionResult<List<AccountDto>>> GetAsync(EmployeePosition? position)
public async Task<ActionResult<List<EmployeeDto>>> GetAsync([FromQuery] EmployeeQueryParameters queryParameters)
{
var accounts = await _service.GetAsync(position);
var accounts = await _service.GetAsync(queryParameters);

return Ok(accounts);
}

[HttpGet("{id}", Name = nameof(GetAccountByIdAsync))]
public async Task<ActionResult<AccountDto>> GetAccountByIdAsync(string id)
[HttpGet("{id}", Name = nameof(GetEmployeeByIdAsync))]
public async Task<ActionResult<EmployeeDto>> GetEmployeeByIdAsync(string id)
{
var account = await _service.GetByIdAsync(id);

@@ -36,15 +36,15 @@ public async Task<ActionResult<AccountDto>> GetAccountByIdAsync(string id)

[HttpPost]
[Authorize(Roles = $"{Roles.Manager},{Roles.Administrator}")]
public async Task<ActionResult<AccountDto>> CreateAsync([FromBody] CreateAccountDto account)
public async Task<ActionResult<EmployeeDto>> CreateAsync([FromBody] CreateEmployeeDto account)
{
var createdAccount = await _service.CreateAsync(account);

return CreatedAtAction(nameof(GetAccountByIdAsync), new { id = createdAccount.Id }, createdAccount);
return CreatedAtAction(nameof(GetEmployeeByIdAsync), new { id = createdAccount.Id }, createdAccount);
}

[HttpPut("{id}")]
public async Task<ActionResult<AccountDto>> UpdateAsync([FromRoute] string id, [FromBody] UpdateAccountDto account)
public async Task<ActionResult<EmployeeDto>> UpdateAsync([FromRoute] string id, [FromBody] UpdateEmployeeDto account)
{
if (id != account.Id)
{
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ public OilMarksController(IOilMarkService oilMarkService)
}

[HttpGet]
public async Task<ActionResult<List<OilMarkDto>>> GetAsync(OilMarkQueryParameters queryParameters)
public async Task<ActionResult<List<OilMarkDto>>> GetAsync([FromQuery] OilMarkQueryParameters queryParameters)
{
var oilMarks = await _oilMarkService.GetAllAsync(queryParameters);

Original file line number Diff line number Diff line change
@@ -20,9 +20,9 @@ public async Task<ActionResult<DispatcherReviewDto>> CreateAsync(
[FromRoute] int dispatcherId,
[FromBody] CreateDispatcherReviewDto review)
{
if (review.ReviewerId != dispatcherId)
if (review.DispatcherId != dispatcherId)
{
return BadRequest($"Route id: {dispatcherId} does not match with body id: {review.ReviewerId}.");
return BadRequest($"Route id: {dispatcherId} does not match with body id: {review.DispatcherId}.");
}

var createdReview = await _reviewService.CreateAsync(review);
Original file line number Diff line number Diff line change
@@ -20,9 +20,9 @@ public async Task<ActionResult<DoctorReviewDto>> CreateReview(
[FromRoute] int doctorId,
[FromBody] CreateDoctorReviewDto review)
{
if (doctorId != review.ReviewerId)
if (doctorId != review.DoctorId)
{
return BadRequest($"Route id: {doctorId} does not match with body id: {review.ReviewerId}.");
return BadRequest($"Route id: {doctorId} does not match with body id: {review.DoctorId}.");
}

var craetedReview = await _reviewService.CreateAsync(review);
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using CheckDrive.Application.DTOs.ManagerReview;
using CheckDrive.Application.Interfaces.Review;
using Microsoft.AspNetCore.Mvc;

namespace CheckDrive.Api.Controllers.Reviews;

[ApiController]
[Route("api/reviews/managers/{managerId:int}")]
public class ManagerReviewsController : ControllerBase
{
private readonly IManagerReviewService _reviewService;

public ManagerReviewsController(IManagerReviewService reviewService)
{
_reviewService = reviewService;
}

[HttpPost]
public async Task<ActionResult<ManagerReviewDto>> CreateReview([FromBody] CreateManagerReviewDto review)
{
var result = await _reviewService.CreateAsync(review);

return Created("", result);
}
}
Original file line number Diff line number Diff line change
@@ -20,9 +20,9 @@ public async Task<ActionResult<MechanicAcceptanceReviewDto>> CreateAcceptanceRev
[FromRoute] int mechanicId,
[FromBody] CreateMechanicAcceptanceReviewDto review)
{
if (review.ReviewerId != mechanicId)
if (review.MechanicId != mechanicId)
{
return BadRequest($"Route id: {mechanicId} does not match with body id: {review.ReviewerId}.");
return BadRequest($"Route id: {mechanicId} does not match with body id: {review.MechanicId}.");
}

var createdReview = await _reviewService.CreateAsync(review);
Original file line number Diff line number Diff line change
@@ -20,9 +20,9 @@ public async Task<ActionResult<MechanicHandoverReviewDto>> CreateHandoverReviewA
[FromRoute] int mechanicId,
[FromBody] CreateMechanicHandoverReviewDto review)
{
if (review.ReviewerId != mechanicId)
if (review.MechanicId != mechanicId)
{
return BadRequest($"Route id: {mechanicId} does not match with body id: {review.ReviewerId}.");
return BadRequest($"Route id: {mechanicId} does not match with body id: {review.MechanicId}.");
}

var createdReview = await _reviewService.CreateAsync(review);
Original file line number Diff line number Diff line change
@@ -20,9 +20,9 @@ public async Task<ActionResult<OperatorReviewDto>> CreateAsync(
[FromRoute] int operatorId,
[FromBody] CreateOperatorReviewDto review)
{
if (review.ReviewerId != operatorId)
if (review.OperatorId != operatorId)
{
return BadRequest($"Route id: {operatorId} does not match with body id: {review.ReviewerId}.");
return BadRequest($"Route id: {operatorId} does not match with body id: {review.OperatorId}.");
}

var createdReview = await _reviewService.CreateAsync(review);
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
using CheckDrive.Application.DTOs.OperatorReview;
using CheckDrive.Application.DTOs.Review;
using CheckDrive.Application.Interfaces.Review;
using CheckDrive.Application.DTOs.DispatcherReview;

namespace CheckDrive.Api.Controllers.Reviews;

@@ -43,10 +44,18 @@ public async Task<ActionResult<List<MechanicReviewHistoryDto>>> GetMechanicHisto
}

[HttpGet("operators/{operatorId:int}")]
public async Task<ActionResult<List<OperatorReviewDto>>> GetOperatorHistoriesAsync(int operatorId)
public async Task<ActionResult<List<OperatorReviewHistory>>> GetOperatorHistoriesAsync(int operatorId)
{
var reviews = await _historyService.GetOperatorHistoriesAsync(operatorId);

return Ok(reviews);
}

[HttpGet("dispatchers/{dispatcherId:int}")]
public async Task<ActionResult<List<DispatcherReviewHistoryDto>>> GetDispatcherHistoriesAsync(int dispatcherId)
{
var reviews = await _historyService.GetDispatcherHistoriesAsync(dispatcherId);

return Ok(reviews);
}
}
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
using CheckDrive.Infrastructure.Configurations;
using CheckDrive.Infrastructure.Extensions;
using CheckDrive.TestDataCreator.Configurations;
using CheckDrive.TestDataCreator.Extensions;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.IdentityModel.Tokens;
@@ -18,6 +19,7 @@ public static IServiceCollection ConfigureServices(this IServiceCollection servi
{
services.RegisterApplication();
services.RegisterInfrastructure(configuration);
services.RegisterTestDataCreator();

services.AddSingleton<FileExtensionContentTypeProvider>();
services.AddSignalR(options =>
9 changes: 6 additions & 3 deletions CheckDrive.Api/CheckDrive.Api/Extensions/StartupExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using CheckDrive.Api.Helpers;
using CheckDrive.Api.Middlewares;
using CheckDrive.Api.Middlewares;
using CheckDrive.Domain.Interfaces;
using CheckDrive.TestDataCreator.Configurations;
using CheckDrive.TestDataCreator.Interfaces;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Options;

@@ -23,7 +23,10 @@ public static IApplicationBuilder UseDatabaseSeeder(this WebApplication app)
var userManager = scope.ServiceProvider.GetRequiredService<UserManager<IdentityUser>>();
var options = scope.ServiceProvider.GetRequiredService<IOptions<DataSeedOptions>>();

DatabaseSeeder.SeedDatabase(context, userManager, options.Value);
var seederFactory = scope.ServiceProvider.GetRequiredService<IDatabaseSeederFactory>();
var seeder = seederFactory.CreateSeeder(app.Environment.EnvironmentName);

seeder.SeedDatabase(context, userManager, options.Value);

return app;
}
Loading

Unchanged files with check annotations Beta

}
var user = await _userManager.FindByNameAsync(request.UserName);
var roles = await _userManager.GetRolesAsync(user);

Check warning on line 38 in CheckDrive.Api/CheckDrive.Application/Services/Auth/AuthService.cs

GitHub Actions / build

Possible null reference argument for parameter 'user' in 'Task<IList<string>> UserManager<IdentityUser>.GetRolesAsync(IdentityUser user)'.

Check warning on line 38 in CheckDrive.Api/CheckDrive.Application/Services/Auth/AuthService.cs

GitHub Actions / build

Possible null reference argument for parameter 'user' in 'Task<IList<string>> UserManager<IdentityUser>.GetRolesAsync(IdentityUser user)'.
var token = _jwtTokenGenerator.GenerateToken(employee, roles);
return token;