增加控制器,部分逻辑转为自实现
This commit is contained in:
parent
578f73a23a
commit
2ddef0d1b5
|
@ -0,0 +1,75 @@
|
||||||
|
using LFlow.Base.Interfaces;
|
||||||
|
using LFlow.Base.Utils;
|
||||||
|
using LFlow.VersionManagement.Enums;
|
||||||
|
using LFlow.VersionManagement.Model;
|
||||||
|
using LFlow.VersionManagement.Service;
|
||||||
|
using Mapster;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace LFlow.VersionManagement.Controller;
|
||||||
|
public class VersionManagementController(IVersionManagementService service) : BaseController
|
||||||
|
{
|
||||||
|
[HttpDelete]
|
||||||
|
public int DeleteById(string id)
|
||||||
|
{
|
||||||
|
return service.DeleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public PagedApiResult<List<VersionDto>> GetAll(int pageIndex, int pageSize)
|
||||||
|
{
|
||||||
|
var total = 0;
|
||||||
|
var result = service.GetAll(pageIndex, pageSize, ref total);
|
||||||
|
return PagedApiResult<List<VersionDto>>.SuccessResult(
|
||||||
|
data: Mapper.Map<List<VersionDto>>(result) ?? [],
|
||||||
|
total,
|
||||||
|
pageIndex,
|
||||||
|
pageSize
|
||||||
|
);
|
||||||
|
//return new PagedApiResult<List<VersionDto>>
|
||||||
|
//{
|
||||||
|
// Data = Mapper.Map<List<VersionDto>>(result),
|
||||||
|
// PageIndex = pageIndex,
|
||||||
|
// PageSize = pageSize,
|
||||||
|
// Message = "获取成功",
|
||||||
|
// Code = 200,
|
||||||
|
// Success = true,
|
||||||
|
// TotalCount = total
|
||||||
|
//};
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public ApiResult<VersionDto> GetById(string id)
|
||||||
|
{
|
||||||
|
var result = service.GetById(id).Adapt<VersionDto>();
|
||||||
|
return ApiResult<VersionDto>.SuccessResult(result);
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public ApiResult<VersionDto> Save(VersionDto entity, bool isUpdate)
|
||||||
|
{
|
||||||
|
if (!isUpdate)
|
||||||
|
{
|
||||||
|
entity.ID = Guid.NewGuid().ToString();
|
||||||
|
entity.DownloadUrl = "/";
|
||||||
|
}
|
||||||
|
var result = service.Save(entity, isUpdate).Adapt<VersionDto>();
|
||||||
|
return ApiResult<VersionDto>.SuccessResult(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public List<VersionDto> Search(VersionDto whereObj)
|
||||||
|
{
|
||||||
|
return service.Search(whereObj).Adapt<List<VersionDto>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
//[HttpPost]
|
||||||
|
//public ApiResult<VersionDto> CheckUpdate(VersionDto current)
|
||||||
|
//{
|
||||||
|
|
||||||
|
//}
|
||||||
|
[HttpGet]
|
||||||
|
public ApiResult<VersionDto> GetLastUpdate(VersionType type, VersionChannel channel, UpgradeTargetType targetType)
|
||||||
|
{
|
||||||
|
return ApiResult<VersionDto>.SuccessResult(service.GetLastVersion(type, channel, targetType));
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,17 @@
|
||||||
using LFlow.Base.Interfaces;
|
using LFlow.Base.Interfaces;
|
||||||
|
using LFlow.VersionManagement.Enums;
|
||||||
using LFlow.VersionManagement.Model;
|
using LFlow.VersionManagement.Model;
|
||||||
|
|
||||||
namespace LFlow.VersionManagement.Service;
|
namespace LFlow.VersionManagement.Service;
|
||||||
public interface IVersionManagementService : IService<VersionDto>
|
public interface IVersionManagementService : IService//<VersionDto>
|
||||||
{
|
{
|
||||||
|
VersionDto GetById(string id);
|
||||||
|
List<VersionDto> Search(VersionDto whereObj);
|
||||||
|
|
||||||
|
int DeleteById(string id);
|
||||||
|
VersionDto Save(VersionDto entity, bool isUpdate);
|
||||||
|
|
||||||
|
List<VersionDto> GetAll(int pageIndex, int pageSize, ref int total);
|
||||||
|
|
||||||
|
VersionDto? GetLastVersion(VersionType type, VersionChannel channel, UpgradeTargetType targetType);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,60 +1,37 @@
|
||||||
using LFlow.Base.Interfaces;
|
using LFlow.Base.Interfaces;
|
||||||
using LFlow.Base.Utils;
|
using LFlow.VersionManagement.Enums;
|
||||||
using LFlow.VersionManagement.Model;
|
using LFlow.VersionManagement.Model;
|
||||||
|
using LFlow.VersionManagement.Repository;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
|
|
||||||
namespace LFlow.VersionManagement.Service;
|
namespace LFlow.VersionManagement.Service;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 版本管理服务
|
/// 版本管理服务
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class VersionManagementService : BaseController, IVersionManagementService
|
public class VersionManagementService : IVersionManagementService
|
||||||
{
|
{
|
||||||
private readonly IRepo<VersionModel, string> _repo;
|
private readonly IRepo<VersionModel, string> _repo;
|
||||||
public VersionManagementService(IRepo<VersionModel, string> repo)
|
public VersionManagementService(IRepo<VersionModel, string> repo)
|
||||||
{
|
{
|
||||||
_repo = repo;
|
_repo = repo;
|
||||||
}
|
}
|
||||||
[HttpDelete]
|
|
||||||
public int DeleteById(string id)
|
|
||||||
{
|
|
||||||
return _repo.DeleteById(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet]
|
public int DeleteById(string id) => _repo.DeleteById(id);
|
||||||
public PagedApiResult<List<VersionDto>> GetAll(int pageIndex, int pageSize)
|
public List<VersionDto> GetAll(int pageIndex, int pageSize, ref int total) => _repo.GetAll(pageIndex, pageSize, ref total).Adapt<List<VersionDto>>();
|
||||||
{
|
public VersionDto GetById(string id) => _repo.Get(id).Adapt<VersionDto>();
|
||||||
var total = 0;
|
public VersionDto Save(VersionDto entity, bool isUpdate) => _repo.SaveOrUpdate(entity.Adapt<VersionModel>(), isUpdate).Adapt<VersionDto>();
|
||||||
var result = _repo.GetAll(pageIndex, pageSize, ref total);
|
// 搜索需要增加分页
|
||||||
return new PagedApiResult<List<VersionDto>>
|
|
||||||
{
|
|
||||||
Data = Mapper.Map<List<VersionDto>>(result),
|
|
||||||
PageIndex = pageIndex,
|
|
||||||
PageSize = pageSize,
|
|
||||||
Message = "获取成功",
|
|
||||||
Success = true,
|
|
||||||
TotalCount = total
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet]
|
|
||||||
public VersionDto GetById(string id)
|
|
||||||
{
|
|
||||||
return _repo.Get(id).Adapt<VersionDto>();
|
|
||||||
}
|
|
||||||
[HttpPost]
|
|
||||||
public VersionDto Save(VersionDto entity, bool isUpdate)
|
|
||||||
{
|
|
||||||
return _repo.SaveOrUpdate(entity.Adapt<VersionModel>(), isUpdate).Adapt<VersionDto>();
|
|
||||||
}
|
|
||||||
[HttpPost]
|
|
||||||
public List<VersionDto> Search(VersionDto whereObj)
|
public List<VersionDto> Search(VersionDto whereObj)
|
||||||
|
=> _repo.Search(whereObj.Adapt<VersionModel>()).Adapt<List<VersionDto>>();
|
||||||
|
public VersionDto? GetLastVersion(VersionType type, VersionChannel channel, UpgradeTargetType targetType)
|
||||||
{
|
{
|
||||||
return _repo.Search(whereObj.Adapt<VersionModel>()).Adapt<List<VersionDto>>();
|
if (_repo is VersionManagementRepo versionRepo)
|
||||||
}
|
{
|
||||||
[HttpPost]
|
return versionRepo.GetLatestVersion(type, channel, targetType).Adapt<VersionDto>();
|
||||||
public List<string> SearchAllId(VersionDto whereObj)
|
}
|
||||||
{
|
else
|
||||||
return _repo.WhereSearchId(whereObj.Adapt<VersionModel>());
|
{
|
||||||
|
return default;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue