59 lines
1.5 KiB
C#
59 lines
1.5 KiB
C#
using AutoMapper;
|
|
using Common;
|
|
using Common.Utils;
|
|
using Microsoft.Extensions.Logging;
|
|
using MongoDB.Bson;
|
|
using MongoRepository;
|
|
using UserDomain.Entity;
|
|
using UserService.Notices.Param;
|
|
|
|
namespace UserService.Notices
|
|
{
|
|
public class NoticeService : INoticeService
|
|
{
|
|
private readonly IMongoBaseRepository<Notice> _noticeMongo;
|
|
private readonly IMapper _mapper;
|
|
|
|
|
|
public NoticeService(IMongoBaseRepository<Notice> noticeMongo, IMapper mapper)
|
|
{
|
|
_noticeMongo = noticeMongo;
|
|
_mapper = mapper;
|
|
}
|
|
|
|
|
|
public async Task<Notice> Get(string id)
|
|
{
|
|
var model = await _noticeMongo.FindByIdAsync(id);
|
|
if (model == null)
|
|
return null;
|
|
if (model.IsDelete)
|
|
return null;
|
|
return model;
|
|
|
|
}
|
|
|
|
|
|
public async Task<(List<Notice> list, long count)> GetList(GetNoticeListParam param)
|
|
{
|
|
var where = LinqExtensions.True<Notice>().And(e => e.IsDelete == false);
|
|
if (!string.IsNullOrWhiteSpace(param.KeyWord))
|
|
where = where.And(e => e.Title.Contains(param.KeyWord));
|
|
|
|
|
|
var result = await _noticeMongo.QueryPageAsync(where, c => c.CreateTime, true, param.PageSize ?? 0, param.PageIndex ?? 0);
|
|
|
|
return (result.list, result.count);
|
|
}
|
|
public async Task<Notice> GetNewOne()
|
|
{
|
|
var model = await _noticeMongo.FindOneAsync(e => e.IsDelete == false, c => c.CreateTime);
|
|
|
|
return model;
|
|
|
|
|
|
}
|
|
|
|
}
|
|
}
|