Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PersonalAccessToken and GetRolesByUserId #27

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.0.14</Version>
<Version>0.0.0.15</Version>
<Description>client generated code.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>microservice,auth,authentication,client</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using EasyMicroservices.Cores.Relational.EntityFrameworkCore;
using EasyMicroservices.Cores.Relational.EntityFrameworkCore.Intrerfaces;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;

namespace EasyMicroservices.AuthenticationsMicroservice.Database.Contexts
{
Expand All @@ -18,6 +19,7 @@ public AuthenticationsContext(IEntityFrameworkCoreDatabaseBuilder builder) : bas
public DbSet<ServicePermissionEntity> ServicePermissions { get; set; }
public DbSet<RoleServicePermissionEntity> RoleServicePermissions { get; set; }
public DbSet<RoleParentChildEntity> RoleParentChildren { get; set; }
public DbSet<PersonalAccessTokenEntity> PersonalAccessTokens { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using EasyMicroservices.AuthenticationsMicroservice.Database.Schemas;
using EasyMicroservices.Cores.Interfaces;

namespace EasyMicroservices.AuthenticationsMicroservice.Database.Entities
{
public class PersonalAccessTokenEntity : PersonalAccessTokenSchema, IIdSchema<long>
{
public long Id { get; set; }

public long UserId { get; set; }
public UserEntity User { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ public class UserEntity : UserSchema, IIdSchema<long>
{
public long Id { get; set; }
public ICollection<UserRoleEntity> UserRoles { get; set; }
public ICollection<PersonalAccessTokenEntity> PersonalAccessTokens { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using EasyMicroservices.Cores.Database.Schemas;

namespace EasyMicroservices.AuthenticationsMicroservice.Database.Schemas
{
public class PersonalAccessTokenSchema : FullAbilitySchema
{
public string Value { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using EasyMicroservices.Cores.Database.Schemas;

namespace EasyMicroservices.AuthenticationsMicroservice.Contracts.Common
{
public class PersonalAccessTokenContract : FullAbilityIdSchema<long>
{
public string Value { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using EasyMicroservices.Cores.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EasyMicroservices.Cores.Interfaces;

namespace EasyMicroservices.AuthenticationsMicroservice.Contracts.Common
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace EasyMicroservices.AuthenticationsMicroservice.Contracts.Requests
{
public class AddPersonalAccessTokenRequestContract
{
public long UserId { get; set; }
public string Value { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace EasyMicroservices.AuthenticationsMicroservice.Contracts.Requests
{
public class PersonalAccessTokenRequestContract
{
public string Value { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using EasyMicroservices.AuthenticationsMicroservice.Contracts.Common;
using EasyMicroservices.AuthenticationsMicroservice.Contracts.Requests;
using EasyMicroservices.AuthenticationsMicroservice.Database.Entities;
using EasyMicroservices.Cores.AspCoreApi;
using EasyMicroservices.Cores.Interfaces;

namespace EasyMicroservices.AuthenticationsMicroservice.WebApi.Controllers
{
public class PersonalAccessTokenController : SimpleQueryServiceController<PersonalAccessTokenEntity, AddPersonalAccessTokenRequestContract, PersonalAccessTokenContract, PersonalAccessTokenContract, long>
{
public PersonalAccessTokenController(IBaseUnitOfWork unitOfWork) : base(unitOfWork)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
using EasyMicroservices.AuthenticationsMicroservice.Contracts.Requests;
using EasyMicroservices.AuthenticationsMicroservice.Database.Entities;
using EasyMicroservices.Cores.AspCoreApi;
using EasyMicroservices.Cores.Contracts.Requests;
using EasyMicroservices.Cores.Interfaces;
using EasyMicroservices.ServiceContracts;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace EasyMicroservices.AuthenticationsMicroservice.WebApi.Controllers
{
Expand All @@ -11,5 +15,17 @@ public class RoleController : SimpleQueryServiceController<RoleEntity, AddRoleRe
public RoleController(IBaseUnitOfWork unitOfWork) : base(unitOfWork)
{
}

[HttpPost]
public async Task<ListMessageContract<RoleContract>> GetRolesByUserId(GetIdRequestContract<long> request)
{
var result = await UnitOfWork.GetLongLogic<UserRoleEntity>()
.GetAll(q => q.Include(x => x.User)
.Include(x => x.Role)
.Where(x => x.UserId == request.Id))
.AsCheckedResult();

return UnitOfWork.GetMapper().MapToList<RoleContract>(result.Select(x => x.Role));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using EasyMicroservices.AuthenticationsMicroservice.Contracts.Common;
using EasyMicroservices.AuthenticationsMicroservice.Contracts.Requests;
using EasyMicroservices.AuthenticationsMicroservice.Contracts.Responses;
using EasyMicroservices.AuthenticationsMicroservice.Database.Entities;
using EasyMicroservices.AuthenticationsMicroservice.Helpers;
using EasyMicroservices.Cores.AspCoreApi;
using EasyMicroservices.Cores.AspEntityFrameworkCoreApi.Interfaces;
using EasyMicroservices.ServiceContracts;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace EasyMicroservices.AuthenticationsMicroservice.WebApi.Controllers
{
Expand All @@ -32,6 +30,13 @@ public async Task<MessageContract<UserContract>> VerifyUserIdentity(UserSummaryC
return await _unitOfWork.GetContractLogic<UserEntity, AddUserRequestContract, UserContract, UserContract, long>().GetBy(x => x.UserName == request.UserName && x.Password == request.Password);
}

[HttpPost]
public async Task<MessageContract<UserContract>> GetUserByPersonalAccessToken(PersonalAccessTokenRequestContract request)
{
var result = await _unitOfWork.GetLongLogic<PersonalAccessTokenEntity>().GetBy(x => x.Value == request.Value
, q => q.Include(x => x.User)).AsCheckedResult();

return _unitOfWork.GetMapper().Map<UserContract>(result.User);
}
}
}
Loading