feat(ministry): add Ministry entity, seed (10), and read endpoint
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
using ROLAC.API.DTOs.Ministry;
|
||||
namespace ROLAC.API.Services;
|
||||
|
||||
public interface IMinistryService
|
||||
{
|
||||
Task<List<MinistryDto>> GetAllAsync(bool includeInactive);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ROLAC.API.Data;
|
||||
using ROLAC.API.DTOs.Ministry;
|
||||
|
||||
namespace ROLAC.API.Services;
|
||||
|
||||
public class MinistryService : IMinistryService
|
||||
{
|
||||
private readonly AppDbContext _db;
|
||||
public MinistryService(AppDbContext db) => _db = db;
|
||||
|
||||
public async Task<List<MinistryDto>> GetAllAsync(bool includeInactive)
|
||||
{
|
||||
var query = _db.Ministries.AsNoTracking().AsQueryable();
|
||||
if (!includeInactive) query = query.Where(m => m.IsActive);
|
||||
return await query
|
||||
.OrderBy(m => m.SortOrder).ThenBy(m => m.Name_en)
|
||||
.Select(m => new MinistryDto
|
||||
{
|
||||
Id = m.Id, Name_en = m.Name_en, Name_zh = m.Name_zh,
|
||||
SortOrder = m.SortOrder, IsActive = m.IsActive,
|
||||
})
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user