Skip to content

Commit

Permalink
[Contracts management][Duy] Cancel contract
Browse files Browse the repository at this point in the history
  • Loading branch information
duykasama committed Mar 20, 2024
1 parent e52c5d1 commit 7826238
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
17 changes: 11 additions & 6 deletions Domus.Api/Controllers/ContractController.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using System.Diagnostics.Contracts;
using Domus.Api.Controllers.Base;
using Domus.Api.Controllers.Base;
using Domus.Service.Constants;
using Domus.Service.Interfaces;
using Domus.Service.Models.Common;
using Domus.Service.Models.Requests.Base;
using Domus.Service.Models.Requests.Contracts;
using Domus.Service.Models.Requests.Products;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Contract = Domus.Domain.Entities.Contract;

namespace Domus.Api.Controllers;

Expand Down Expand Up @@ -130,12 +127,20 @@ public async Task<IActionResult> GetMyContract()
return await ExecuteServiceLogic( async () => await _contractService.GetUsersContract(GetJwtToken())
).ConfigureAwait(false);
}

[HttpGet("my-contract/search")]

public async Task<IActionResult> SearchMyContractsUsingGetRequest([FromQuery] SearchUsingGetRequest request)
{
return await ExecuteServiceLogic(
async () => await _contractService.SearchMyContractsUsingGet(request, GetJwtToken()).ConfigureAwait(false)
).ConfigureAwait(false);
}
}

[HttpGet("cancel/{contractId:guid}")]
public async Task<IActionResult> CancelContract(Guid contractId)
{
return await ExecuteServiceLogic(
async () => await _contractService.CancelContract(contractId).ConfigureAwait(false)
).ConfigureAwait(false);
}
}
14 changes: 11 additions & 3 deletions Domus.Service/Implementations/ContractService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,11 @@
using Domus.Service.Exceptions;
using Domus.Service.Interfaces;
using Domus.Service.Models;
using Domus.Service.Models.Common;
using Domus.Service.Models.Email;
using Domus.Service.Models.Requests.Base;
using Domus.Service.Models.Requests.Contracts;
using Domus.Service.Models.Requests.Products;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore;
using UnauthorizedAccessException = Domus.Service.Exceptions.UnauthorizedAccessException;

Expand Down Expand Up @@ -403,4 +400,15 @@ private async Task ValidateContractRequest(ContractRequest request)
if (!contractorRoles.Contains(UserRoleConstants.STAFF))
throw new UnauthorizedAccessException($"Unauthorized ContractorId: {request.ContractorId}");
}

public async Task<ServiceActionResult> CancelContract(Guid contractId)
{
var contract = await _contractRepository.GetAsync(x => x.Id == contractId && !x.IsDeleted) ?? throw new Exception($"Not found contract: {contractId}");
contract.Status = ContractStatus.CANCELED;

await _contractRepository.UpdateAsync(contract);
await _unitOfWork.CommitAsync();

return new ServiceActionResult(true);
}
}
6 changes: 2 additions & 4 deletions Domus.Service/Interfaces/IContractService.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using Domus.Common.Interfaces;
using Domus.Domain.Entities;
using Domus.Service.Models;
using Domus.Service.Models.Requests.Base;
using Domus.Service.Models.Requests.Contracts;
using Domus.Service.Models.Requests.OfferedPackages;
using Domus.Service.Models.Requests.Products;
using Microsoft.AspNetCore.Http;

namespace Domus.Service.Interfaces;

Expand All @@ -26,4 +23,5 @@ public interface IContractService : IAutoRegisterable
Task<ServiceActionResult> SignContract(Guid contractId, SignedContractRequest request);
Task<ServiceActionResult> GetUsersContract(string token);
Task<ServiceActionResult> SearchMyContractsUsingGet(SearchUsingGetRequest request, string token);
}
Task<ServiceActionResult> CancelContract(Guid contractId);
}

0 comments on commit 7826238

Please sign in to comment.