Skip to content

Commit

Permalink
psp-7909 take ui refactor. (#3980)
Browse files Browse the repository at this point in the history
* psp-7909 take ui refactor.

* psp-8145

* correct invalid type.

* code review corrections.

* merge corrections.
  • Loading branch information
devinleighsmith authored May 1, 2024
1 parent 11d9656 commit 5a15dcd
Show file tree
Hide file tree
Showing 38 changed files with 4,652 additions and 994 deletions.
115 changes: 108 additions & 7 deletions source/backend/api/Areas/Takes/Controllers/TakeController.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MapsterMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Pims.Api.Helpers.Exceptions;
using Pims.Api.Models.Concepts.Take;
using Pims.Api.Policies;
using Pims.Api.Services;
using Pims.Core.Extensions;
using Pims.Core.Json;
using Pims.Dal.Entities;
using Pims.Dal.Exceptions;
using Pims.Dal.Security;
using Swashbuckle.AspNetCore.Annotations;

Expand Down Expand Up @@ -104,28 +107,98 @@ public IActionResult GetTakesByPropertyId([FromRoute] long fileId, [FromRoute] l
}

/// <summary>
/// Update the list of takes associated to a property within an acquisition file.
/// Add the passed take to the acquisition property with the given id.
/// </summary>
/// <returns></returns>
[HttpPut("acquisition/property/{acquisitionFilePropertyId:long}")]
[HttpPost("acquisition/property/{acquisitionFilePropertyId:long}/takes")]
[HasPermission(Permissions.AcquisitionFileEdit, Permissions.PropertyEdit)]
[Produces("application/json")]
[ProducesResponseType(typeof(IEnumerable<TakeModel>), 200)]
[ProducesResponseType(typeof(TakeModel), 201)]
[SwaggerOperation(Tags = new[] { "take" })]
[TypeFilter(typeof(NullJsonResultFilter))]
public IActionResult AddAcquisitionPropertyTake(long acquisitionFilePropertyId, [FromBody] TakeModel take)
{
_logger.LogInformation(
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}",
nameof(TakeController),
nameof(AddAcquisitionPropertyTake),
User.GetUsername(),
DateTime.Now);

if (acquisitionFilePropertyId != take.PropertyAcquisitionFileId)
{
throw new BadRequestException("Invalid acquisition file property id.");
}

_logger.LogInformation("Dispatching to service: {Service}", _takeService.GetType());

var addedTake = _takeService.AddAcquisitionPropertyTake(acquisitionFilePropertyId, _mapper.Map<PimsTake>(take));
return new JsonResult(_mapper.Map<TakeModel>(addedTake));
}

/// <summary>
/// Update a take with the given take and acquisition file property id with the passed take.
/// </summary>
/// <returns></returns>
[HttpPut("acquisition/property/{acquisitionFilePropertyId:long}/takes/{takeId:long}")]
[HasPermission(Permissions.AcquisitionFileEdit, Permissions.PropertyEdit)]
[Produces("application/json")]
[ProducesResponseType(typeof(TakeModel), 200)]
[SwaggerOperation(Tags = new[] { "take" })]
[TypeFilter(typeof(NullJsonResultFilter))]
public IActionResult UpdateAcquisitionPropertyTakes(long acquisitionFilePropertyId, [FromBody] IEnumerable<TakeModel> takes)
public IActionResult UpdateAcquisitionPropertyTake(long acquisitionFilePropertyId, long takeId, [FromBody] TakeModel take)
{
_logger.LogInformation(
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}",
nameof(TakeController),
nameof(UpdateAcquisitionPropertyTakes),
nameof(UpdateAcquisitionPropertyTake),
User.GetUsername(),
DateTime.Now);

if (acquisitionFilePropertyId != take.PropertyAcquisitionFileId)
{
throw new BadRequestException("Invalid acquisition file property id.");
}
else if (takeId != take.Id)
{
throw new BadRequestException("Invalid take id.");
}

_logger.LogInformation("Dispatching to service: {Service}", _takeService.GetType());

var updatedTakes = _takeService.UpdateAcquisitionPropertyTakes(acquisitionFilePropertyId, _mapper.Map<IEnumerable<PimsTake>>(takes));
return new JsonResult(_mapper.Map<IEnumerable<TakeModel>>(updatedTakes));
var updatedTake = _takeService.UpdateAcquisitionPropertyTake(acquisitionFilePropertyId, _mapper.Map<PimsTake>(take));
return new JsonResult(_mapper.Map<TakeModel>(updatedTake));
}

/// <summary>
/// Delete a take with the given take id and acquisition file property id.
/// </summary>
[HttpDelete("acquisition/property/{acquisitionFilePropertyId:long}/takes/{takeId:long}")]
[HasPermission(Permissions.AcquisitionFileEdit, Permissions.PropertyEdit)]
[Produces("application/json")]
[ProducesResponseType(typeof(void), 200)]
[SwaggerOperation(Tags = new[] { "take" })]
[TypeFilter(typeof(NullJsonResultFilter))]
public void DeleteAcquisitionPropertyTake(long acquisitionFilePropertyId, long takeId, [FromQuery] string[] userOverrideCodes)
{
_logger.LogInformation(
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}",
nameof(TakeController),
nameof(DeleteAcquisitionPropertyTake),
User.GetUsername(),
DateTime.Now);

_logger.LogInformation("Dispatching to service: {Service}", _takeService.GetType());
var existingTake = _takeService.GetById(takeId);
if (existingTake.PropertyAcquisitionFileId != acquisitionFilePropertyId)
{
throw new BadRequestException("Invalid acquisition file property id.");
}
var deleted = _takeService.DeleteAcquisitionPropertyTake(takeId, userOverrideCodes.Select(oc => UserOverrideCode.Parse(oc)));
if (!deleted)
{
throw new InvalidOperationException($"Failed to delete take {takeId}.");
}
}

/// <summary>
Expand All @@ -152,6 +225,34 @@ public IActionResult GetTakesCountByPropertyId([FromRoute] long propertyId)
return new JsonResult(count);
}

/// <summary>
/// GGet a take by id.
/// </summary>
/// <returns></returns>
[HttpGet("acquisition/property/{acquisitionFilePropertyId:long}/takes/{takeId:long}")]
[HasPermission(Permissions.AcquisitionFileView, Permissions.PropertyView)]
[Produces("application/json")]
[ProducesResponseType(typeof(int), 200)]
[SwaggerOperation(Tags = new[] { "take" })]
public IActionResult GetTakeByPropertyFileId(long acquisitionFilePropertyId, long takeId)
{
_logger.LogInformation(
"Request received by Controller: {Controller}, Action: {ControllerAction}, User: {User}, DateTime: {DateTime}",
nameof(TakeController),
nameof(GetTakesCountByPropertyId),
User.GetUsername(),
DateTime.Now);

_logger.LogInformation("Dispatching to service: {Service}", _takeService.GetType());

var take = _takeService.GetById(takeId);
if(take.PropertyAcquisitionFileId != acquisitionFilePropertyId)
{
throw new BadRequestException("Invalid acquisition file property id.");
}
return new JsonResult(_mapper.Map<TakeModel>(take));
}

#endregion
}
}
12 changes: 10 additions & 2 deletions source/backend/api/Services/ITakeService.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
using System.Collections.Generic;
using Pims.Dal.Entities;
using Pims.Dal.Exceptions;

namespace Pims.Api.Services
{
public interface ITakeService
{

PimsTake GetById(long takeId);

PimsTake AddAcquisitionPropertyTake(long acquisitionFilePropertyId, PimsTake take);

PimsTake UpdateAcquisitionPropertyTake(long acquisitionFilePropertyId, PimsTake take);

bool DeleteAcquisitionPropertyTake(long takeId, IEnumerable<UserOverrideCode> userOverrides);

IEnumerable<PimsTake> GetByFileId(long fileId);

IEnumerable<PimsTake> GetByPropertyId(long fileId, long acquisitionFilePropertyId);

int GetCountByPropertyId(long propertyId);

IEnumerable<PimsTake> UpdateAcquisitionPropertyTakes(long acquisitionFilePropertyId, IEnumerable<PimsTake> takes);
}
}
Loading

0 comments on commit 5a15dcd

Please sign in to comment.