265 lines
7.2 KiB
C#
265 lines
7.2 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using XiangYi.Application.DTOs.Responses;
|
|
using XiangYi.Application.Interfaces;
|
|
|
|
namespace XiangYi.AdminApi.Controllers;
|
|
|
|
/// <summary>
|
|
/// 后台系统配置控制器
|
|
/// </summary>
|
|
[ApiController]
|
|
[Route("api/admin/config")]
|
|
[Authorize]
|
|
public class AdminConfigController : ControllerBase
|
|
{
|
|
private readonly ISystemConfigService _configService;
|
|
private readonly ILogger<AdminConfigController> _logger;
|
|
|
|
public AdminConfigController(
|
|
ISystemConfigService configService,
|
|
ILogger<AdminConfigController> logger)
|
|
{
|
|
_configService = configService;
|
|
_logger = logger;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取默认头像
|
|
/// </summary>
|
|
[HttpGet("defaultAvatar")]
|
|
public async Task<ApiResponse<DefaultAvatarResponse>> GetDefaultAvatar()
|
|
{
|
|
var avatarUrl = await _configService.GetDefaultAvatarAsync();
|
|
return ApiResponse<DefaultAvatarResponse>.Success(new DefaultAvatarResponse
|
|
{
|
|
AvatarUrl = avatarUrl
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置默认头像
|
|
/// </summary>
|
|
[HttpPost("defaultAvatar")]
|
|
public async Task<ApiResponse> SetDefaultAvatar([FromBody] SetDefaultAvatarRequest request)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(request.AvatarUrl))
|
|
{
|
|
return ApiResponse.Error(40001, "头像URL不能为空");
|
|
}
|
|
|
|
var result = await _configService.SetDefaultAvatarAsync(request.AvatarUrl);
|
|
return result ? ApiResponse.Success("设置成功") : ApiResponse.Error(40001, "设置失败");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取所有系统配置
|
|
/// </summary>
|
|
[HttpGet("all")]
|
|
public async Task<ApiResponse<Dictionary<string, string>>> GetAllConfigs()
|
|
{
|
|
var configs = await _configService.GetAllConfigsAsync();
|
|
return ApiResponse<Dictionary<string, string>>.Success(configs);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取用户协议
|
|
/// </summary>
|
|
[HttpGet("userAgreement")]
|
|
public async Task<ApiResponse<AgreementResponse>> GetUserAgreement()
|
|
{
|
|
var content = await _configService.GetUserAgreementAsync();
|
|
return ApiResponse<AgreementResponse>.Success(new AgreementResponse
|
|
{
|
|
Content = content ?? ""
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置用户协议
|
|
/// </summary>
|
|
[HttpPost("userAgreement")]
|
|
public async Task<ApiResponse> SetUserAgreement([FromBody] SetAgreementRequest request)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(request.Content))
|
|
{
|
|
return ApiResponse.Error(40001, "协议内容不能为空");
|
|
}
|
|
|
|
var result = await _configService.SetUserAgreementAsync(request.Content);
|
|
return result ? ApiResponse.Success("设置成功") : ApiResponse.Error(40001, "设置失败");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取隐私协议
|
|
/// </summary>
|
|
[HttpGet("privacyPolicy")]
|
|
public async Task<ApiResponse<AgreementResponse>> GetPrivacyPolicy()
|
|
{
|
|
var content = await _configService.GetPrivacyPolicyAsync();
|
|
return ApiResponse<AgreementResponse>.Success(new AgreementResponse
|
|
{
|
|
Content = content ?? ""
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置隐私协议
|
|
/// </summary>
|
|
[HttpPost("privacyPolicy")]
|
|
public async Task<ApiResponse> SetPrivacyPolicy([FromBody] SetAgreementRequest request)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(request.Content))
|
|
{
|
|
return ApiResponse.Error(40001, "协议内容不能为空");
|
|
}
|
|
|
|
var result = await _configService.SetPrivacyPolicyAsync(request.Content);
|
|
return result ? ApiResponse.Success("设置成功") : ApiResponse.Error(40001, "设置失败");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取会员权益长图
|
|
/// </summary>
|
|
[HttpGet("memberBenefitsImage")]
|
|
public async Task<ApiResponse<MemberBenefitsImageResponse>> GetMemberBenefitsImage()
|
|
{
|
|
var imageUrl = await _configService.GetMemberBenefitsImageAsync();
|
|
return ApiResponse<MemberBenefitsImageResponse>.Success(new MemberBenefitsImageResponse
|
|
{
|
|
ImageUrl = imageUrl
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置会员权益长图
|
|
/// </summary>
|
|
[HttpPost("memberBenefitsImage")]
|
|
public async Task<ApiResponse> SetMemberBenefitsImage([FromBody] SetMemberBenefitsImageRequest request)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(request.ImageUrl))
|
|
{
|
|
return ApiResponse.Error(40001, "图片URL不能为空");
|
|
}
|
|
|
|
var result = await _configService.SetMemberBenefitsImageAsync(request.ImageUrl);
|
|
return result ? ApiResponse.Success("设置成功") : ApiResponse.Error(40001, "设置失败");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取搜索页Banner
|
|
/// </summary>
|
|
[HttpGet("searchBanner")]
|
|
public async Task<ApiResponse<SearchBannerResponse>> GetSearchBanner()
|
|
{
|
|
var imageUrl = await _configService.GetSearchBannerAsync();
|
|
return ApiResponse<SearchBannerResponse>.Success(new SearchBannerResponse
|
|
{
|
|
ImageUrl = imageUrl
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置搜索页Banner
|
|
/// </summary>
|
|
[HttpPost("searchBanner")]
|
|
public async Task<ApiResponse> SetSearchBanner([FromBody] SetSearchBannerRequest request)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(request.ImageUrl))
|
|
{
|
|
return ApiResponse.Error(40001, "图片URL不能为空");
|
|
}
|
|
|
|
var result = await _configService.SetSearchBannerAsync(request.ImageUrl);
|
|
return result ? ApiResponse.Success("设置成功") : ApiResponse.Error(40001, "设置失败");
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 默认头像响应
|
|
/// </summary>
|
|
public class DefaultAvatarResponse
|
|
{
|
|
/// <summary>
|
|
/// 头像URL
|
|
/// </summary>
|
|
public string? AvatarUrl { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置默认头像请求
|
|
/// </summary>
|
|
public class SetDefaultAvatarRequest
|
|
{
|
|
/// <summary>
|
|
/// 头像URL
|
|
/// </summary>
|
|
public string AvatarUrl { get; set; } = string.Empty;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 协议响应
|
|
/// </summary>
|
|
public class AgreementResponse
|
|
{
|
|
/// <summary>
|
|
/// 协议内容
|
|
/// </summary>
|
|
public string Content { get; set; } = string.Empty;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置协议请求
|
|
/// </summary>
|
|
public class SetAgreementRequest
|
|
{
|
|
/// <summary>
|
|
/// 协议内容
|
|
/// </summary>
|
|
public string Content { get; set; } = string.Empty;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 会员权益长图响应
|
|
/// </summary>
|
|
public class MemberBenefitsImageResponse
|
|
{
|
|
/// <summary>
|
|
/// 图片URL
|
|
/// </summary>
|
|
public string? ImageUrl { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置会员权益长图请求
|
|
/// </summary>
|
|
public class SetMemberBenefitsImageRequest
|
|
{
|
|
/// <summary>
|
|
/// 图片URL
|
|
/// </summary>
|
|
public string ImageUrl { get; set; } = string.Empty;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 搜索页Banner响应
|
|
/// </summary>
|
|
public class SearchBannerResponse
|
|
{
|
|
/// <summary>
|
|
/// 图片URL
|
|
/// </summary>
|
|
public string? ImageUrl { get; set; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置搜索页Banner请求
|
|
/// </summary>
|
|
public class SetSearchBannerRequest
|
|
{
|
|
/// <summary>
|
|
/// 图片URL
|
|
/// </summary>
|
|
public string ImageUrl { get; set; } = string.Empty;
|
|
}
|