From 2ba7d86e7132f77a198c6549e964cb422e3cb0e8 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 14 Nov 2025 05:02:01 +0000 Subject: [PATCH] Refactor CompaniesController to use DTOs for machine and company operations --- .../Controllers/CompaniesController.cs | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Marechai.Server/Controllers/CompaniesController.cs b/Marechai.Server/Controllers/CompaniesController.cs index 1b29a551..be5fd609 100644 --- a/Marechai.Server/Controllers/CompaniesController.cs +++ b/Marechai.Server/Controllers/CompaniesController.cs @@ -190,15 +190,15 @@ public class CompaniesController(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public Task> GetMachinesAsync(int id) => context.Machines.Where(m => m.CompanyId == id) - .OrderBy(m => m.Name) - .Select(m => new Machine - { - Id = m.Id, - Name = m.Name, - Type = m.Type - }) - .ToListAsync(); + public Task> GetMachinesAsync(int id) => context.Machines.Where(m => m.CompanyId == id) + .OrderBy(m => m.Name) + .Select(m => new MachineDto + { + Id = m.Id, + Name = m.Name, + Type = m.Type + }) + .ToListAsync(); [HttpGet("{id:int}/description/text")] [AllowAnonymous] @@ -215,12 +215,12 @@ public class CompaniesController(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public Task GetSoldToAsync(int? id) => context.Companies.Select(c => new Company - { - Id = c.Id, - Name = c.Name - }) - .FirstOrDefaultAsync(c => c.Id == id); + public Task GetSoldToAsync(int? id) => context.Companies.Select(c => new CompanyDto + { + Id = c.Id, + Name = c.Name + }) + .FirstOrDefaultAsync(c => c.Id == id); [HttpGet("/countries/{id:int}/name")] [AllowAnonymous] @@ -233,8 +233,8 @@ public class CompaniesController(MarechaiContext context) : ControllerBase [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] - public Task> GetCompaniesByCountryAsync(int countryId) => context.Companies.Include(c => c.Logos) - .Where(c => c.CountryId == countryId) + public Task> GetCompaniesByCountryAsync(int id) => context.Companies.Include(c => c.Logos) + .Where(c => c.CountryId == id) .OrderBy(c => c.Name) .Select(c => new CompanyDto {