I already use ServiceStack OrmLite for quering my database, but now I want to create some CRUD API's myself. I have a separate project where my POCO's are declared with the ServiceStack DataAnnotations.
An example class of my POCO project:
public class DropPosition
{
[PrimaryKey, AutoIncrement]
public long Id { get; set; }
public int PositionId { get; set; }
public string PositionBarcode { get; set; }
public string BoxBarcode { get; set; }
public int? OrderReference { get; set; }
public DateTime? StartTime { get; set; }
public DateTime? EndTime { get; set; }
public bool ActivateLight { get; set; }
[Reference]
public virtual List<WorkOrder> WorkOrders { get; set; } = new List<WorkOrder>();
}
Now I've created a new web project so I can serve my API endpoints using AutoQuery, and extended the POCO class:
public class DropPosition
{
[PrimaryKey, AutoIncrement]
public long Id { get; set; }
public int PositionId { get; set; }
public string PositionBarcode { get; set; }
public string BoxBarcode { get; set; }
public int? OrderReference { get; set; }
public DateTime? StartTime { get; set; }
public DateTime? EndTime { get; set; }
public bool ActivateLight { get; set; }
[Reference]
public virtual List<WorkOrder> WorkOrders { get; set; } = new List<WorkOrder>();
}
[Route("/DropPositions", "GET")]
[Route("/DropPositions/{Id}", "GET")]
public class QueryDropPositions : QueryDb<DropPosition>
{
public long Id { get; set; }
public int PositionId { get; set; }
public string PositionBarcode { get; set; }
public string BoxBarcode { get; set; }
public int? OrderReference { get; set; }
public bool ActivateLight { get; set; }
}
[Route("/DropPositions", "POST")]
public class CreateDropPosition : ICreateDb<DropPosition>, IReturn<DropPosition>
{
public int PositionId { get; set; }
public string PositionBarcode { get; set; }
public string BoxBarcode { get; set; }
public int? OrderReference { get; set; }
public DateTime? StartTime { get; set; }
public DateTime? EndTime { get; set; }
public bool ActivateLight { get; set; }
}
[Route("/DropPositions/{Id}", "PUT")]
public class UpdateDropPosition : IUpdateDb<DropPosition>, IReturn<DropPosition>
{
public long Id { get; set; }
public int PositionId { get; set; }
public string PositionBarcode { get; set; }
public string BoxBarcode { get; set; }
public int? OrderReference { get; set; }
public DateTime? StartTime { get; set; }
public DateTime? EndTime { get; set; }
public bool ActivateLight { get; set; }
}
[Route("/DropPositions/{Id}", "DELETE")]
public class DeleteDropPosition : IDeleteDb<DropPosition>, IReturnVoid
{
public long Id { get; set; }
}
And then followed the best pratice examples like this and referenced my POCO project.
public class AppHost: AppHostBase, IHostingStartup
{
public AppHost() : base("AutoQuery", typeof(ServiceStackService).Assembly)
{
}
public override void Configure(Container container)
{
// configure ServiceStack only IOC, Config & Plugins
SetConfig(new HostConfig
{
DebugMode = true
});
// auto query
Plugins.Add(new AutoQueryFeature
{
MaxLimit = 1000,
//GenerateCrudServices = new GenerateCrudServices
//{
// AutoRegister = true
//}
});
}
public void Configure(IWebHostBuilder builder)
{
builder.Configure(app =>
{
if (!HasInit)
{
app.UseServiceStack(new AppHost());
}
});
builder.ConfigureServices((context, services) =>
{
// ormlite
var sorterConnectionFactory = new OrmLiteConnectionFactory(ConnectionStrings.SorterLocal, SqlServerDialect.Provider);
// unicode
sorterConnectionFactory.DialectProvider.GetStringConverter().UseUnicode = true;
// register
services.AddSingleton<IDbConnectionFactory>(sorterConnectionFactory);
});
}
}
But I can't see my new API endpoints using the api explorer... But when I activate the GenerateCrudServices options, I see the auto-generated API endpoints. Did I forgot something? Should I change my code for only using my own declared AutoQuery CRUD API's?
I've tried to follow the example BookingsCrud