Skip to content

Commit 99637a9

Browse files
committed
Refactor to use better named APIs, tagged services + typed AutoQuery APIs
1 parent 8a66725 commit 99637a9

File tree

14 files changed

+195
-215
lines changed

14 files changed

+195
-215
lines changed

src/Northwind.ServiceInterface/CachedServices.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ namespace Northwind.ServiceInterface
66
[CacheResponse(Duration = 60 * 60, MaxAge = 30 * 60)]
77
public class CachedServices : Service
88
{
9-
public object Get(CachedCustomers request) =>
10-
Gateway.Send(new Customers());
9+
public object Get(CachedGetAllCustomers request) =>
10+
Gateway.Send(new GetAllCustomers());
1111

12-
public object Get(CachedCustomerDetails request) =>
13-
Gateway.Send(new CustomerDetails { Id = request.Id });
12+
public object Get(CachedGetCustomerDetails request) =>
13+
Gateway.Send(new GetCustomerDetails { Id = request.Id });
1414

15-
public object Get(CachedOrders request) =>
16-
Gateway.Send(new Orders { CustomerId = request.CustomerId, Page = request.Page });
15+
public object Get(CachedGetOrders request) =>
16+
Gateway.Send(new GetOrders { CustomerId = request.CustomerId, Page = request.Page });
1717
}
1818
}

