Skip to content

Commit

Permalink
remove Logger from the baseapi constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
nixhantb committed Jan 18, 2025
1 parent 59a032b commit a9d469b
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 55 deletions.
8 changes: 1 addition & 7 deletions JobLeet.WebApi/JobLeet.Api/Controllers/BaseApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ public abstract class BaseApiController<TEntity, TModel, TService> : ControllerB
where TService : IService<TEntity, TModel>
{
protected readonly TService _service;
protected readonly ILoggerManagerV1 _logger;
protected readonly IValidator<TEntity> _validator;
protected BaseApiController(TService service, ILoggerManagerV1 logger, IValidator<TEntity> validator)
protected BaseApiController(TService service, IValidator<TEntity> validator)
{
_service= service ?? throw new ArgumentNullException(nameof(service));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_validator = validator ?? throw new ArgumentNullException(nameof(validator));

}
Expand All @@ -33,13 +31,11 @@ public virtual async Task<IActionResult> GetAllAsync()
{
try
{
_logger.LogInfo("Triggering HTTP GET request");
var entities = await _service.GetAllAsync();
return Ok(entities);
}
catch (Exception ex)
{
_logger.LogError($"An error occurred while fetching all entities: {ex.Message}");
var errorResponse = new GlobalErrorResponse
{
Error = "Internal Server Error",
Expand Down Expand Up @@ -68,7 +64,6 @@ public virtual async Task<IActionResult> GetByIdAsync(int id)
}
catch (Exception ex)
{
_logger.LogError($"An error occurred while fetching the data: {ex.Message}");
var errorResponse = new GlobalErrorResponse
{
Error = "System Exception",
Expand Down Expand Up @@ -109,7 +104,6 @@ public virtual async Task<IActionResult> CreateAsync([FromBody] TEntity entity)
}
catch (Exception ex)
{
_logger.LogError($"Error occurred while creating the entity: {ex.Message}");
var errorResponse = new GlobalErrorResponse
{
Error = "System Exception",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using FluentValidation;
using JobLeet.WebApi.JobLeet.Api.Logging;
using JobLeet.WebApi.JobLeet.Api.Models.Common.V1;
using JobLeet.WebApi.JobLeet.Core.Entities.Common.V1;
using JobLeet.WebApi.JobLeet.Core.Interfaces.Common.V1;
Expand All @@ -8,10 +7,11 @@
namespace JobLeet.WebApi.JobLeet.Api.Controllers.Common.V1
{
[Route("api/v1/addresses")]
public class AddressController : BaseApiController<Address,AddressModel, IAddressService>
public class AddressController : BaseApiController<Address, AddressModel, IAddressService>
{
public AddressController(IAddressService addressRepository, ILoggerManagerV1 logger, IValidator<Address> validator) : base(addressRepository, logger, validator)
{
public AddressController(IAddressService addressRepository, IValidator<Address> validator)
: base(addressRepository, validator)
{

}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using FluentValidation;
using JobLeet.WebApi.JobLeet.Api.Logging;
using JobLeet.WebApi.JobLeet.Api.Models.Common.V1;
using JobLeet.WebApi.JobLeet.Core.Entities.Common.V1;
using JobLeet.WebApi.JobLeet.Core.Interfaces.Common.V1;
Expand All @@ -8,10 +7,10 @@
namespace JobLeet.WebApi.JobLeet.Api.Controllers.Common.V1
{
[Route("api/v1/educations")]
public class EducationController : BaseApiController<Education,EducationModel, IEducationService>
public class EducationController : BaseApiController<Education, EducationModel, IEducationService>
{
public EducationController(IEducationService educationService, ILoggerManagerV1 logger, IValidator<Education> validator)
:base(educationService, logger, validator) { }
public EducationController(IEducationService educationService, IValidator<Education> validator)
: base(educationService, validator) { }

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using JobLeet.WebApi.JobLeet.Api.Models.Common.V1;
using JobLeet.WebApi.JobLeet.Api.Logging;
using JobLeet.WebApi.JobLeet.Core.Interfaces.Common.V1;
using Microsoft.AspNetCore.Mvc;
using JobLeet.WebApi.JobLeet.Core.Entities.Common.V1;
Expand All @@ -10,8 +9,8 @@ namespace JobLeet.WebApi.JobLeet.Api.Controllers.Common.V1
[Route("api/v1/email-types")]
public class EmailController : BaseApiController<Email, EmailModel, IEmailService>
{
public EmailController(IEmailService emailService, ILoggerManagerV1 logger, IValidator<Email> validator)
: base(emailService, logger, validator)
public EmailController(IEmailService emailService, IValidator<Email> validator)
: base(emailService, validator)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using FluentValidation;
using JobLeet.WebApi.JobLeet.Api.Logging;
using JobLeet.WebApi.JobLeet.Api.Models.Common.V1;
using JobLeet.WebApi.JobLeet.Core.Entities.Common.V1;
using JobLeet.WebApi.JobLeet.Core.Interfaces.Common.V1;
Expand All @@ -10,8 +9,8 @@ namespace JobLeet.WebApi.JobLeet.Api.Controllers.Common.V1
[Route("api/v1/experiences")]
public class ExperienceController : BaseApiController<Experience, ExperienceModel, IExperienceService>
{
public ExperienceController(IExperienceService experienceService, ILoggerManagerV1 logger, IValidator<Experience> validator)
: base(experienceService, logger, validator)
public ExperienceController(IExperienceService experienceService, IValidator<Experience> validator)
: base(experienceService, validator)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using FluentValidation;
using JobLeet.WebApi.JobLeet.Api.Logging;
using JobLeet.WebApi.JobLeet.Api.Models.Common.V1;
using JobLeet.WebApi.JobLeet.Core.Entities.Common.V1;
using JobLeet.WebApi.JobLeet.Core.Interfaces.Common.V1;
Expand All @@ -10,8 +9,8 @@ namespace JobLeet.WebApi.JobLeet.Api.Controllers.Common.V1
[Route("api/v1/person-names")]
public class PersonNameController : BaseApiController<PersonName, PersonNameModel, IPersonNameService>
{
public PersonNameController(IPersonNameService personNameService, ILoggerManagerV1 logger, IValidator<PersonName> validator)
: base(personNameService, logger, validator)
public PersonNameController(IPersonNameService personNameService, IValidator<PersonName> validator)
: base(personNameService, validator)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using FluentValidation;
using JobLeet.WebApi.JobLeet.Api.Logging;
using JobLeet.WebApi.JobLeet.Api.Models.Common.V1;
using JobLeet.WebApi.JobLeet.Core.Entities.Common.V1;
using JobLeet.WebApi.JobLeet.Core.Interfaces.Common.V1;
Expand All @@ -10,8 +9,8 @@ namespace JobLeet.WebApi.JobLeet.Api.Controllers.Common.V1
[Route("api/v1/phones")]
public class PhoneController : BaseApiController<Phone, PhoneModel, IPhoneService>
{
public PhoneController(IPhoneService phoneService, ILoggerManagerV1 logger, IValidator<Phone> validator)
: base(phoneService, logger, validator)
public PhoneController(IPhoneService phoneService,IValidator<Phone> validator)
: base(phoneService, validator)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using FluentValidation;
using JobLeet.WebApi.JobLeet.Api.Logging;
using JobLeet.WebApi.JobLeet.Api.Models.Common.V1;
using JobLeet.WebApi.JobLeet.Core.Entities.Common.V1;
using JobLeet.WebApi.JobLeet.Core.Interfaces.Common.V1;
Expand All @@ -10,8 +9,8 @@ namespace JobLeet.WebApi.JobLeet.Api.Controllers.Common.V1
[Route("api/v1/qualification-types")]
public class QualificationController : BaseApiController<Qualification, QualificationModel, IQualificationService>
{
public QualificationController(IQualificationService qualificationService, ILoggerManagerV1 logger, IValidator<Qualification> validator)
: base(qualificationService, logger, validator)
public QualificationController(IQualificationService qualificationService, IValidator<Qualification> validator)
: base(qualificationService, validator)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using FluentValidation;
using JobLeet.WebApi.JobLeet.Api.Logging;
using JobLeet.WebApi.JobLeet.Api.Models.Common.V1;
using JobLeet.WebApi.JobLeet.Core.Entities.Common.V1;
using JobLeet.WebApi.JobLeet.Core.Interfaces.Common.V1;
Expand All @@ -10,8 +9,8 @@ namespace JobLeet.WebApi.JobLeet.Api.Controllers.Common.V1
[Route("api/v1/skills")]
public class SkillController : BaseApiController<Skill, SkillModel, ISkillService>
{
public SkillController(ISkillService skillService, ILoggerManagerV1 logger, IValidator<Skill> validator)
: base(skillService, logger, validator)
public SkillController(ISkillService skillService, IValidator<Skill> validator)
: base(skillService, validator)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using FluentValidation;
using JobLeet.WebApi.JobLeet.Api.Logging;
using JobLeet.WebApi.JobLeet.Api.Models.Companies.V1;
using JobLeet.WebApi.JobLeet.Core.Entities.Companies.V1;
using JobLeet.WebApi.JobLeet.Core.Interfaces.Companies.V1;
Expand All @@ -10,8 +9,8 @@ namespace JobLeet.WebApi.JobLeet.Api.Controllers.Companies.V1
[Route("api/v1/companies")]
public class CompanyController : BaseApiController<Company, CompanyModel, ICompanyService>
{
public CompanyController(ICompanyService companyService, ILoggerManagerV1 logger, IValidator<Company> validator)
: base(companyService, logger, validator)
public CompanyController(ICompanyService companyService, IValidator<Company> validator)
: base(companyService, validator)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using FluentValidation;
using JobLeet.WebApi.JobLeet.Api.Logging;
using JobLeet.WebApi.JobLeet.Api.Models.Companies.V1;
using JobLeet.WebApi.JobLeet.Core.Entities.Companies.V1;
using JobLeet.WebApi.JobLeet.Core.Interfaces.Companies.V1;
Expand All @@ -10,8 +9,8 @@ namespace JobLeet.WebApi.JobLeet.Api.Controllers.Companies.V1
[Route("api/v1/industry-types")]
public class IndustryTypeController : BaseApiController<Industry, IndustryModel, IIndustryTypeService>
{
public IndustryTypeController(IIndustryTypeService industryTypeService, ILoggerManagerV1 logger, IValidator<Industry> validator)
: base(industryTypeService, logger, validator)
public IndustryTypeController(IIndustryTypeService industryTypeService, IValidator<Industry> validator)
: base(industryTypeService, validator)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using JobLeet.WebApi.JobLeet.Api.Logging;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

Expand All @@ -13,8 +12,8 @@ namespace JobLeet.WebApi.JobLeet.Api.Controllers.Job.V1
[Route("api/v1/employers")]
public class EmployerController : BaseApiController<Employer, EmployerModel, IEmployerService>
{
public EmployerController(IEmployerService employerService, ILoggerManagerV1 logger, IValidator<Employer> validator)
: base(employerService, logger, validator)
public EmployerController(IEmployerService employerService, IValidator<Employer> validator)
: base(employerService, validator)
{

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using FluentValidation;
using JobLeet.WebApi.JobLeet.Api.Logging;
using JobLeet.WebApi.JobLeet.Api.Models.Jobs.V1;
using JobLeet.WebApi.JobLeet.Core.Entities.Jobs.V1;
using JobLeet.WebApi.JobLeet.Core.Interfaces.Jobs.V1;
Expand All @@ -11,8 +10,8 @@ namespace JobLeet.WebApi.JobLeet.Api.Controllers.Job.V1
[ApiController]
public class ApplicationController : BaseApiController<Application, ApplicationModel, IApplicationService>
{
public ApplicationController(IApplicationService applicationService, ILoggerManagerV1 logger, IValidator<Application> validator)
: base(applicationService, logger, validator)
public ApplicationController(IApplicationService applicationService, IValidator<Application> validator)
: base(applicationService, validator)
{

}
Expand All @@ -22,16 +21,12 @@ public async Task<IActionResult> ApplyForJobAsync([FromQuery] int seekerId, [Fro
{
try
{
_logger.LogInfo($"Seeker {seekerId} is applying for job {jobId} at company {companyId}.");


var application = await _service.ApplyForJobAsync(seekerId, jobId, companyId);

return Ok(application);
}
catch (Exception ex)
{
_logger.LogError($"Error occurred while applying for a job: {ex.Message}");
return StatusCode(500, new
{
Error = "Internal Server Error",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using FluentValidation;
using JobLeet.WebApi.JobLeet.Api.Logging;
using JobLeet.WebApi.JobLeet.Api.Models.Jobs.V1;
using JobLeet.WebApi.JobLeet.Core.Entities.Jobs.V1;
using JobLeet.WebApi.JobLeet.Core.Interfaces.Jobs.V1;
Expand All @@ -11,8 +10,8 @@ namespace JobLeet.WebApi.JobLeet.Api.Controllers.Job.V1
[ApiController]
public class JobController : BaseApiController<JobEntity, JobModel, IJobService>
{
public JobController(IJobService jobService, ILoggerManagerV1 logger, IValidator<JobEntity> validator)
: base(jobService, logger, validator)
public JobController(IJobService jobService, IValidator<JobEntity> validator)
: base(jobService, validator)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ namespace JobLeet.WebApi.JobLeet.Api.Controllers.Job.V1
[Route("api/v1/seekers")]
public class SeekersController : BaseApiController<Seeker, SeekerModel, ISeekerService>
{
public SeekersController(ISeekerService seekerService, ILoggerManagerV1 logger, IValidator<Seeker> validator)
: base(seekerService, logger, validator)
public SeekersController(ISeekerService seekerService,IValidator<Seeker> validator)
: base(seekerService, validator)
{
}
}
Expand Down

0 comments on commit a9d469b

Please sign in to comment.