user mgmt done
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Torma Kristóf 2021-05-19 19:39:46 +02:00
parent 634488c2d8
commit 0b01340e88
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
6 changed files with 68 additions and 10 deletions

View File

@ -1,8 +1,6 @@
using HanyadikHetVan.Data.Entities;
using HanyadikHetVan.Services;
using HanyadikHetVan.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Security.Claims;
@ -16,12 +14,10 @@ namespace HanyadikHetVan.Controllers.V2
public class HanyadikHetVanController : Controller
{
private readonly HanyadikHetVanEntityService _hanyadikHetVanEntityService;
private readonly UserManager<User> _userManager;
public HanyadikHetVanController(HanyadikHetVanEntityService hanyadikHetVanEntityService, UserManager<User> userManager)
public HanyadikHetVanController(HanyadikHetVanEntityService hanyadikHetVanEntityService)
{
_hanyadikHetVanEntityService = hanyadikHetVanEntityService ?? throw new ArgumentNullException(nameof(hanyadikHetVanEntityService));
_userManager = userManager ?? throw new ArgumentNullException(nameof(userManager));
}
[HttpGet("{weeklytimespanId}")]
@ -56,7 +52,6 @@ namespace HanyadikHetVan.Controllers.V2
}
}
[HttpGet("my")]
[Authorize]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(int))]

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace HanyadikHetVan.DTO
{
public class UserDTO
{
public string Email { get; set; }
public string Password { get; set; }
}
}

View File

@ -0,0 +1,14 @@
using AutoMapper;
using HanyadikHetVan.Data.Entities;
using HanyadikHetVan.DTO;
namespace HanyadikHetVan.Profiles
{
public class UserProfile : Profile
{
public UserProfile()
{
CreateMap<User, UserDTO>();
}
}
}

View File

@ -22,14 +22,14 @@ namespace HanyadikHetVan.Services
public async Task<int> GetDefaultWeek()
{
var latest = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).LastAsync();
var latest = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).OrderBy(x => x.Id).LastAsync();
var latestDto = _mapper.Map<WeeklyTimeSpan, WeeklyTimeSpanDTO>(latest);
return latestDto.CurrentWeek;
}
public async Task<int> GetUserDefaultWeek(string userId)
{
var latest = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).Where(x => x.UserId == userId).LastAsync();
var latest = await _dbContext.WeeklyTimeSpans.Include(x => x.Pauses).Where(x => x.UserId == userId).OrderBy(x => x.Id).LastAsync();
var latestDto = _mapper.Map<WeeklyTimeSpan, WeeklyTimeSpanDTO>(latest);
return latestDto.CurrentWeek;
}

View File

@ -0,0 +1,36 @@
using HanyadikHetVan.Data.Entities;
using HanyadikHetVan.DTO;
using Microsoft.AspNetCore.Identity;
using System;
using System.Threading.Tasks;
namespace HanyadikHetVan.Services
{
public class UserService
{
private readonly UserManager<User> _userManager;
public UserService(UserManager<User> userManager)
{
_userManager = userManager ?? throw new ArgumentNullException(nameof(userManager));
}
public async Task<UserDTO> CreateUser(string email, string password)
{
var newUser = new User
{
UserName = email,
Email = email,
EmailConfirmed = true,
};
var result = await _userManager.CreateAsync(newUser,password);
if (!result.Succeeded)
{
throw new Exception("Failed to create user.");
}
return new UserDTO() { Email = email };
}
}
}

View File

@ -104,7 +104,6 @@ namespace HanyadikHetVan
{
c.SwaggerEndpoint("v1/swagger.json", "Original API");
c.SwaggerEndpoint("v2/swagger.json", "Homework API");
c.OAuthClientId("admin");
});
}
else