点赞功能接口开发
This commit is contained in:
@@ -4,21 +4,6 @@
|
||||
<name>Yi.Framework.ApiMicroservice</name>
|
||||
</assembly>
|
||||
<members>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.ArticleController.PageList(Yi.Framework.Model.Models.ArticleEntity,Yi.Framework.Common.Models.PageParModel)">
|
||||
<summary>
|
||||
动态条件分页查询
|
||||
</summary>
|
||||
<param name="entity"></param>
|
||||
<param name="page"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.ArticleController.Add(Yi.Framework.Model.Models.ArticleEntity)">
|
||||
<summary>
|
||||
添加
|
||||
</summary>
|
||||
<param name="entity"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:Yi.Framework.ApiMicroservice.Controllers.BaseCrudController`1">
|
||||
<summary>
|
||||
Json To Sql 类比模式,通用模型
|
||||
@@ -150,6 +135,33 @@
|
||||
<param name="ids"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.AgreeController.Operate(System.Int64)">
|
||||
<summary>
|
||||
点赞操作
|
||||
</summary>
|
||||
<param name="articleId"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:Yi.Framework.ApiMicroservice.Controllers.ArticleController">
|
||||
<summary>
|
||||
文章控制器
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.ArticleController.PageList(Yi.Framework.Model.Models.ArticleEntity,Yi.Framework.Common.Models.PageParModel)">
|
||||
<summary>
|
||||
动态条件分页查询
|
||||
</summary>
|
||||
<param name="entity"></param>
|
||||
<param name="page"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.ArticleController.Add(Yi.Framework.Model.Models.ArticleEntity)">
|
||||
<summary>
|
||||
添加
|
||||
</summary>
|
||||
<param name="entity"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.Framework.ApiMicroservice.Controllers.SkuController.PageList(Yi.Framework.Model.Models.SkuEntity,Yi.Framework.Common.Models.PageParModel)">
|
||||
<summary>
|
||||
动态条件分页查询
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Org.BouncyCastle.Asn1.IsisMtt.X509;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.DTOModel.Vo;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
using Yi.Framework.Service;
|
||||
using Yi.Framework.WebCore;
|
||||
using Yi.Framework.WebCore.AttributeExtend;
|
||||
using Yi.Framework.WebCore.AuthorizationPolicy;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class AgreeController : ControllerBase
|
||||
{
|
||||
[Autowired]
|
||||
public IAgreeService _iAgreeService { get; set; }
|
||||
[Autowired]
|
||||
public IArticleService _iArticleService { get; set; }
|
||||
[Autowired]
|
||||
public ILogger<AgreeEntity> _logger { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 点赞操作
|
||||
/// </summary>
|
||||
/// <param name="articleId"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public async Task<Result> Operate(long articleId)
|
||||
{
|
||||
//long userId = HttpContext.GetUserIdInfo();
|
||||
long userId = 1L;
|
||||
var article = await _iArticleService._repository.GetByIdAsync(articleId);
|
||||
if (await _iAgreeService._repository.IsAnyAsync(u => u.UserId == userId && u.ArticleId == articleId))
|
||||
{
|
||||
//已点赞,取消点赞
|
||||
await _iAgreeService._repository.UseTranAsync(async () =>
|
||||
{
|
||||
await _iAgreeService._repository.DeleteAsync(u => u.UserId == userId && u.ArticleId == articleId);
|
||||
await _iArticleService._repository.UpdateIgnoreNullAsync(new ArticleEntity { Id = articleId, AgreeNum = article.AgreeNum - 1 });
|
||||
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
//未点赞,添加点赞记录
|
||||
await _iAgreeService._repository.UseTranAsync(async () =>
|
||||
{
|
||||
await _iAgreeService._repository.InsertAsync(new AgreeEntity { UserId = userId, ArticleId = articleId });
|
||||
await _iArticleService._repository.UpdateIgnoreNullAsync(new ArticleEntity { Id = articleId, AgreeNum = article.AgreeNum + 1 });
|
||||
});
|
||||
|
||||
}
|
||||
return Result.Success("这里业务全部拆开放service层去");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Common.Models;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.DTOModel.Vo;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
@@ -17,6 +17,9 @@ using Yi.Framework.WebCore.AuthorizationPolicy;
|
||||
|
||||
namespace Yi.Framework.ApiMicroservice.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 文章控制器
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/[controller]/[action]")]
|
||||
public class ArticleController : BaseSimpleCrudController<ArticleEntity>
|
||||
@@ -1,6 +1,4 @@
|
||||
using Hangfire;
|
||||
using Hangfire.MemoryStorage.Database;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
@@ -18,8 +18,6 @@ using Yi.Framework.WebCore.LogExtend;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using Yi.Framework.WebCore.AutoFacExtend;
|
||||
using Hangfire;
|
||||
using Hangfire.MemoryStorage;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Configuration.AddCommandLine(args);
|
||||
@@ -43,14 +41,14 @@ builder.Host.ConfigureContainer<ContainerBuilder>(containerBuilder =>
|
||||
#region
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>ģ<EFBFBD><C4A3>
|
||||
#endregion
|
||||
//containerBuilder.RegisterModule<PropertiesAutowiredModule>();
|
||||
containerBuilder.RegisterModule<PropertiesAutowiredModule>();
|
||||
#region
|
||||
//ʹ<><CAB9>AppService<63><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ŵĽ<C5B5><C4BD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>,<2C>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ø<EFBFBD><C3B8>ַ<EFBFBD>ʽ<EFBFBD>Զ<EFBFBD>ע<EFBFBD><D7A2>
|
||||
#endregion
|
||||
containerBuilder.AddAutoIocService("Yi.Framework.Repository", "Yi.Framework.Service");
|
||||
});
|
||||
////<2F><><EFBFBD><EFBFBD>ע<EFBFBD>룬<EFBFBD><EBA3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>mvcģ<63><C4A3>ת<EFBFBD>Ӹ<EFBFBD>ioc
|
||||
//builder.Services.Replace(ServiceDescriptor.Transient<IControllerActivator, ServiceBasedControllerActivator>());
|
||||
builder.Services.Replace(ServiceDescriptor.Transient<IControllerActivator, ServiceBasedControllerActivator>());
|
||||
|
||||
builder.Host.ConfigureLogging(loggingBuilder =>
|
||||
{
|
||||
|
||||
Binary file not shown.
@@ -8,8 +8,6 @@
|
||||
<PackageReference Include="AlibabaCloud.SDK.Dysmsapi20170525" Version="2.0.8" />
|
||||
<PackageReference Include="Consul" Version="1.6.10.3" />
|
||||
<PackageReference Include="CSRedisCore" Version="3.6.9" />
|
||||
<PackageReference Include="Hangfire.AspNetCore" Version="1.7.32" />
|
||||
<PackageReference Include="Hangfire.MemoryStorage" Version="1.7.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="6.0.1" />
|
||||
|
||||
@@ -4,32 +4,32 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.DTOModel
|
||||
namespace Yi.Framework.DTOModel.Vo
|
||||
{
|
||||
public class ArticleVo
|
||||
{
|
||||
public long Id { get; set; }
|
||||
|
||||
|
||||
public string Title { get; set; }
|
||||
|
||||
|
||||
public string Content { get; set; }
|
||||
|
||||
|
||||
public long? UserId { get; set; }
|
||||
|
||||
public long? CreateUser { get; set; }
|
||||
|
||||
|
||||
public DateTime? CreateTime { get; set; }
|
||||
|
||||
|
||||
public long? ModifyUser { get; set; }
|
||||
|
||||
|
||||
public DateTime? ModifyTime { get; set; }
|
||||
|
||||
|
||||
public bool? IsDeleted { get; set; }
|
||||
|
||||
|
||||
public long? TenantId { get; set; }
|
||||
|
||||
|
||||
public int? OrderNum { get; set; }
|
||||
|
||||
|
||||
public string Remark { get; set; }
|
||||
public List<string> Images { get; set; }
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.DTOModel
|
||||
namespace Yi.Framework.DTOModel.Vo
|
||||
{
|
||||
/// <summary>
|
||||
/// 前端只需要这些数据即可
|
||||
@@ -0,0 +1,9 @@
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Interface
|
||||
{
|
||||
public partial interface IAgreeService:IBaseService<AgreeEntity>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
using SqlSugar;
|
||||
namespace Yi.Framework.Model.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 点赞表
|
||||
///</summary>
|
||||
[SugarTable("Agree")]
|
||||
public partial class AgreeEntity
|
||||
{
|
||||
public AgreeEntity()
|
||||
{
|
||||
this.CreateTime = DateTime.Now;
|
||||
}
|
||||
[JsonConverter(typeof(ValueToStringConverter))]
|
||||
[SugarColumn(ColumnName="Id" ,IsPrimaryKey = true )]
|
||||
public long Id { get; set; }
|
||||
/// <summary>
|
||||
/// 用户id
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="UserId" )]
|
||||
public long? UserId { get; set; }
|
||||
/// <summary>
|
||||
/// 文章id
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="ArticleId" )]
|
||||
public long? ArticleId { get; set; }
|
||||
/// <summary>
|
||||
/// 创建者
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="CreateUser" )]
|
||||
public long? CreateUser { get; set; }
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="CreateTime" )]
|
||||
public DateTime? CreateTime { get; set; }
|
||||
/// <summary>
|
||||
/// 租户Id
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="TenantId" )]
|
||||
public long? TenantId { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -22,12 +22,12 @@ namespace Yi.Framework.Model.Models
|
||||
/// 文章标题
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Title" )]
|
||||
public string? Title { get; set; }
|
||||
public string Title { get; set; }
|
||||
/// <summary>
|
||||
/// 文章内容
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Content" )]
|
||||
public string? Content { get; set; }
|
||||
public string Content { get; set; }
|
||||
/// <summary>
|
||||
/// 用户id
|
||||
///</summary>
|
||||
@@ -72,11 +72,16 @@ namespace Yi.Framework.Model.Models
|
||||
/// 描述
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Remark" )]
|
||||
public string? Remark { get; set; }
|
||||
public string Remark { get; set; }
|
||||
/// <summary>
|
||||
/// 图片列表
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="Images",IsJson = true)]
|
||||
public List<string>? Images { get; set; }
|
||||
[SugarColumn(ColumnName="Images" )]
|
||||
public string Images { get; set; }
|
||||
/// <summary>
|
||||
/// 点赞数量
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName="AgreeNum" )]
|
||||
public int? AgreeNum { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
using SqlSugar;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Repository;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public partial class AgreeService : BaseService<AgreeEntity>, IAgreeService
|
||||
{
|
||||
public AgreeService(IRepository<AgreeEntity> repository) : base(repository)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.DTOModel;
|
||||
using Yi.Framework.DTOModel.Vo;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.WebCore.Mapper
|
||||
|
||||
Reference in New Issue
Block a user