This commit is contained in:
parent
634488c2d8
commit
0b01340e88
@ -1,8 +1,6 @@
|
|||||||
using HanyadikHetVan.Data.Entities;
|
using HanyadikHetVan.Services;
|
||||||
using HanyadikHetVan.Services;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Identity;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System;
|
using System;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
@ -16,12 +14,10 @@ namespace HanyadikHetVan.Controllers.V2
|
|||||||
public class HanyadikHetVanController : Controller
|
public class HanyadikHetVanController : Controller
|
||||||
{
|
{
|
||||||
private readonly HanyadikHetVanEntityService _hanyadikHetVanEntityService;
|
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));
|
_hanyadikHetVanEntityService = hanyadikHetVanEntityService ?? throw new ArgumentNullException(nameof(hanyadikHetVanEntityService));
|
||||||
_userManager = userManager ?? throw new ArgumentNullException(nameof(userManager));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("{weeklytimespanId}")]
|
[HttpGet("{weeklytimespanId}")]
|
||||||
@ -56,7 +52,6 @@ namespace HanyadikHetVan.Controllers.V2
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[HttpGet("my")]
|
[HttpGet("my")]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(int))]
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(int))]
|
||||||
|
14
HanyadikHetVan/DTO/UserDTO.cs
Normal file
14
HanyadikHetVan/DTO/UserDTO.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
14
HanyadikHetVan/Profiles/UserProfile.cs
Normal file
14
HanyadikHetVan/Profiles/UserProfile.cs
Normal 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>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -22,14 +22,14 @@ namespace HanyadikHetVan.Services
|
|||||||
|
|
||||||
public async Task<int> GetDefaultWeek()
|
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);
|
var latestDto = _mapper.Map<WeeklyTimeSpan, WeeklyTimeSpanDTO>(latest);
|
||||||
return latestDto.CurrentWeek;
|
return latestDto.CurrentWeek;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<int> GetUserDefaultWeek(string userId)
|
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);
|
var latestDto = _mapper.Map<WeeklyTimeSpan, WeeklyTimeSpanDTO>(latest);
|
||||||
return latestDto.CurrentWeek;
|
return latestDto.CurrentWeek;
|
||||||
}
|
}
|
||||||
|
36
HanyadikHetVan/Services/UserService.cs
Normal file
36
HanyadikHetVan/Services/UserService.cs
Normal 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 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -104,7 +104,6 @@ namespace HanyadikHetVan
|
|||||||
{
|
{
|
||||||
c.SwaggerEndpoint("v1/swagger.json", "Original API");
|
c.SwaggerEndpoint("v1/swagger.json", "Original API");
|
||||||
c.SwaggerEndpoint("v2/swagger.json", "Homework API");
|
c.SwaggerEndpoint("v2/swagger.json", "Homework API");
|
||||||
c.OAuthClientId("admin");
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user