Skip to content

Commit

Permalink
移除AutoMapper 改用Mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
liuning committed Aug 24, 2023
1 parent bba07ea commit 3bc1c69
Show file tree
Hide file tree
Showing 25 changed files with 119 additions and 492 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using MineCosmos.Core.Api.Filter;
using MineCosmos.Core.Common.Helper;
using MineCosmos.Core.IRepository.Base;
Expand Down Expand Up @@ -84,7 +85,7 @@ public async Task<dynamic> PutItem(ReqMinecraftItemDto model)
ItemData= model.Source,
ItemType = WareHouseItemTypeEnum.插件
}
}
}.Adapt<List<PlayerWareHouseItemDto>>()
});


Expand Down
26 changes: 11 additions & 15 deletions MineCosmos.Core.Api/Controllers/UserController.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;

using MineCosmos.Core.AuthHelper.OverWrite;
using MineCosmos.Core.Common.Helper;
using MineCosmos.Core.Common.HttpContextUser;
Expand All @@ -13,7 +9,7 @@
using MineCosmos.Core.Repository.UnitOfWorks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Mapster;

namespace MineCosmos.Core.Controllers
{
Expand All @@ -31,7 +27,6 @@ public class UserController : BaseApiController
readonly IRoleServices _roleServices;
private readonly IDepartmentServices _departmentServices;
private readonly IUser _user;
private readonly IMapper _mapper;
private readonly ILogger<UserController> _logger;

/// <summary>
Expand All @@ -49,15 +44,14 @@ public UserController(IUnitOfWorkManage unitOfWorkManage, ISysUserInfoServices s
IUserRoleServices userRoleServices,
IRoleServices roleServices,
IDepartmentServices departmentServices,
IUser user, IMapper mapper, ILogger<UserController> logger)
IUser user, ILogger<UserController> logger)
{
_unitOfWorkManage = unitOfWorkManage;
_sysUserInfoServices = sysUserInfoServices;
_userRoleServices = userRoleServices;
_roleServices = roleServices;
_departmentServices = departmentServices;
_user = user;
_mapper = mapper;
_logger = logger;
}

