update
This commit is contained in:
@@ -7,8 +7,6 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Models.Account;
|
||||
using Models.Motion;
|
||||
using MyOffice.Data.Models.Accounts;
|
||||
using MyOffice.Web.Models.AccountMotion;
|
||||
using Services.Account;
|
||||
using Services.Account.Domain;
|
||||
|
||||
@@ -59,7 +57,7 @@ public class AccountController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpGet("~/api/accounts/{id}/motions")]
|
||||
public object AccountMotionsGet(string id, [FromQuery] AccountMotionsGetModel request)
|
||||
public object MotionsGet(string id, [FromQuery] MotionsGetModel request)
|
||||
{
|
||||
var exec = _accountService.GetMotions(UserId, id!.AsGuid(), request.From.StartOfDay(), request.To.EndOfDay());
|
||||
|
||||
@@ -78,7 +76,7 @@ public class AccountController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpPost("~/api/accounts/{id}/motions")]
|
||||
public object AccountsMotionsPost(string id, MotionRequest motion)
|
||||
public object MotionsPost(string id, MotionRequest motion)
|
||||
{
|
||||
var exec = _accountService.MotionAdd(UserId, id.AsGuid(), motion.FromModel());
|
||||
|
||||
@@ -95,4 +93,42 @@ public class AccountController : BaseApiController
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPut("~/api/accounts/{id}/motions/{motionId}")]
|
||||
public object MotionsPut(string id, string motionId, MotionRequest motion)
|
||||
{
|
||||
var exec = _accountService.MotionUpdate(UserId, id.AsGuid(), motionId.AsGuid(), motion.FromModel());
|
||||
|
||||
switch (exec.Status)
|
||||
{
|
||||
case MotionUpdateResult.not_found:
|
||||
return ProblemBadRequest("Motion not found.");
|
||||
case MotionUpdateResult.failure:
|
||||
return ProblemBadRequest("Updating motion failed.");
|
||||
case MotionUpdateResult.success:
|
||||
return exec.Result!.ToModel();
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete("~/api/accounts/{id}/motions/{motionId}")]
|
||||
public object MotionsDelete(string id, string motionId)
|
||||
{
|
||||
var exec = _accountService.MotionRemove(UserId, id.AsGuid(), motionId.AsGuid());
|
||||
|
||||
switch (exec.Status)
|
||||
{
|
||||
case MotionDeleteResult.not_found:
|
||||
return ProblemBadRequest("Motion not found.");
|
||||
case MotionDeleteResult.failure:
|
||||
return ProblemBadRequest("Deliting motion failed.");
|
||||
case MotionDeleteResult.success:
|
||||
return exec.Result!.ToModel();
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
{
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
public class AccountMotionsGetModel
|
||||
public class MotionsGetModel
|
||||
{
|
||||
[Required]
|
||||
public DateTime From { get; set; }
|
||||
@@ -13,9 +13,9 @@ public class MotionRequest
|
||||
|
||||
public static class MotionRequestExtension
|
||||
{
|
||||
public static MotionAdd FromModel(this MotionRequest input)
|
||||
public static MotionAddUpdate FromModel(this MotionRequest input)
|
||||
{
|
||||
return new MotionAdd
|
||||
return new MotionAddUpdate
|
||||
{
|
||||
Date = input.Date,
|
||||
Motion = input.Motion,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace MyOffice.Web.Models.AccountMotion
|
||||
namespace MyOffice.Web.Models.Motion
|
||||
{
|
||||
using Core.Extensions;
|
||||
using Data.Models.Accounts;
|
||||
|
||||
Reference in New Issue
Block a user