Files
mixtape/zero.Core/Api/ApplicationsApi.cs
T

92 lines
2.1 KiB
C#
Raw Normal View History

2020-05-22 21:19:49 +02:00
using FluentValidation;
using Raven.Client.Documents;
2020-04-06 00:26:31 +02:00
using Raven.Client.Documents.Session;
using System.Collections.Generic;
using System.Threading.Tasks;
2021-10-13 12:47:18 +02:00
using zero.Core.Collections;
2020-04-06 00:26:31 +02:00
using zero.Core.Entities;
using zero.Core.Extensions;
2020-04-06 00:26:31 +02:00
namespace zero.Core.Api
{
public class ApplicationsApi : BackofficeApi, IApplicationsApi
2020-04-06 00:26:31 +02:00
{
2021-05-04 17:23:52 +02:00
IValidator<Application> Validator;
2020-05-22 21:19:49 +02:00
2021-10-13 12:47:18 +02:00
public ApplicationsApi(ICollectionContext store, IValidator<Application> validator) : base(store, isCoreDatabase: true)
2020-05-22 21:19:49 +02:00
{
2020-09-09 13:43:01 +02:00
Validator = validator;
2020-05-22 21:19:49 +02:00
}
/// <inheritdoc />
2021-05-04 17:23:52 +02:00
public async Task<Application> GetById(string id)
{
2021-05-04 17:23:52 +02:00
return await GetById<Application>(id);
}
2020-04-06 00:26:31 +02:00
/// <inheritdoc />
2021-05-04 17:23:52 +02:00
public async Task<IList<Application>> GetAll()
2020-04-06 00:26:31 +02:00
{
2021-10-13 12:47:18 +02:00
return await Session
2021-05-04 17:23:52 +02:00
.Query<Application>()
2020-10-05 18:01:28 +02:00
.OrderByDescending(x => x.CreatedDate)
.ToListAsync();
2020-04-06 00:26:31 +02:00
}
/// <inheritdoc />
2021-05-04 17:23:52 +02:00
public async Task<ListResult<Application>> GetByQuery(ListQuery<Application> query)
{
query.SearchFor(entity => entity.Name);
2021-10-13 12:47:18 +02:00
return await Session.Query<Application>().ToQueriedListAsync(query);
}
/// <inheritdoc />
2021-05-04 17:23:52 +02:00
public async Task<EntityResult<Application>> Save(Application model)
{
return await SaveModel(model, Validator);
}
/// <inheritdoc />
2021-05-04 17:23:52 +02:00
public async Task<EntityResult<Application>> Delete(string id)
{
2021-05-04 17:23:52 +02:00
return await DeleteById<Application>(id);
}
2020-04-06 00:26:31 +02:00
}
public interface IApplicationsApi
2020-04-06 00:26:31 +02:00
{
/// <summary>
/// Get application by Id
/// </summary>
2021-05-04 17:23:52 +02:00
Task<Application> GetById(string id);
2020-04-06 00:26:31 +02:00
/// <summary>
/// Get all available zero applications
/// </summary>
2021-05-04 17:23:52 +02:00
Task<IList<Application>> GetAll();
/// <summary>
/// Get all available applications (with query)
/// </summary>
2021-05-04 17:23:52 +02:00
Task<ListResult<Application>> GetByQuery(ListQuery<Application> query);
/// <summary>
/// Creates or updates a application
/// </summary>
2021-05-04 17:23:52 +02:00
Task<EntityResult<Application>> Save(Application model);
/// <summary>
/// Deletes a application by Id
/// </summary>
2021-05-04 17:23:52 +02:00
Task<EntityResult<Application>> Delete(string id);
2020-04-06 00:26:31 +02:00
}
}