Skip to content

Commit

Permalink
Revert "Update (#2)"
Browse files Browse the repository at this point in the history
This reverts commit 99bbf12.
  • Loading branch information
Zenrac authored Dec 17, 2020
1 parent 99bbf12 commit 7f537b5
Show file tree
Hide file tree
Showing 29 changed files with 189 additions and 2,165 deletions.
26 changes: 0 additions & 26 deletions .release-it.json

This file was deleted.

11 changes: 0 additions & 11 deletions generators/client/files-blazor.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@ const CLIENT_TEST_DIR = constants.CLIENT_TEST_DIR;
* For any other config an object { file:.., method:.., template:.. } can be used
*/
const files = {
blazorAutoMapperProfiles: [
{
path: CLIENT_SRC_DIR,
templates: [
{
file: 'Project.Client/AutoMapper/AutoMapperProfile.cs',
renameTo: generator => `${generator.mainClientDir}/AutoMapper/AutoMapperProfile.cs`,
},
],
},
],
blazorAppModels: [
{
path: CLIENT_SRC_DIR,
Expand Down
11 changes: 0 additions & 11 deletions generators/client/needle-api/needle-client-blazor.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,4 @@ module.exports = class extends needleBase {

this.addBlockContentToFile(rewriteFileModel, errorMessage);
}

addDtoMapping(entityName) {
const errorMessage = `${chalk.yellow('Reference to ') + entityName} ${chalk.yellow('not added to AutoMapper.\n')}`;
const autoMapperProfilePath = `src/${this.mainClientDir}/AutoMapper/AutoMapperProfile.cs`;
const mappingEntry =
// prettier-ignore
this.generator.stripMargin(`|CreateMap<${entityName}Model, ${entityName}Dto>().ReverseMap();`);
const rewriteFileModel = this.generateFileModel(autoMapperProfilePath, 'jhipster-needle-add-dto-model-mapping', mappingEntry);

this.addBlockContentToFile(rewriteFileModel, errorMessage);
}
};

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
</dl>

<button type="submit" @onclick="@Back" class="btn btn-info">
<Icon Name='"fa-arrow-left"' />&nbsp;<span>Back</span>
<fa-icon icon="arrow-left"></fa-icon>&nbsp;<span>Back</span>
</button>
</div>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@
@foreach (var user in UserModels)
{
<tr>
<td><a href="/admin/user-management/@user.Login/view">@user.Id</a></td>
<td><a href="/user-management/@user.Login/view">@user.Id</a></td>
<td>@user.Login</td>
<td>@user.Email</td>
<td>
@if (user.Activated)
{
@if (AuthenticationService?.CurrentUser?.Login == user.Login)
@if (AuthenticationService.CurrentUser.Login == user.Login)
{
<button class="btn btn-success btn-sm" disabled @onclick=@(() => ActiveUser(user, false))>
Activated
Expand Down Expand Up @@ -91,7 +91,7 @@
<span class="d-none d-md-inline">Edit</span>
</a>

@if (AuthenticationService?.CurrentUser?.Login == user.Login)
@if (AuthenticationService.CurrentUser.Login == user.Login)
{
<button type="button" @onclick=@(() => DeleteUser(user.Login)) disabled
class="btn btn-danger btn-sm">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
using System;
using System.Net.Http;
using System.Reflection;
using System.Threading.Tasks;
using AutoMapper;
using Blazored.Modal;
using Blazored.SessionStorage;
using Blazorise;
using Blazorise.Bootstrap;
using Blazorise.Icons.FontAwesome;
using <%= namespace %>.Client.Pages.Utils;
using <%= namespace %>.Client.Services;
using <%= namespace %>.Client.Services.AccountServices;
using <%= namespace %>.Client.Services.EntityServices;
// jhipster-needle-add-using-for-services - JHipster will add using services
using <%= namespace %>.Client.Services.EntityServices.User;
Expand Down Expand Up @@ -40,13 +37,10 @@ namespace <%= namespace %>.Client
builder.Services.AddSingleton<ISessionStorageService, SessionStorageService>().AddSingleton<ISyncSessionStorageService, SessionStorageService>();
builder.Services.AddBlazoredModal();

builder.Services.AddAutoMapper(Assembly.GetExecutingAssembly());

builder.Services.AddSingleton<AuthenticationStateProvider, AuthenticationService>();
builder.Services.AddSingleton<INavigationService, NavigationService>();

builder.Services.AddSingleton<IUserService, UserService>();
builder.Services.AddSingleton<IRegisterService, RegisterService>();

// jhipster-needle-add-services-in-di - JHipster will add services in DI

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="10.1.1" />
<PackageReference Include="Blazored.Modal" Version="5.1.0" />
<PackageReference Include="Blazored.SessionStorage" Version="1.0.12" />
<PackageReference Include="Blazorise.Bootstrap" Version="0.9.1.2" />
Expand Down Expand Up @@ -84,7 +83,6 @@


<ItemGroup>
<ProjectReference Include="..\..\<%= namespace %>.Dto\<%= namespace %>.Dto.csproj" />
<ProjectReference Include="..\<%= namespace %>.Client.Shared\<%= namespace %>.Client.Shared.csproj" />
<ProjectReference Include="..\..\<%= namespace %>.Crosscutting\<%= namespace %>.Crosscutting.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading.Tasks;
using AutoMapper;
using <%= namespace %>.Dto;
using <%= namespace %>.Client.Models;

namespace <%= namespace %>.Client.Services.AccountServices
Expand All @@ -29,19 +27,16 @@ namespace <%= namespace %>.Client.Services.AccountServices
private const string RegisterUrl = "/api/register";

private readonly HttpClient _httpClient;
private readonly IMapper _mapper;

public RegisterService(HttpClient httpClient, IMapper mapper)
public RegisterService(HttpClient httpClient)
{
_httpClient = httpClient;
_mapper = mapper;
_httpClient.BaseAddress = new Uri(Configuration.BaseUri);
}

public async Task<HttpResponseMessage> Save(UserSaveModel registerModel)
{
var registerDto = _mapper.Map<ManagedUserDto>(registerModel);
return await _httpClient.PostAsJsonAsync(RegisterUrl, registerDto);
return await _httpClient.PostAsJsonAsync(RegisterUrl, registerModel);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ using System.Net.Http;
using System.Net.Http.Json;
using System.Security.Claims;
using System.Threading.Tasks;
using AutoMapper;
using Blazored.SessionStorage;
using <%= namespace %>.Client.Models;
using <%= namespace %>.Dto;
using Microsoft.AspNetCore.Components.Authorization;

namespace <%= namespace %>.Client.Services
Expand All @@ -36,17 +34,15 @@ namespace <%= namespace %>.Client.Services

private readonly HttpClient _httpClient;
private readonly ISyncSessionStorageService _sessionStorage;
private readonly IMapper _mapper;

public bool IsAuthenticated { get; set; }
public UserModel CurrentUser { get; set; }
public JwtToken JwtToken { get; set; }

public AuthenticationService(HttpClient httpClient, ISyncSessionStorageService sessionStorage, IMapper mapper)
public AuthenticationService(HttpClient httpClient, ISyncSessionStorageService sessionStorage)
{
_httpClient = httpClient;
_sessionStorage = sessionStorage;
_mapper = mapper;
_httpClient.BaseAddress = new Uri(Configuration.BaseUri);
var token = _sessionStorage.GetItem<string>(JhiAuthenticationtoken);
if (!string.IsNullOrEmpty(token))
Expand All @@ -58,8 +54,7 @@ namespace <%= namespace %>.Client.Services

public async Task<bool> SignIn(LoginModel loginModel)
{
var loginDto = _mapper.Map<LoginDto>(loginModel);
var result = await _httpClient.PostAsJsonAsync(AuthenticatationUrl, loginDto);
var result = await _httpClient.PostAsJsonAsync(AuthenticatationUrl, loginModel);
if (result.IsSuccessStatusCode)
{
JwtToken = await result.Content.ReadFromJsonAsync<JwtToken>();
Expand All @@ -86,8 +81,7 @@ namespace <%= namespace %>.Client.Services
_httpClient.DefaultRequestHeaders.Add(AuthorizationHeader, $"Bearer {jwtToken.IdToken}");
try
{
var userDto = await _httpClient.GetFromJsonAsync<UserDto>(AccountUrl);
CurrentUser = _mapper.Map<UserModel>(userDto);
CurrentUser = await _httpClient.GetFromJsonAsync<UserModel>(AccountUrl);
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,23 @@ using System.Net.Http.Json;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using AutoMapper;
using <%= namespace %>.Client.Models;
using Microsoft.AspNetCore.Components.Authorization;

namespace <%= namespace %>.Client.Services.EntityServices
{
public class AbstractEntityService<TModel, TDto> where TModel : class
where TDto : class
public class AbstractEntityService<T> where T : class
{
private const string AuthorizationHeader = "Authorization";
private readonly AuthenticationStateProvider _authenticationStateProvider;
private readonly JsonSerializerOptions _options;

protected readonly HttpClient _httpClient;
protected readonly IMapper _mapper;

protected JwtToken JwtToken { get; set; }
protected string BaseUrl { get; }

public AbstractEntityService(HttpClient httpClient, AuthenticationStateProvider authenticationStateProvider, IMapper mapper, string baseUrl)
public AbstractEntityService(HttpClient httpClient, AuthenticationStateProvider authenticationStateProvider, string baseUrl)
{
_httpClient = httpClient;
_authenticationStateProvider = authenticationStateProvider;
Expand All @@ -50,7 +47,6 @@ namespace <%= namespace %>.Client.Services.EntityServices
_httpClient.DefaultRequestHeaders.Add(AuthorizationHeader, $"Bearer {JwtToken.IdToken}");
}
BaseUrl = baseUrl;
_mapper = mapper;
_options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
Expand All @@ -62,28 +58,24 @@ namespace <%= namespace %>.Client.Services.EntityServices
};
}

public virtual async Task<IList<TModel>> GetAll()
public virtual async Task<IList<T>> GetAll()
{
var resultsDto = await _httpClient.GetFromJsonAsync<IList<TDto>>(BaseUrl, _options);
return _mapper.Map<IList<TModel>>(resultsDto);
return await _httpClient.GetFromJsonAsync<IList<T>>(BaseUrl, _options);
}

public virtual async Task<TModel> Get(string id)
public virtual async Task<T> Get(string id)
{
var resultDto = await _httpClient.GetFromJsonAsync<TModel>($"{BaseUrl}/{id}", _options);
return _mapper.Map<TModel>(resultDto);
return await _httpClient.GetFromJsonAsync<T>($"{BaseUrl}/{id}", _options);
}

public virtual async Task Add(TModel model)
public virtual async Task Add(T model)
{
var dto = _mapper.Map<TDto>(model);
await _httpClient.PostAsJsonAsync(BaseUrl, dto, _options);
await _httpClient.PostAsJsonAsync(BaseUrl, model, _options);
}

public virtual async Task Update(TModel model)
public virtual async Task Update(T model)
{
var dto = _mapper.Map<TDto>(model);
await _httpClient.PutAsJsonAsync(BaseUrl, dto, _options);
await _httpClient.PutAsJsonAsync(BaseUrl, model, _options);
}

public virtual async Task Delete(string id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using <%= namespace %>.Client.Models;
using <%= namespace %>.Dto;

namespace <%= namespace %>.Client.Services.EntityServices.User
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using System.Threading.Tasks;
using AutoMapper;
using <%= namespace %>.Client.Models;
using <%= namespace %>.Dto;
using Microsoft.AspNetCore.Components.Authorization;

namespace <%= namespace %>.Client.Services.EntityServices.User
{
public class UserService : AbstractEntityService<UserModel, UserDto>,IUserService
public class UserService : AbstractEntityService<UserModel>,IUserService
{
public UserService(HttpClient httpClient, AuthenticationStateProvider authenticationStateProvider, IMapper mapper) : base(httpClient, authenticationStateProvider, mapper, "/api/users")
public UserService(HttpClient httpClient, AuthenticationStateProvider authenticationStateProvider) : base(httpClient, authenticationStateProvider, "/api/users")
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ using System.Security.Claims;
using System.Threading.Tasks;
using AutoFixture;
using Blazored.Modal.Services;
using Blazorise;
using Blazorise.Bootstrap;
using Blazorise.Icons.FontAwesome;
using Bunit;
using Bunit.Rendering;
using FluentAssertions;
Expand All @@ -46,12 +43,6 @@ namespace <%= namespace %>.Client.Test.Pages.Admin.UserManagement
{
_userService = new Mock<IUserService>();
_navidationService = new Mock<INavigationService>();
Services.AddBlazorise(options =>
{
options.ChangeTextOnKeyPress = true;
})
.AddBootstrapProviders()
.AddFontAwesomeIcons();
Services.AddSingleton<IUserService>(_userService.Object);
Services.AddSingleton<INavigationService>(_navidationService.Object);
}
Expand Down
1 change: 0 additions & 1 deletion generators/entity-client/files-blazor.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,4 @@ function writeFiles() {
blazorNeedle.addEntityToMenu(this.entityClass);
blazorNeedle.addServiceInDI(this.entityClass);
blazorNeedle.addUsingForService(this.namespace, this.entityClass);
blazorNeedle.addDtoMapping(this.entityClass);
}
Loading

0 comments on commit 7f537b5

Please sign in to comment.