using GDZZ.Core;
using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using GDZZ.Application.Entity;
using Microsoft.AspNetCore.Authorization;
namespace GDZZ.Application
{
///
/// 求职列表服务
///
[ApiDescriptionSettings("Application",Name = "JobHunt", Order = 1)]
public class JobHuntService : IJobHuntService, IDynamicApiController, ITransient
{
private readonly SqlSugarRepository _rep;
public JobHuntService(SqlSugarRepository rep)
{
_rep = rep;
}
///
/// 分页查询求职列表
///
///
///
[HttpGet("/JobHunt/page")]
[AllowAnonymous]
public async Task Page([FromQuery] JobHuntInput input)
{
var entities = await _rep.AsQueryable()
.WhereIF(!string.IsNullOrWhiteSpace(input.Address), u => u.Address.Contains(input.Address.Trim()))
.WhereIF(!string.IsNullOrWhiteSpace(input.Tags), u => u.Tags == input.Tags)
.WhereIF(!string.IsNullOrWhiteSpace(input.Position), u => u.Position == input.Position)
.OrderBy(u => u.Sort)
.ToPagedListAsync(input.PageNo, input.PageSize);
return entities.XnPagedResult();
}
///
/// 增加求职列表
///
///
///
[HttpPost("/JobHunt/add")]
[AllowAnonymous]
public async Task Add(AddJobHuntInput input)
{
var entity = input.Adapt();
await _rep.InsertAsync(entity);
}
///
/// 删除求职列表
///
///
///
[HttpPost("/JobHunt/delete")]
[AllowAnonymous]
public async Task Delete(DeleteJobHuntInput input)
{
var entity = await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
await _rep.DeleteAsync(entity);
}
///
/// 更新求职列表
///
///
///
[HttpPost("/JobHunt/edit")]
[AllowAnonymous]
public async Task Update(UpdateJobHuntInput input)
{
var entity = input.Adapt();
await _rep.AsUpdateable(entity).IgnoreColumns(ignoreAllNullColumns:true).ExecuteCommandAsync();
}
///
/// 获取求职列表
///
///
///
[HttpGet("/JobHunt/Detail")]
[AllowAnonymous]
public async Task Get([FromQuery] QueryeJobHuntInput input)
{
return await _rep.FirstOrDefaultAsync(u => u.Id == input.Id);
}
///
/// 获取求职列表列表
///
///
///
[HttpGet("/JobHunt/list")]
[AllowAnonymous]
public async Task List([FromQuery] JobHuntInput input)
{
return await _rep.AsQueryable()
.Where(x=>x.CreatedUserId == UserManager.UserId)
.OrderByDescending(x=>x.Tags)
.ToListAsync();
}
}
}