src/Northwind.ServiceInterface/CustomerDetailsService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ namespace Northwind.ServiceInterface
99
{
1010
public class CustomerDetailsService : Service
1111
{
12-
public CustomerDetailsResponse Get(CustomerDetails request)
12+
public CustomerDetailsResponse Get(GetCustomerDetails request)
1313
{
1414
var customer = Db.SingleById<Customer>(request.Id);
1515
if (customer == null)
1616
throw new HttpError(HttpStatusCode.NotFound,
1717
new ArgumentException("Customer does not exist: " + request.Id));
1818

19-
var ordersResponse = base.Gateway.Send(new Orders { CustomerId = customer.Id });
19+
var ordersResponse = base.Gateway.Send(new GetOrders { CustomerId = customer.Id });
2020
return new CustomerDetailsResponse
2121
{
2222
Customer = customer,
23-
CustomerOrders = ordersResponse.Results,
23+
Orders = ordersResponse.Results,
2424
};
2525
}
2626
}

src/Northwind.ServiceInterface/CustomersService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Northwind.ServiceInterface
77
{
88
public class CustomersService : Service
99
{
10-
public object Get(Customers request) =>
11-
new CustomersResponse { Customers = Db.Select<Customer>() };
10+
public object Get(GetAllCustomers request) =>
11+
new CustomersResponse { Results = Db.Select<Customer>() };
1212
}
1313
}

src/Northwind.ServiceInterface/OrdersService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class OrdersService : Service
1010
{
1111
private const int PageCount = 20;
1212

13-
public OrdersResponse Get(Orders request)
13+
public OrdersResponse Get(GetOrders request)
1414
{
1515
var orders = request.CustomerId.IsNullOrEmpty()
1616
? Db.Select(Db.From<Order>().OrderByDescending(o => o.OrderDate))

src/Northwind.ServiceInterface/VCardFormat.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static void SerializeToStream(IRequest req, object response, Stream strea
3939
var customers = response as CustomersResponse;
4040
if (customers != null)
4141
{
42-
customers.Customers.ForEach(x => WriteCustomer(sw, x));
42+
customers.Results.ForEach(x => WriteCustomer(sw, x));
4343
}
4444
}
4545
}
Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
using Northwind.ServiceModel.Types;
1+
using System.Collections.Generic;
2+
using Northwind.ServiceModel.Types;
23
using ServiceStack;
34

45
namespace Northwind.ServiceModel
56
{
6-
[Route("/query/customers")]
7-
public class QueryCustomers : QueryDb<Customer> { }
7+
[Route("/query/customers"), Tag(Tags.AutoQuery)]
8+
public class QueryCustomers : QueryDb<Customer>
9+
{
10+
public List<string> Ids { get; set; }
11+
public string CountryStartsWith { get; set; }
12+
}
813

9-
[Route("/query/orders")]
10-
public class QueryOrders : QueryDb<Order> { }
14+
[Route("/query/orders"), Tag(Tags.AutoQuery)]
15+
public class QueryOrders : QueryDb<Order>
16+
{
17+
public decimal? Freight { get; set; }
18+
}
1119
}

src/Northwind.ServiceModel/CachedOperations.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,24 @@
33

44
namespace Northwind.ServiceModel
55
{
6-
[DataContract]
7-
[Route("/cached/customers")]
8-
public class CachedCustomers
9-
{
10-
}
6+
[Route("/cached/customers"), Tag(Tags.Cached)]
7+
public class CachedGetAllCustomers : IReturn<CustomersResponse> {}
118

129
[DataContract]
13-
[Route("/cached/customers/{Id}")]
14-
public class CachedCustomerDetails
10+
[Route("/cached/customers/{Id}"), Tag(Tags.Cached)]
11+
public class CachedGetCustomerDetails : IReturn<CustomerDetailsResponse>
1512
{
1613
[DataMember]
1714
public string Id { get; set; }
1815
}
1916

20-
[DataContract]
17+
[Tag(Tags.Cached)]
2118
[Route("/cached/orders")]
2219
[Route("/cached/orders/page/{Page}")]
2320
[Route("/cached/customers/{CustomerId}/orders")]
24-
public class CachedOrders
21+
public class CachedGetOrders : IReturn<OrdersResponse>
2522
{
26-
[DataMember]
2723
public int? Page { get; set; }
28-
29-
[DataMember]
3024
public string CustomerId { get; set; }
3125
}
3226
}

src/Northwind.ServiceModel/Customers.cs renamed to src/Northwind.ServiceModel/GetAllCustomers.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,14 @@
55

66
namespace Northwind.ServiceModel
77
{
8-
[DataContract]
9-
[Route("/customers")]
10-
public class Customers : IReturn<CustomersResponse> {}
8+
[Route("/customers"), Tag(Tags.Customers)]
9+
public class GetAllCustomers : IReturn<CustomersResponse> {}
1110

1211
[DataContract]
1312
public class CustomersResponse : IHasResponseStatus
1413
{
15-
public CustomersResponse()
16-
{
17-
this.ResponseStatus = new ResponseStatus();
18-
this.Customers = new List<Customer>();
19-
}
20-
2114
[DataMember]
22-
public List<Customer> Customers { get; set; }
23-
15+
public List<Customer> Results { get; set; }
2416
[DataMember]
2517
public ResponseStatus ResponseStatus { get; set; }
2618
}

src/Northwind.ServiceModel/CustomerDetails.cs renamed to src/Northwind.ServiceModel/GetCustomerDetails.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,19 @@
55

66
namespace Northwind.ServiceModel
77
{
8-
[DataContract]
9-
[Route("/customers/{Id}")]
10-
public class CustomerDetails : IReturn<CustomerDetailsResponse>
8+
[Route("/customers/{Id}"), Tag(Tags.Customers)]
9+
public class GetCustomerDetails : IReturn<CustomerDetailsResponse>
1110
{
12-
[DataMember]
1311
public string Id { get; set; }
1412
}
1513

1614
[DataContract]
1715
public class CustomerDetailsResponse : IHasResponseStatus
1816
{
19-
public CustomerDetailsResponse()
20-
{
21-
this.ResponseStatus = new ResponseStatus();
22-
this.CustomerOrders = new List<CustomerOrder>();
23-
}
24-
2517
[DataMember]
2618
public Customer Customer { get; set; }
27-
2819
[DataMember]
29-
public List<CustomerOrder> CustomerOrders { get; set; }
30-
20+
public List<CustomerOrder> Orders { get; set; }
3121
[DataMember]
3222
public ResponseStatus ResponseStatus { get; set; }
3323
}
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
11
using ServiceStack;
22
using System.Collections.Generic;
3+
using System.Runtime.Serialization;
34
using Northwind.ServiceModel.Types;
45

56
namespace Northwind.ServiceModel
67
{
8+
[Tag(Tags.Orders)]
79
[Route("/orders")]
810
[Route("/orders/page/{Page}")]
911
[Route("/customers/{CustomerId}/orders")]
10-
public class Orders : IReturn<OrdersResponse>
12+
public class GetOrders : IReturn<OrdersResponse>
1113
{
1214
public int? Page { get; set; }
13-
1415
public string CustomerId { get; set; }
1516
}
1617

18+
[DataContract]
1719
public class OrdersResponse : IHasResponseStatus
1820
{
19-
public OrdersResponse()
20-
{
21-
this.ResponseStatus = new ResponseStatus();
22-
this.Results = new List<CustomerOrder>();
23-
}
24-
21+
[DataMember]
2522
public List<CustomerOrder> Results { get; set; }
26-
23+
[DataMember]
2724
public ResponseStatus ResponseStatus { get; set; }
2825
}
2926
}

0 commit comments

Comments
 (0)