完善主题内容
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.AspNetCore.Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
public static class ControllerAddExtension
|
||||
{
|
||||
public static IMvcBuilder AddNewtonsoftJsonServer(this IMvcBuilder mvcBuilder)
|
||||
{
|
||||
return mvcBuilder.AddNewtonsoftJson(opt =>
|
||||
{
|
||||
//忽略循环引用
|
||||
opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
||||
//不改变字段大小
|
||||
//opt.SerializerSettings.ContractResolver = new DefaultContractResolver();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.13" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
|
||||
<PackageReference Include="NET.AutoApi" Version="1.0.5" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||
|
||||
@@ -27,22 +27,6 @@ LogLevel logLevel = LogLevel.Warning)
|
||||
Details = details;
|
||||
}
|
||||
|
||||
public UserFriendlyException(
|
||||
string message,
|
||||
ResultCodeEnum code = ResultCodeEnum.NotSuccess,
|
||||
string? details = null,
|
||||
Exception? innerException = null,
|
||||
LogLevel logLevel = LogLevel.Warning)
|
||||
: base(
|
||||
(int)code,
|
||||
message,
|
||||
details,
|
||||
innerException,
|
||||
logLevel)
|
||||
{
|
||||
Details = details;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 序列化参数的构造函数
|
||||
/// </summary>
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace Yi.Framework.Ddd.Services
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<TGetOutputDto> CreateAsync(TCreateInput input)
|
||||
public virtual async Task<TGetOutputDto> CreateAsync(TCreateInput input)
|
||||
{
|
||||
var entity = await MapToEntityAsync(input);
|
||||
|
||||
|
||||
@@ -14,6 +14,22 @@
|
||||
Discuss服务实现
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:Yi.BBS.Application.Forum.DiscussService.GetPlateIdAsync(System.Int64,Yi.BBS.Application.Contracts.Forum.Dtos.Discuss.DiscussGetListInputVo)">
|
||||
<summary>
|
||||
获取改板块下的主题
|
||||
</summary>
|
||||
<param name="plateId"></param>
|
||||
<param name="input"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:Yi.BBS.Application.Forum.DiscussService.CreatePlateIdAsync(System.Int64,Yi.BBS.Application.Contracts.Forum.Dtos.Discuss.DiscussCreateInputVo)">
|
||||
<summary>
|
||||
创建主题
|
||||
</summary>
|
||||
<param name="plateId"></param>
|
||||
<param name="input"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:Yi.BBS.Application.Forum.PlateService">
|
||||
<summary>
|
||||
Plate服务实现
|
||||
|
||||
@@ -4,5 +4,10 @@
|
||||
<name>Yi.BBS.Domain</name>
|
||||
</assembly>
|
||||
<members>
|
||||
<member name="T:Yi.BBS.Domain.Forum.ForumManager">
|
||||
<summary>
|
||||
论坛模块的领域服务
|
||||
</summary>
|
||||
</member>
|
||||
</members>
|
||||
</doc>
|
||||
|
||||
@@ -5,6 +5,7 @@ using Yi.Framework.Core;
|
||||
using Yi.Framework.Core.Attributes;
|
||||
using Yi.BBS.Application;
|
||||
using Yi.BBS.Sqlsugar;
|
||||
using Yi.Framework.AspNetCore.Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Yi.BBS.Web
|
||||
{
|
||||
|
||||
Binary file not shown.
@@ -1,3 +1,4 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -9,6 +10,7 @@ namespace Yi.BBS.Application.Contracts.Exhibition.Dtos.Banner
|
||||
{
|
||||
public class BannerGetListOutputDto : IEntityDto<long>
|
||||
{
|
||||
|
||||
public long Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string? Logo { get; set; }
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -9,6 +10,7 @@ namespace Yi.BBS.Application.Contracts.Exhibition.Dtos
|
||||
{
|
||||
public class BannerGetOutputDto : IEntityDto<long>
|
||||
{
|
||||
|
||||
public long Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string? Logo { get; set; }
|
||||
|
||||
@@ -11,13 +11,10 @@ namespace Yi.BBS.Application.Contracts.Forum.Dtos.Discuss
|
||||
/// </summary>
|
||||
public class DiscussCreateInputVo
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Types { get; set; }
|
||||
public string? Introduction { get; set; }
|
||||
public DateTime? CreateTime { get; set; }
|
||||
public int AgreeNum { get; set; }
|
||||
public int SeeNum { get; set; }
|
||||
public string Content { get; set; }
|
||||
public string? Color { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -9,6 +10,7 @@ namespace Yi.BBS.Application.Contracts.Forum.Dtos.Discuss
|
||||
{
|
||||
public class DiscussGetListOutputDto : IEntityDto<long>
|
||||
{
|
||||
|
||||
public long Id { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Types { get; set; }
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -9,6 +10,7 @@ namespace Yi.BBS.Application.Contracts.Forum.Dtos
|
||||
{
|
||||
public class DiscussGetOutputDto : IEntityDto<long>
|
||||
{
|
||||
|
||||
public long Id { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Types { get; set; }
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -9,6 +10,7 @@ namespace Yi.BBS.Application.Contracts.Forum.Dtos.Plate
|
||||
{
|
||||
public class PlateGetListOutputDto : IEntityDto<long>
|
||||
{
|
||||
|
||||
public long Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string? Logo { get; set; }
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -8,6 +9,7 @@ namespace Yi.BBS.Application.Contracts.Forum.Dtos.Plate
|
||||
{
|
||||
public class PlateUpdateInputVo
|
||||
{
|
||||
|
||||
public long Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string? Logo { get; set; }
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -8,7 +9,8 @@ namespace Yi.BBS.Application.Contracts.GlobalSetting.Dtos.Temp
|
||||
{
|
||||
public class ActionJwtDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public long Id { get; set; }
|
||||
public string ActionName { get; set; }
|
||||
public string Router { get; set; }
|
||||
public string Icon { get; set; }
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -18,6 +19,7 @@ namespace Yi.BBS.Application.Contracts.GlobalSetting.Dtos.Temp
|
||||
|
||||
public class LoginUserInfoDto
|
||||
{
|
||||
|
||||
public long Id { get; set; }
|
||||
|
||||
public string UserName { get; set; }
|
||||
|
||||
@@ -6,6 +6,10 @@ using Yi.Framework.Ddd.Services;
|
||||
using Yi.BBS.Application.Contracts.Forum.Dtos.Discuss;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Yi.Framework.Ddd.Dtos;
|
||||
using Yi.BBS.Domain.Forum;
|
||||
using AutoMapper;
|
||||
using SqlSugar;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
|
||||
namespace Yi.BBS.Application.Forum
|
||||
{
|
||||
@@ -16,12 +20,43 @@ namespace Yi.BBS.Application.Forum
|
||||
public class DiscussService : CrudAppService<DiscussEntity, DiscussGetOutputDto, DiscussGetListOutputDto, long, DiscussGetListInputVo, DiscussCreateInputVo, DiscussUpdateInputVo>,
|
||||
IDiscussService, IAutoApiService
|
||||
{
|
||||
private readonly ForumManager _forumManager;
|
||||
public DiscussService(ForumManager forumManager)
|
||||
{
|
||||
_forumManager = forumManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取改板块下的主题
|
||||
/// </summary>
|
||||
/// <param name="plateId"></param>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
public async Task<PagedResultDto<DiscussGetListOutputDto>> GetPlateIdAsync([FromRoute] long plateId, [FromQuery] DiscussGetListInputVo input)
|
||||
{
|
||||
var entities = await _repository.GetPageListAsync(x => x.PlateId == plateId, input);
|
||||
var items= await MapToGetListOutputDtosAsync(entities);
|
||||
var total = await _repository.CountAsync(x=>x.IsDeleted==false);
|
||||
var items = await MapToGetListOutputDtosAsync(entities);
|
||||
var total = await _repository.CountAsync(x => x.IsDeleted == false);
|
||||
return new PagedResultDto<DiscussGetListOutputDto>(total, items);
|
||||
}
|
||||
|
||||
[AutoApi(false)]
|
||||
public override Task<DiscussGetOutputDto> CreateAsync(DiscussCreateInputVo input)
|
||||
{
|
||||
return base.CreateAsync(input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建主题
|
||||
/// </summary>
|
||||
/// <param name="plateId"></param>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<DiscussGetOutputDto> CreatePlateIdAsync([FromRoute] long plateId, DiscussCreateInputVo input)
|
||||
{
|
||||
var entity = await _forumManager.CreateDiscussAsync(plateId, input.Title, input.Types, input.Content, input.Introduction);
|
||||
return await MapToGetOutputDtoAsync(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,5 +12,6 @@ namespace Yi.BBS.Domain.Shared.Forum.ConstClasses
|
||||
|
||||
public class PlateConst
|
||||
{
|
||||
public const string 板块不存在 = "传入的板块id不存在";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@ namespace Yi.BBS.Domain.Forum.Entities
|
||||
[SugarTable("Discuss")]
|
||||
public class DiscussEntity : IEntity<long>, ISoftDelete
|
||||
{
|
||||
public DiscussEntity()
|
||||
{
|
||||
}
|
||||
public DiscussEntity(long plateId)
|
||||
{
|
||||
PlateId = plateId;
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace Yi.BBS.Domain.Forum.Entities
|
||||
[SugarTable("Plate")]
|
||||
public class PlateEntity : IEntity<long>, ISoftDelete
|
||||
{
|
||||
|
||||
[SugarColumn(IsPrimaryKey = true)]
|
||||
public long Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.BBS.Domain.Forum.Entities;
|
||||
using Yi.BBS.Domain.Shared.Forum.ConstClasses;
|
||||
using Yi.Framework.Ddd.Repositories;
|
||||
|
||||
namespace Yi.BBS.Domain.Forum
|
||||
{
|
||||
/// <summary>
|
||||
/// 论坛模块的领域服务
|
||||
/// </summary>
|
||||
[AppService]
|
||||
public class ForumManager
|
||||
{
|
||||
private readonly IRepository<DiscussEntity> _discussRepository;
|
||||
private readonly IRepository<PlateEntity> _plateEntityRepository;
|
||||
public ForumManager(IRepository<DiscussEntity> discussRepository, IRepository<PlateEntity> plateEntityRepository)
|
||||
{
|
||||
_discussRepository = discussRepository;
|
||||
_plateEntityRepository = plateEntityRepository;
|
||||
}
|
||||
|
||||
//主题是不能直接创建的,需要由领域服务统一创建
|
||||
public async Task<DiscussEntity> CreateDiscussAsync(long plateId, string title, string types, string content, string? introduction = null)
|
||||
{
|
||||
if (!await _plateEntityRepository.IsAnyAsync(x => x.Id == plateId))
|
||||
{
|
||||
throw new UserFriendlyException(PlateConst.板块不存在);
|
||||
}
|
||||
var entity = new DiscussEntity(plateId);
|
||||
entity.Id = SnowflakeHelper.NextId;
|
||||
entity.Title = title;
|
||||
entity.Types = types;
|
||||
entity.Introduction = introduction;
|
||||
entity.Content = content;
|
||||
entity.CreateTime = DateTime.Now;
|
||||
entity.AgreeNum= 0;
|
||||
entity.SeeNum= 0;
|
||||
return await _discussRepository.InsertReturnEntityAsync(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user