forked from ServiceStackApps/Northwind
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
516 additions
and
644 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
using Northwind.ServiceModel; | ||
using ServiceStack; | ||
|
||
namespace Northwind.ServiceInterface | ||
namespace Northwind.ServiceInterface; | ||
|
||
[CacheResponse(Duration = 60 * 60, MaxAge = 30 * 60)] | ||
public class CachedServices : Service | ||
{ | ||
[CacheResponse(Duration = 60 * 60, MaxAge = 30 * 60)] | ||
public class CachedServices : Service | ||
{ | ||
public object Get(CachedGetAllCustomers request) => | ||
Gateway.Send(new GetAllCustomers()); | ||
public object Get(CachedGetAllCustomers request) => | ||
Gateway.Send(new GetAllCustomers()); | ||
|
||
public object Get(CachedGetCustomerDetails request) => | ||
Gateway.Send(new GetCustomerDetails { Id = request.Id }); | ||
public object Get(CachedGetCustomerDetails request) => | ||
Gateway.Send(new GetCustomerDetails { Id = request.Id }); | ||
|
||
public object Get(CachedGetOrders request) => | ||
Gateway.Send(new GetOrders { CustomerId = request.CustomerId, Page = request.Page }); | ||
} | ||
public object Get(CachedGetOrders request) => | ||
Gateway.Send(new GetOrders { CustomerId = request.CustomerId, Page = request.Page }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,25 @@ | ||
using System; | ||
using System.Net; | ||
using Northwind.ServiceModel; | ||
using Northwind.ServiceModel.Types; | ||
using ServiceStack; | ||
using ServiceStack.OrmLite; | ||
|
||
namespace Northwind.ServiceInterface | ||
namespace Northwind.ServiceInterface; | ||
|
||
public class CustomerDetailsService : Service | ||
{ | ||
public class CustomerDetailsService : Service | ||
public CustomerDetailsResponse Get(GetCustomerDetails request) | ||
{ | ||
public CustomerDetailsResponse Get(GetCustomerDetails request) | ||
{ | ||
var customer = Db.SingleById<Customer>(request.Id); | ||
if (customer == null) | ||
throw new HttpError(HttpStatusCode.NotFound, | ||
new ArgumentException("Customer does not exist: " + request.Id)); | ||
var customer = Db.SingleById<Customer>(request.Id); | ||
if (customer == null) | ||
throw new HttpError(HttpStatusCode.NotFound, | ||
new ArgumentException("Customer does not exist: " + request.Id)); | ||
|
||
var ordersResponse = base.Gateway.Send(new GetOrders { CustomerId = customer.Id }); | ||
return new CustomerDetailsResponse | ||
{ | ||
Customer = customer, | ||
Orders = ordersResponse.Results, | ||
}; | ||
} | ||
var ordersResponse = base.Gateway.Send(new GetOrders { CustomerId = customer.Id }); | ||
return new CustomerDetailsResponse | ||
{ | ||
Customer = customer, | ||
Orders = ordersResponse.Results, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 4 additions & 13 deletions
17
src/Northwind.ServiceInterface/Northwind.ServiceInterface.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<AssemblyName>Northwind.ServiceInterface</AssemblyName> | ||
<PackageId>Northwind.ServiceInterface</PackageId> | ||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> | ||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> | ||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="../Northwind.ServiceModel/Northwind.ServiceModel.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="ServiceStack.Server" Version="5.*" /> | ||
<PackageReference Include="ServiceStack" Version="5.*" /> | ||
<PackageReference Include="ServiceStack.Interfaces" Version="5.*" /> | ||
<PackageReference Include="ServiceStack.Text" Version="5.*" /> | ||
<PackageReference Include="ServiceStack.Client" Version="5.*" /> | ||
<PackageReference Include="ServiceStack.Common" Version="5.*" /> | ||
<PackageReference Include="ServiceStack.OrmLite" Version="5.*" /> | ||
<PackageReference Include="ServiceStack.Server" Version="6.*" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,57 @@ | ||
using Northwind.ServiceModel; | ||
using ServiceStack; | ||
using ServiceStack.Web; | ||
using System; | ||
using System.IO; | ||
|
||
namespace Northwind.ServiceInterface; | ||
|
||
namespace Northwind.ServiceInterface | ||
using ServiceModel.Types; | ||
|
||
public class VCardFormat | ||
{ | ||
using ServiceModel.Types; | ||
private const string VCardContentType = "text/x-vcard"; | ||
|
||
public class VCardFormat | ||
public static void Register(IAppHost appHost) | ||
{ | ||
private const string VCardContentType = "text/x-vcard"; | ||
appHost.ContentTypes.Register(VCardContentType, SerializeToStream, DeserializeFromStream); | ||
|
||
public static void Register(IAppHost appHost) | ||
appHost.GlobalResponseFilters.Add((req, res, dto) => | ||
{ | ||
appHost.ContentTypes.Register(VCardContentType, SerializeToStream, DeserializeFromStream); | ||
|
||
appHost.GlobalResponseFilters.Add((req, res, dto) => | ||
if (req.ResponseContentType == VCardContentType) | ||
{ | ||
if (req.ResponseContentType == VCardContentType) | ||
{ | ||
res.AddHeader(HttpHeaders.ContentDisposition, | ||
string.Format("attachment;filename={0}.vcf", req.OperationName)); | ||
} | ||
}); | ||
} | ||
|
||
public static void SerializeToStream(IRequest req, object response, Stream stream) | ||
{ | ||
var customerResponse = response as CustomerDetailsResponse; | ||
using (var sw = new StreamWriter(stream)) | ||
{ | ||
if (customerResponse != null) | ||
{ | ||
WriteCustomer(sw, customerResponse.Customer); | ||
} | ||
var customers = response as CustomersResponse; | ||
if (customers != null) | ||
{ | ||
customers.Results.ForEach(x => WriteCustomer(sw, x)); | ||
} | ||
res.AddHeader(HttpHeaders.ContentDisposition, | ||
string.Format("attachment;filename={0}.vcf", req.OperationName)); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
public static void WriteCustomer(StreamWriter sw, Customer customer) | ||
public static void SerializeToStream(IRequest req, object response, Stream stream) | ||
{ | ||
var customerResponse = response as CustomerDetailsResponse; | ||
using var sw = new StreamWriter(stream); | ||
if (customerResponse != null) | ||
{ | ||
sw.WriteLine("BEGIN:VCARD"); | ||
sw.WriteLine("VERSION:2.1"); | ||
sw.WriteLine("FN:" + customer.ContactName); | ||
sw.WriteLine("ORG:" + customer.CompanyName); | ||
sw.WriteLine("TITLE:" + customer.ContactTitle); | ||
sw.WriteLine("EMAIL;TYPE=PREF,INTERNET:" + customer.Email); | ||
sw.WriteLine("TEL;HOME;VOICE:" + customer.Phone); | ||
sw.WriteLine("TEL;WORK;FAX:" + customer.Fax); | ||
sw.WriteLine("ADR;TYPE=HOME;" | ||
+ new[] { customer.Address, customer.City, customer.PostalCode }.Join(";")); | ||
sw.WriteLine("END:VCARD"); | ||
WriteCustomer(sw, customerResponse.Customer); | ||
} | ||
|
||
public static object DeserializeFromStream(Type type, Stream stream) | ||
if (response is CustomersResponse customers) | ||
{ | ||
throw new NotImplementedException(); | ||
customers.Results.ForEach(x => WriteCustomer(sw, x)); | ||
} | ||
} | ||
} | ||
|
||
public static void WriteCustomer(StreamWriter sw, Customer customer) | ||
{ | ||
sw.WriteLine("BEGIN:VCARD"); | ||
sw.WriteLine("VERSION:2.1"); | ||
sw.WriteLine("FN:" + customer.ContactName); | ||
sw.WriteLine("ORG:" + customer.CompanyName); | ||
sw.WriteLine("TITLE:" + customer.ContactTitle); | ||
sw.WriteLine("EMAIL;TYPE=PREF,INTERNET:" + customer.Email); | ||
sw.WriteLine("TEL;HOME;VOICE:" + customer.Phone); | ||
sw.WriteLine("TEL;WORK;FAX:" + customer.Fax); | ||
sw.WriteLine("ADR;TYPE=HOME;" | ||
+ new[] { customer.Address, customer.City, customer.PostalCode }.Join(";")); | ||
sw.WriteLine("END:VCARD"); | ||
} | ||
|
||
public static object DeserializeFromStream(Type type, Stream stream) => throw new NotImplementedException(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
using System.Collections.Generic; | ||
using Northwind.ServiceModel.Types; | ||
using Northwind.ServiceModel.Types; | ||
using ServiceStack; | ||
|
||
namespace Northwind.ServiceModel | ||
namespace Northwind.ServiceModel; | ||
|
||
[Route("/query/customers"), Tag(Tags.AutoQuery)] | ||
public class QueryCustomers : QueryDb<Customer> | ||
{ | ||
[Route("/query/customers"), Tag(Tags.AutoQuery)] | ||
public class QueryCustomers : QueryDb<Customer> | ||
{ | ||
public List<string> Ids { get; set; } | ||
public string CountryStartsWith { get; set; } | ||
} | ||
public List<string> Ids { get; set; } | ||
public string CountryStartsWith { get; set; } | ||
} | ||
|
||
[Route("/query/orders"), Tag(Tags.AutoQuery)] | ||
public class QueryOrders : QueryDb<Order> | ||
{ | ||
public decimal? Freight { get; set; } | ||
} | ||
[Route("/query/orders"), Tag(Tags.AutoQuery)] | ||
public class QueryOrders : QueryDb<Order> | ||
{ | ||
public decimal? Freight { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
using ServiceStack; | ||
|
||
namespace Northwind.ServiceModel | ||
{ | ||
[Route("/cached/customers"), Tag(Tags.Cached)] | ||
public class CachedGetAllCustomers : IGet, IReturn<CustomersResponse> {} | ||
namespace Northwind.ServiceModel; | ||
|
||
[Route("/cached/customers"), Tag(Tags.Cached)] | ||
public class CachedGetAllCustomers : IGet, IReturn<CustomersResponse> {} | ||
|
||
[Route("/cached/customers/{Id}"), Tag(Tags.Cached)] | ||
public class CachedGetCustomerDetails : IGet, IReturn<CustomerDetailsResponse> | ||
{ | ||
public string Id { get; set; } | ||
} | ||
[Route("/cached/customers/{Id}"), Tag(Tags.Cached)] | ||
public class CachedGetCustomerDetails : IGet, IReturn<CustomerDetailsResponse> | ||
{ | ||
public string Id { get; set; } | ||
} | ||
|
||
[Tag(Tags.Cached)] | ||
[Route("/cached/orders")] | ||
[Route("/cached/orders/page/{Page}")] | ||
[Route("/cached/customers/{CustomerId}/orders")] | ||
public class CachedGetOrders : IGet, IReturn<OrdersResponse> | ||
{ | ||
public int? Page { get; set; } | ||
public string CustomerId { get; set; } | ||
} | ||
} | ||
[Tag(Tags.Cached)] | ||
[Route("/cached/orders")] | ||
[Route("/cached/orders/page/{Page}")] | ||
[Route("/cached/customers/{CustomerId}/orders")] | ||
public class CachedGetOrders : IGet, IReturn<OrdersResponse> | ||
{ | ||
public int? Page { get; set; } | ||
public string CustomerId { get; set; } | ||
} |
Oops, something went wrong.