Skip to content

Commit

Permalink
完成第八章
Browse files Browse the repository at this point in the history
  • Loading branch information
MrChuJiu committed Jul 2, 2021
1 parent e892ebd commit e1a3b43
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 65 deletions.
2 changes: 1 addition & 1 deletion SwiftCode.BBS.API/Controllers/AuthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public async Task<MessageModel<string>> Login(string loginName, string loginPass
/// <param name="input"></param>
/// <returns></returns>
[HttpPost]
public async Task<MessageModel<string>> Register(RegisterInputDto input)
public async Task<MessageModel<string>> Register(CreateUserInfoInputDto input)
{
var userInfo = await _userInfoService.FindAsync(x => x.LoginName == input.LoginName);
if (userInfo != null)
Expand Down
2 changes: 1 addition & 1 deletion SwiftCode.BBS.API/Controllers/UserInfoController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public async Task<MessageModel<UserInfoDetailsDto>> GetAsync()
/// <param name="input"></param>
/// <returns></returns>
[HttpPut]
public async Task<MessageModel<string>> UpdateAsync(UserInfoInputDto input)
public async Task<MessageModel<string>> UpdateAsync(UpdateUserInfoInputDto input)
{
var token = JwtHelper.ParsingJwtToken(HttpContext);
var userInfo = await _userInfoService.GetAsync(x => x.Id == token.Uid);
Expand Down
4 changes: 2 additions & 2 deletions SwiftCode.BBS.API/SwiftCode.BBS.API.xml

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

9 changes: 9 additions & 0 deletions SwiftCode.BBS.EntityFramework/SwiftCodeBbsContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,19 @@ public SwiftCodeBbsContext(DbContextOptions<SwiftCodeBbsContext> options)
{

}
public DbSet<UserInfo> UserInfos { get; set; }

public DbSet<Article> Articles { get; set; }

public DbSet<Question> Questions { get; set; }

public DbSet<ArticleComment> ArticleComments { get; set; }

public DbSet<QuestionComment> QuestionComments { get; set; }

public DbSet<Advertisement> Advertisements { get; set; }


protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// 用户
Expand Down
2 changes: 1 addition & 1 deletion SwiftCode.BBS.Extensions/AutoMapper/UserInfoProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class UserInfoProfile : Profile
/// </summary>
public UserInfoProfile()
{
CreateMap<RegisterInputDto, UserInfo>();
CreateMap<CreateUserInfoInputDto, UserInfo>();
CreateMap<UserInfo, UserInfoDto>();

CreateMap<UserInfo, UserInfoDetailsDto>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class AutofacModuleRegister: Autofac.Module
protected override void Load(ContainerBuilder builder)
{

var basePath = AppContext.BaseDirectory;
builder.RegisterGeneric(typeof(BaseRepository<>)).As(typeof(IBaseRepository<>)).InstancePerDependency();
builder.RegisterGeneric(typeof(BaseServices<>)).As(typeof(IBaseServices<>)).InstancePerDependency();

Expand Down
3 changes: 2 additions & 1 deletion SwiftCode.BBS.IRepositories/BASE/IBaseRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public interface IBaseRepository<TEntity> where TEntity : class
Task<List<TEntity>> GetPagedListAsync(int skipCount, int maxResultCount, string sorting, CancellationToken cancellationToken = default);

Task<long> GetCountAsync(CancellationToken cancellationToken = default);
Task<long> GetCountAsync<TEntity>(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken) where TEntity : class, new();

Task<long> GetCountAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken);
}
}
44 changes: 22 additions & 22 deletions SwiftCode.BBS.Model/SwiftCode.BBS.Model.xml

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

16 changes: 0 additions & 16 deletions SwiftCode.BBS.Model/ViewModels/PagedDto.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace SwiftCode.BBS.Model.ViewModels.UserInfo
{
public class RegisterInputDto
public class CreateUserInfoInputDto
{
/// <summary>
/// 用户名
Expand Down
16 changes: 0 additions & 16 deletions SwiftCode.BBS.Model/ViewModels/UserInfo/TokenInfoViewModel.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace SwiftCode.BBS.Model.ViewModels.UserInfo
{
public class UserInfoInputDto
public class UpdateUserInfoInputDto
{
/// <summary>
/// 个人介绍
Expand Down
9 changes: 7 additions & 2 deletions SwiftCode.BBS.Repositories/BASE/BaseRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ public Task<TEntity> FindAsync(Expression<Func<TEntity, bool>> predicate, Cancel
{
return _context.Set<TEntity>().Where(predicate).SingleOrDefaultAsync(cancellationToken);
}

/// <summary>
/// 数据不存在会抛出异常
/// </summary>
/// <param name="predicate"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<TEntity> GetAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default)
{
var entity = await FindAsync(predicate, cancellationToken);
Expand Down Expand Up @@ -150,7 +155,7 @@ public Task<long> GetCountAsync(CancellationToken cancellationToken = default)
return _context.Set<TEntity>().LongCountAsync(cancellationToken);
}

public Task<long> GetCountAsync<TEntity1>(Expression<Func<TEntity1, bool>> predicate, CancellationToken cancellationToken) where TEntity1 : class, new()
public Task<long> GetCountAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken)
{
return _context.Set<TEntity>().Where(predicate).LongCountAsync(cancellationToken);
}
Expand Down

0 comments on commit e1a3b43

Please sign in to comment.