-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Crud job applications (without files)
- Loading branch information
Showing
23 changed files
with
453 additions
and
6 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
skit.API/Controllers/Areas/CompanyOwner/C_JobApplicationsController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using skit.API.Attributes; | ||
using skit.Application.JobApplications.Commands.DeleteJobApplication; | ||
using skit.Application.JobApplications.Commands.UpdateJobApplication; | ||
using skit.Application.JobApplications.Queries.BrowseJobApplications; | ||
using skit.Application.JobApplications.Queries.GetJobApplication; | ||
using skit.Core.Identity.Static; | ||
using skit.Shared.Responses; | ||
|
||
namespace skit.API.Controllers.Areas.CompanyOwner; | ||
|
||
[Route($"{Endpoints.BaseUrl}/jobApplications")] | ||
[ApiAuthorize(Roles = UserRoles.CompanyOwner)] | ||
public sealed class C_JobApplicationsController : BaseController | ||
{ | ||
/// <summary> | ||
/// Browse job applications | ||
/// </summary> | ||
[HttpGet] | ||
[ProducesResponseType(StatusCodes.Status200OK)] | ||
public async Task<ActionResult<BrowseJobApplicationsResponse>> BrowseJobApplications( | ||
[FromQuery] BrowseJobApplicationsQuery query, CancellationToken cancellationToken = default) | ||
{ | ||
var response = await Mediator.Send(query, cancellationToken); | ||
return Ok(response); | ||
} | ||
|
||
/// <summary> | ||
/// Get job application by id | ||
/// </summary> | ||
[HttpGet("{jobApplicationId:guid}")] | ||
[ProducesResponseType(StatusCodes.Status200OK)] | ||
[ProducesResponseType(StatusCodes.Status404NotFound)] | ||
public async Task<ActionResult<GetJobApplicationResponse>> GetJobApplication([FromRoute] Guid jobApplicationId, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
var response = await Mediator.Send(new GetJobApplicationQuery(jobApplicationId), cancellationToken); | ||
return OkOrNotFound(response); | ||
} | ||
|
||
/// <summary> | ||
/// Update job application | ||
/// </summary> | ||
[HttpPut("{jobApplicationId::guid}")] | ||
[ProducesResponseType(StatusCodes.Status200OK)] | ||
[ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
public async Task<ActionResult<CreateOrUpdateResponse>> UpdateJobApplication([FromRoute] Guid jobApplicationId, | ||
[FromBody] UpdateJobApplicationCommand command, CancellationToken cancellationToken = default) | ||
{ | ||
var response = await Mediator.Send(command with {JobApplicationId = jobApplicationId}, cancellationToken); | ||
return Ok(response); | ||
} | ||
|
||
/// <summary> | ||
/// Delete job application | ||
/// </summary> | ||
[HttpDelete("{jobApplicationId::guid}")] | ||
[ProducesResponseType(StatusCodes.Status200OK)] | ||
[ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
public async Task<IActionResult> DeleteJobApplication([FromRoute] Guid jobApplicationId, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
await Mediator.Send(new DeleteJobApplicationCommand(jobApplicationId), cancellationToken); | ||
return Ok(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
skit.API/Controllers/Areas/Public/P_JobApplicationsController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc; | ||
using skit.Application.JobApplications.Commands.CreateJobApplication; | ||
using skit.Application.JobApplications.Commands.UpdateJobApplication; | ||
using skit.Shared.Responses; | ||
|
||
namespace skit.API.Controllers.Areas.Public; | ||
|
||
[AllowAnonymous] | ||
[Route($"{Endpoints.BasePublicUrl}/jobApplications")] | ||
public sealed class P_JobApplicationsController : BaseController | ||
{ | ||
/// <summary> | ||
/// Create application | ||
/// </summary> | ||
[HttpPost] | ||
[ProducesResponseType(StatusCodes.Status201Created)] | ||
[ProducesResponseType(StatusCodes.Status400BadRequest)] | ||
public async Task<ActionResult<CreateOrUpdateResponse>> CreateJobApplication([FromBody] CreateJobApplicationCommand command, | ||
CancellationToken cancellationToken = default) | ||
{ | ||
var response = await Mediator.Send(command, cancellationToken); | ||
return Created(string.Empty, response); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
....Application/JobApplications/Commands/CreateJobApplication/CreateJobApplicationCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using MediatR; | ||
using skit.Shared.Responses; | ||
|
||
namespace skit.Application.JobApplications.Commands.CreateJobApplication; | ||
|
||
public sealed record CreateJobApplicationCommand( | ||
Guid OfferId, | ||
string FirstName, | ||
string SurName, | ||
string? Description) : IRequest<CreateOrUpdateResponse>; |
36 changes: 36 additions & 0 deletions
36
....Application/JobApplications/Commands/CreateJobApplication/CreateJobApplicationHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using MediatR; | ||
using skit.Core.JobApplications.Entities; | ||
using skit.Core.JobApplications.Repositories; | ||
using skit.Core.Offers.Exceptions; | ||
using skit.Core.Offers.Repositories; | ||
using skit.Shared.Responses; | ||
|
||
namespace skit.Application.JobApplications.Commands.CreateJobApplication; | ||
|
||
internal sealed class CreateJobApplicationHandler : IRequestHandler<CreateJobApplicationCommand, CreateOrUpdateResponse> | ||
{ | ||
private readonly IOfferRepository _offerRepository; | ||
private readonly IJobApplicationRepository _jobApplicationRepository; | ||
|
||
public CreateJobApplicationHandler(IOfferRepository offerRepository, IJobApplicationRepository jobApplicationRepository) | ||
{ | ||
_offerRepository = offerRepository; | ||
_jobApplicationRepository = jobApplicationRepository; | ||
} | ||
|
||
public async Task<CreateOrUpdateResponse> Handle(CreateJobApplicationCommand request, CancellationToken cancellationToken) | ||
{ | ||
var offer = await _offerRepository.GetAsync(request.OfferId, cancellationToken) | ||
?? throw new OfferNotFoundException(); | ||
|
||
var jobApplication = JobApplication.Create( | ||
request.FirstName, | ||
request.SurName, | ||
request.Description, | ||
offer.Id); | ||
|
||
var entityId = await _jobApplicationRepository.AddAsync(jobApplication, cancellationToken); | ||
|
||
return new CreateOrUpdateResponse(entityId); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
....Application/JobApplications/Commands/DeleteJobApplication/DeleteJobApplicationCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using MediatR; | ||
|
||
namespace skit.Application.JobApplications.Commands.DeleteJobApplication; | ||
|
||
public sealed record DeleteJobApplicationCommand(Guid JobApplicationId) : IRequest; |
36 changes: 36 additions & 0 deletions
36
....Application/JobApplications/Commands/DeleteJobApplication/DeleteJobApplicationHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using MediatR; | ||
using skit.Core.Common.Services; | ||
using skit.Core.JobApplications.Exceptions; | ||
using skit.Core.JobApplications.Repositories; | ||
using skit.Core.Offers.Exceptions; | ||
using skit.Core.Offers.Repositories; | ||
|
||
namespace skit.Application.JobApplications.Commands.DeleteJobApplication; | ||
|
||
internal sealed class DeleteJobApplicationHandler : IRequestHandler<DeleteJobApplicationCommand> | ||
{ | ||
private readonly IJobApplicationRepository _jobApplicationRepository; | ||
private readonly IOfferRepository _offerRepository; | ||
private readonly ICurrentUserService _currentUserService; | ||
|
||
public DeleteJobApplicationHandler(IJobApplicationRepository jobApplicationRepository, IOfferRepository offerRepository, ICurrentUserService currentUserService) | ||
{ | ||
_jobApplicationRepository = jobApplicationRepository; | ||
_offerRepository = offerRepository; | ||
_currentUserService = currentUserService; | ||
} | ||
|
||
public async Task Handle(DeleteJobApplicationCommand request, CancellationToken cancellationToken) | ||
{ | ||
var jobApplication = await _jobApplicationRepository.GetAsync(request.JobApplicationId, cancellationToken) | ||
?? throw new JobApplicationNotFoundException(); | ||
|
||
var offer = await _offerRepository.GetAsync(jobApplication.OfferId, cancellationToken) | ||
?? throw new OfferNotFoundException(); | ||
|
||
if (offer.CompanyId != _currentUserService.CompanyId) | ||
throw new JobApplicationNotFoundException(); | ||
|
||
await _jobApplicationRepository.DeleteAsync(jobApplication, cancellationToken); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
....Application/JobApplications/Commands/UpdateJobApplication/UpdateJobApplicationCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using MediatR; | ||
using skit.Shared.Responses; | ||
|
||
namespace skit.Application.JobApplications.Commands.UpdateJobApplication; | ||
|
||
public record UpdateJobApplicationCommand | ||
(string FirstName, string SurName, string? Description) : IRequest<CreateOrUpdateResponse> | ||
{ | ||
internal Guid JobApplicationId { get; init; } | ||
} |
44 changes: 44 additions & 0 deletions
44
....Application/JobApplications/Commands/UpdateJobApplication/UpdateJobApplicationHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using MediatR; | ||
using skit.Core.Common.Services; | ||
using skit.Core.JobApplications.Exceptions; | ||
using skit.Core.JobApplications.Repositories; | ||
using skit.Core.Offers.Exceptions; | ||
using skit.Core.Offers.Repositories; | ||
using skit.Shared.Responses; | ||
|
||
namespace skit.Application.JobApplications.Commands.UpdateJobApplication; | ||
|
||
internal sealed class UpdateJobApplicationHandler : IRequestHandler<UpdateJobApplicationCommand, CreateOrUpdateResponse> | ||
{ | ||
private readonly IJobApplicationRepository _jobApplicationRepository; | ||
private readonly IOfferRepository _offerRepository; | ||
private readonly ICurrentUserService _currentUserService; | ||
|
||
public UpdateJobApplicationHandler(IJobApplicationRepository jobApplicationRepository, IOfferRepository offerRepository, ICurrentUserService currentUserService) | ||
{ | ||
_jobApplicationRepository = jobApplicationRepository; | ||
_offerRepository = offerRepository; | ||
_currentUserService = currentUserService; | ||
} | ||
|
||
public async Task<CreateOrUpdateResponse> Handle(UpdateJobApplicationCommand request, CancellationToken cancellationToken) | ||
{ | ||
var jobApplication = await _jobApplicationRepository.GetAsync(request.JobApplicationId, cancellationToken) | ||
?? throw new JobApplicationNotFoundException(); | ||
|
||
var offer = await _offerRepository.GetAsync(jobApplication.OfferId, cancellationToken) | ||
?? throw new OfferNotFoundException(); | ||
|
||
if (offer.CompanyId != _currentUserService.CompanyId) | ||
throw new JobApplicationNotFoundException(); | ||
|
||
jobApplication.Update( | ||
request.FirstName, | ||
request.SurName, | ||
request.Description); | ||
|
||
var resultId = await _jobApplicationRepository.UpdateAsync(jobApplication, cancellationToken); | ||
|
||
return new CreateOrUpdateResponse(resultId); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
skit.Application/JobApplications/Queries/BrowseJobApplications/BrowseJobApplicationsQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using MediatR; | ||
|
||
namespace skit.Application.JobApplications.Queries.BrowseJobApplications; | ||
|
||
public sealed record BrowseJobApplicationsQuery(string? Search) : IRequest<BrowseJobApplicationsResponse>; |
5 changes: 5 additions & 0 deletions
5
...pplication/JobApplications/Queries/BrowseJobApplications/BrowseJobApplicationsResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using skit.Application.JobApplications.Queries.DTO; | ||
|
||
namespace skit.Application.JobApplications.Queries.BrowseJobApplications; | ||
|
||
public sealed record BrowseJobApplicationsResponse(List<JobApplicationDto> JobApplicationDto); |
9 changes: 9 additions & 0 deletions
9
skit.Application/JobApplications/Queries/DTO/JobApplicationDetailsDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace skit.Application.JobApplications.Queries.DTO; | ||
|
||
public sealed class JobApplicationDetailsDto | ||
{ | ||
public Guid Id { get; set; } | ||
public string FirstName { get; set; } | ||
public string SurName { get; set; } | ||
public string? Description { get; set; } | ||
} |
8 changes: 8 additions & 0 deletions
8
skit.Application/JobApplications/Queries/DTO/JobApplicationDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace skit.Application.JobApplications.Queries.DTO; | ||
|
||
public sealed class JobApplicationDto | ||
{ | ||
public Guid Id { get; set; } | ||
public string FirstName { get; set; } | ||
public string SurName { get; set; } | ||
} |
5 changes: 5 additions & 0 deletions
5
skit.Application/JobApplications/Queries/GetJobApplication/GetJobApplicationQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using MediatR; | ||
|
||
namespace skit.Application.JobApplications.Queries.GetJobApplication; | ||
|
||
public sealed record GetJobApplicationQuery(Guid JobApplicationId) : IRequest<GetJobApplicationResponse>; |
5 changes: 5 additions & 0 deletions
5
skit.Application/JobApplications/Queries/GetJobApplication/GetJobApplicationResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using skit.Application.JobApplications.Queries.DTO; | ||
|
||
namespace skit.Application.JobApplications.Queries.GetJobApplication; | ||
|
||
public sealed record GetJobApplicationResponse(JobApplicationDetailsDto? JobApplicationDto); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
skit.Core/JobApplications/Exceptions/JobApplicationNotFoundException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using skit.Shared.Abstractions.Exceptions; | ||
|
||
namespace skit.Core.JobApplications.Exceptions; | ||
|
||
public sealed class JobApplicationNotFoundException : SkitException | ||
{ | ||
public JobApplicationNotFoundException() : base("JobApplication not found") { } | ||
} |
11 changes: 11 additions & 0 deletions
11
skit.Core/JobApplications/Repositories/IJobApplicationRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using skit.Core.JobApplications.Entities; | ||
|
||
namespace skit.Core.JobApplications.Repositories; | ||
|
||
public interface IJobApplicationRepository | ||
{ | ||
public Task<Guid> AddAsync(JobApplication jobApplication, CancellationToken cancellationToken); | ||
public Task<JobApplication?> GetAsync(Guid jobApplicationId, CancellationToken cancellationToken); | ||
public Task<Guid> UpdateAsync(JobApplication jobApplication, CancellationToken cancellationToken); | ||
public Task DeleteAsync(JobApplication jobApplication, CancellationToken cancellationToken); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.