Skip to content

Commit

Permalink
Resolves #1057 Web API: add endpoints for WalletHistory entity
Browse files Browse the repository at this point in the history
  • Loading branch information
mgesing committed Apr 9, 2024
1 parent 80da2d9 commit f6d9b42
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 3 deletions.
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
- Fixed *boxed titles* spacing and line-height issues
- Web API
- Enabling CORS.
- #928 mask the secret key in backend API user list.
- #928 mask the secret key in backend API user list.
- #1057 add endpoints for `WalletHistory` entity.
- Security
- #886 Replace CoreFTP with FluentFTP.
- #1004 Add captcha to password recovery form.
Expand Down
1 change: 0 additions & 1 deletion src/Smartstore.Core/Checkout/Orders/Domain/Order.cs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,6 @@ public Address ShippingAddress
/// <summary>
/// Gets or sets the wallet history.
/// </summary>
[IgnoreDataMember]
public ICollection<WalletHistory> WalletHistory
{
get => _walletHistory ?? LazyLoader.Load(this, ref _walletHistory) ?? (_walletHistory ??= new HashSet<WalletHistory>());
Expand Down
1 change: 0 additions & 1 deletion src/Smartstore.Core/Platform/Identity/Domain/Customer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ public ICollection<RewardPointsHistory> RewardPointsHistory
/// <summary>
/// Gets or sets the wallet history.
/// </summary>
[IgnoreDataMember]
public ICollection<WalletHistory> WalletHistory
{
get => _walletHistory ?? LazyLoader.Load(this, ref _walletHistory) ?? (_walletHistory ??= new HashSet<WalletHistory>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ public SingleResult<Address> GetShippingAddress(int key)
return GetRelatedEntity(key, x => x.ShippingAddress);
}

[HttpGet("Orders({key})/WalletHistory"), ApiQueryable]
[Permission("Wallet.read")]
public IQueryable<WalletHistory> GetWalletHistory(int key)
{
return GetRelatedQuery(key, x => x.WalletHistory);
}

[HttpGet("Orders({key})/DiscountUsageHistory"), ApiQueryable]
[Permission(Permissions.Promotion.Discount.Read)]
public IQueryable<DiscountUsageHistory> GetDiscountUsageHistory(int key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ public IQueryable<Order> GetOrders(int key)
return GetRelatedQuery(key, x => x.Orders);
}

[HttpGet("Customers({key})/WalletHistory"), ApiQueryable]
[Permission("Wallet.read")]
public IQueryable<WalletHistory> GetWalletHistory(int key)
{
return GetRelatedQuery(key, x => x.WalletHistory);
}

[HttpGet("Customers({key})/ReturnRequests"), ApiQueryable]
[Permission(Permissions.Order.ReturnRequest.Read)]
public IQueryable<ReturnRequest> GetReturnRequests(int key)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using Smartstore.Core.Checkout.Orders;
using Smartstore.Core.Identity;

namespace Smartstore.Web.Api.Controllers
{
/// <summary>
/// The endpoint for operations on WalletHistory entity.
/// </summary>
public class WalletHistoryController : WebApiController<WalletHistory>
{
[HttpGet("WalletHistory"), ApiQueryable]
[Permission("Wallet.read")]
public IQueryable<WalletHistory> Get()
{
return Entities.AsNoTracking();
}

[HttpGet("WalletHistory({key})"), ApiQueryable]
[Permission("Wallet.read")]
public SingleResult<WalletHistory> Get(int key)
{
return GetById(key);
}

[HttpGet("WalletHistory({key})/Customer"), ApiQueryable]
[Permission(Permissions.Customer.Read)]
public SingleResult<Customer> GetCustomer(int key)
{
return GetRelatedEntity(key, x => x.Customer);
}

[HttpGet("WalletHistory({key})/Order"), ApiQueryable]
[Permission(Permissions.Order.Read)]
public SingleResult<Order> GetOrder(int key)
{
return GetRelatedEntity(key, x => x.Order);
}

[HttpPost]
[Permission("Wallet.create")]
public Task<IActionResult> Post([FromBody] WalletHistory model)
{
return PostAsync(model);
}

[HttpPut]
[Permission("Wallet.update")]
public Task<IActionResult> Put(int key, Delta<WalletHistory> model)
{
return PutAsync(key, model);
}

[HttpPatch]
[Permission("Wallet.update")]
public Task<IActionResult> Patch(int key, Delta<WalletHistory> model)
{
return PatchAsync(key, model);
}

[HttpDelete]
[Permission("Wallet.delete")]
public Task<IActionResult> Delete(int key)
{
return DeleteAsync(key);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public override void Build(ODataModelBuilder builder, int version)
builder.EntitySet<TaxCategory>("TaxCategories");
builder.EntitySet<TierPrice>("TierPrices");
builder.EntitySet<UrlRecord>("UrlRecords");
builder.EntitySet<WalletHistory>("WalletHistory");

// INFO: functions specified directly on the ODataModelBuilder (instead of entity type or collection)
// are called unbound functions (like static operations on the service).
Expand Down

0 comments on commit f6d9b42

Please sign in to comment.