Expand All @@ -69,8 +63,9 @@ public UserController(IUnitOfWorkManage unitOfWorkManage, ISysUserInfoServices s
/// <returns></returns>
// GET: api/User
[HttpGet]
public async Task<MessageModel<PageModel<SysUserInfoDto>>> Get(int page = 1, string key = "")
public async Task<MessageModel<PageModel<SysUserInfo>>> Get(int page = 1, string key = "")
{
//SysUserInfoDto
if (string.IsNullOrEmpty(key) || string.IsNullOrWhiteSpace(key))
{
key = "";
Expand Down Expand Up @@ -104,8 +99,8 @@ public async Task<MessageModel<PageModel<SysUserInfoDto>>> Get(int page = 1, str

#endregion


return Success(data.ConvertTo<SysUserInfoDto>(_mapper));
return Success(data);
// return Success(data.ConvertTo<SysUserInfoDto>(_mapper));
}

private (string, List<int>) GetFullDepartmentName(List<Department> departments, int departmentId)
Expand Down Expand Up @@ -153,7 +148,7 @@ public async Task<MessageModel<SysUserInfoDto>> GetInfoByToken(string token)
var userinfo = await _sysUserInfoServices.QueryById(tokenModel.Uid);
if (userinfo != null)
{
data.response = _mapper.Map<SysUserInfoDto>(userinfo);
data.response = userinfo.Adapt<SysUserInfoDto>();// _mapper.Map<SysUserInfoDto>(userinfo);
data.success = true;
data.msg = "获取成功";
}
Expand All @@ -177,7 +172,7 @@ public async Task<MessageModel<string>> Post([FromBody] SysUserInfoDto sysUserIn
sysUserInfo.uLoginPWD = MD5Helper.MD5Encrypt32(sysUserInfo.uLoginPWD);
sysUserInfo.uRemark = _user.Name;

var id = await _sysUserInfoServices.Add(_mapper.Map<SysUserInfo>(sysUserInfo));
var id = await _sysUserInfoServices.Add(sysUserInfo.Adapt<SysUserInfo>()/*_mapper.Map<SysUserInfo>(sysUserInfo)*/);
data.success = id > 0;
if (data.success)
{
Expand Down Expand Up @@ -213,7 +208,8 @@ public async Task<MessageModel<string>> Put([FromBody] SysUserInfoDto sysUserInf
oldUser.CriticalModifyTime = DateTime.Now;
}

_mapper.Map(sysUserInfo, oldUser);

// _mapper.Map(sysUserInfo, oldUser);

_unitOfWorkManage.BeginTran();
// 无论 Update Or Add , 先删除当前用户的全部 U_R 关系
Expand Down
8 changes: 3 additions & 5 deletions MineCosmos.Core.Api/Controllers/UserRoleController.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Threading.Tasks;
using AutoMapper;
using MineCosmos.Core.IServices;
using MineCosmos.Core.Model;
using MineCosmos.Core.Model.Models;
using MineCosmos.Core.Model.ViewModels;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Mapster;

namespace MineCosmos.Core.Controllers
{
Expand All @@ -21,7 +21,6 @@ public class UserRoleController : Controller
private readonly ISysUserInfoServices _sysUserInfoServices;
private readonly IUserRoleServices _userRoleServices;
private readonly IRoleServices _roleServices;
private readonly IMapper _mapper;

/// <summary>
/// 构造函数
Expand All @@ -30,12 +29,11 @@ public class UserRoleController : Controller
/// <param name="userRoleServices"></param>
/// <param name="mapper"></param>
/// <param name="roleServices"></param>
public UserRoleController(ISysUserInfoServices sysUserInfoServices, IUserRoleServices userRoleServices, IMapper mapper, IRoleServices roleServices)
public UserRoleController(ISysUserInfoServices sysUserInfoServices, IUserRoleServices userRoleServices, IRoleServices roleServices)
{
_sysUserInfoServices = sysUserInfoServices;
_userRoleServices = userRoleServices;
_roleServices = roleServices;
_mapper = mapper;
}


Expand All @@ -54,7 +52,7 @@ public async Task<MessageModel<SysUserInfoDto>> AddUser(string loginName, string
{
success = true,
msg = "添加成功",
response = _mapper.Map<SysUserInfoDto>(userInfo)
response = userInfo.Adapt<SysUserInfoDto>() //_mapper.Map<SysUserInfoDto>(userInfo)
};
}

Expand Down
9 changes: 2 additions & 7 deletions MineCosmos.Core.Api/Controllers/ValuesController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using AutoMapper;
using MineCosmos.Core.Common;
using MineCosmos.Core.Common;
using MineCosmos.Core.Common.HttpContextUser;
using MineCosmos.Core.Common.HttpPolly;
using MineCosmos.Core.Common.WebApiClients.HttpApis;
Expand Down Expand Up @@ -31,7 +30,6 @@ namespace MineCosmos.Core.Controllers
[Authorize]
public class ValuesController : ControllerBase
{
private IMapper _mapper;
private readonly IAdvertisementServices _advertisementServices;
private readonly Love _love;
private readonly IRoleModulePermissionServices _roleModulePermissionServices;
Expand All @@ -56,17 +54,14 @@ public class ValuesController : ControllerBase
/// <param name="doubanApi"></param>
/// <param name="httpPollyHelper"></param>
public ValuesController(IBlogArticleServices blogArticleServices
, IMapper mapper
, IAdvertisementServices advertisementServices
, IAdvertisementServices advertisementServices
, Love love
, IRoleModulePermissionServices roleModulePermissionServices
, IUser user, IPasswordLibServices passwordLibServices
, IBlogApi blogApi
, IDoubanApi doubanApi
, IHttpPollyHelper httpPollyHelper)
{
// 测试 Authorize 和 mapper
_mapper = mapper;
_advertisementServices = advertisementServices;
_love = love;
_roleModulePermissionServices = roleModulePermissionServices;
Expand Down
27 changes: 26 additions & 1 deletion MineCosmos.Core.Api/MineCosmos.Core.Model.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions MineCosmos.Core.Api/MineCosmos.Core.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions MineCosmos.Core.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using MineCosmos.Core.Hubs;
using MineCosmos.Core.IServices;
using MineCosmos.Core.Tasks;
using FluentValidation.AspNetCore;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Server.Kestrel.Core;
Expand All @@ -25,6 +24,15 @@
using System.Text;
using AgileConfig.Client;


/*
* Mapster Github :
* https://github.com/MapsterMapper/Mapster
* 无废话的Mapster一些中文文档:
* https://www.cnblogs.com/qiqigou/p/13696669.html
* https://github.com/rivenfx/Mapster-docs
*/

var builder = WebApplication.CreateBuilder(args);

// 1、配置host与容器
Expand Down Expand Up @@ -77,21 +85,17 @@
builder.Services.AddRedisSetup();
builder.Services.AddSqlsugarSetup();
builder.Services.AddDbSetup();
builder.Services.AddAutoMapperSetup();
builder.Services.AddCorsSetup();
builder.Services.AddMiniProfilerSetup();
builder.Services.AddSwaggerSetup();
builder.Services.AddJobSetup();
//builder.Services.AddJobSetup_HostedService();
builder.Services.AddHttpContextSetup();
builder.Services.AddAppTableConfigSetup(builder.Environment);
builder.Services.AddHttpApi();
builder.Services.AddRabbitMQSetup();
builder.Services.AddKafkaSetup(builder.Configuration);
builder.Services.AddEventBusSetup();

//
//builder.Services.AddNacosSetup(builder.Configuration);

builder.Services.AddAuthorizationSetup();
if (Permissions.IsUseIds4 || Permissions.IsUseAuthing)
Expand Down
Loading

0 comments on commit 3bc1c69

Please sign in to comment.