Order

目录

1 Order

1.1 IOrderService

1.2 GetById

1.3 GetByIdAsync

1.4 Delete

  1. Order

using Flatwhite.Core.Tests.Attributes;

using System;

using System.Threading.Tasks;

namespace Flatwhite.Core.Tests

{

public class Order

{

public long Id {get;set;}

public decimal TotalAmount {get;set;}

}

    1. IOrderService

[HandleAllMethodExceptions]

interface IOrderService

{

[FilterAttributeOnInterfaceMethod]

Order GetById(int id);

void Delete(int id);

[FilterAttributeOnInterfaceMethod]

Task GetByIdAsync(int id);

Task DeleteAsync(int id);

}

OrderService 

public class OrderService : IOrderService

{

[ServiceFilter(typeof(FilterAttributeOnClassMethod))]

    1. GetById

public Order GetById(int id)

{

if (id <= 0) throw new ArgumentException("invalid order id");

return new Order {Id = id, TotalAmount = id * DateTime.Now.Ticks};

}

    1. GetByIdAsync

[TypeFilter(typeof(FilterAttributeOnClassMethod))]

public async Task GetByIdAsync(int id)

{

await Task.Delay(10);

return GetById(id);

}

    1. Delete

public void Delete(int id)

{

if (id <= 0) throw new ArgumentException("invalid order id");

if (id > 1000) throw new InvalidOperationException("id not found");

}

public async Task DeleteAsync(int id)

{

await Task.Delay(10);

Delete(id);

}

}

}

你可能感兴趣的:(Flatwhite,java,算法,javascript)