This commit is contained in:
@ -1,7 +1,9 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using HanyadikHetVan.Data.Entities;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Net.Mime;
|
||||
using System.Security.Claims;
|
||||
|
||||
@ -12,9 +14,9 @@ namespace HanyadikHetVan.Controllers.V1
|
||||
[ApiController]
|
||||
public class TestController : Controller
|
||||
{
|
||||
private UserManager<IdentityUser> _userManager;
|
||||
private UserManager<User> _userManager;
|
||||
|
||||
public TestController(UserManager<IdentityUser> userManager)
|
||||
public TestController(UserManager<User> userManager)
|
||||
{
|
||||
_userManager = userManager ?? throw new ArgumentNullException(nameof(userManager));
|
||||
}
|
||||
@ -32,7 +34,7 @@ namespace HanyadikHetVan.Controllers.V1
|
||||
[Produces(MediaTypeNames.Application.Json)]
|
||||
public string Protected()
|
||||
{
|
||||
return this.User.FindFirst(ClaimTypes.NameIdentifier).Value;
|
||||
return this.User.FindFirst(ClaimTypes.Role).Value;
|
||||
}
|
||||
|
||||
[Authorize(Roles = "admin")]
|
||||
|
55
HanyadikHetVan/Controllers/V2/FunFactController.cs
Normal file
55
HanyadikHetVan/Controllers/V2/FunFactController.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using HanyadikHetVan.DTO;
|
||||
using HanyadikHetVan.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HanyadikHetVan.Controllers.V2
|
||||
{
|
||||
[ApiVersion("2.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[ApiController]
|
||||
public class FunFactController : Controller
|
||||
{
|
||||
private readonly FunFactService _funfactService;
|
||||
|
||||
public FunFactController(FunFactService funfactService)
|
||||
{
|
||||
_funfactService = funfactService ?? throw new ArgumentNullException(nameof(funfactService));
|
||||
}
|
||||
|
||||
[HttpPut("{weeklytimespanId}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(FunFactDTO))]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetFunFactOfWeeklyTimeSpan(int weeklytimespanId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var obj = await _funfactService.GetFunFactOfWeeklyTimeSpan(weeklytimespanId);
|
||||
return Ok(obj);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("{funfactId}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(FunFactDTO))]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetFunFactorOfFunFact(int funfactId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var obj = await _funfactService.GetFunFactorOfFunFact(funfactId);
|
||||
return Ok(obj);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,11 @@
|
||||
using HanyadikHetVan.Services;
|
||||
using HanyadikHetVan.Data.Entities;
|
||||
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;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HanyadikHetVan.Controllers.V2
|
||||
@ -12,10 +16,12 @@ namespace HanyadikHetVan.Controllers.V2
|
||||
public class HanyadikHetVanController : Controller
|
||||
{
|
||||
private readonly HanyadikHetVanEntityService _hanyadikHetVanEntityService;
|
||||
private readonly UserManager<User> _userManager;
|
||||
|
||||
public HanyadikHetVanController(HanyadikHetVanEntityService hanyadikHetVanEntityService)
|
||||
public HanyadikHetVanController(HanyadikHetVanEntityService hanyadikHetVanEntityService, UserManager<User> userManager)
|
||||
{
|
||||
_hanyadikHetVanEntityService = hanyadikHetVanEntityService ?? throw new ArgumentNullException(nameof(hanyadikHetVanEntityService));
|
||||
_userManager = userManager ?? throw new ArgumentNullException(nameof(userManager));
|
||||
}
|
||||
|
||||
[HttpGet("{weeklytimespanId}")]
|
||||
@ -49,5 +55,24 @@ namespace HanyadikHetVan.Controllers.V2
|
||||
return BadRequest();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("my")]
|
||||
[Authorize]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(int))]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
public async Task<IActionResult> GetUserDefaultWeek()
|
||||
{
|
||||
try
|
||||
{
|
||||
var wts = await _hanyadikHetVanEntityService.GetUserDefaultWeek(this.User.FindFirst(ClaimTypes.NameIdentifier).Value);
|
||||
return Ok(wts);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,63 +0,0 @@
|
||||
using HanyadikHetVan.DTO;
|
||||
using HanyadikHetVan.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Mime;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HanyadikHetVan.Controllers.V2
|
||||
{
|
||||
[ApiVersion("2.0")]
|
||||
[Route("api/v{version:apiVersion}/[controller]")]
|
||||
[ApiController]
|
||||
public class PurseController : Controller
|
||||
{
|
||||
private readonly PurseService _purseService;
|
||||
|
||||
public PurseController(PurseService purseService)
|
||||
{
|
||||
_purseService = purseService ?? throw new ArgumentNullException(nameof(purseService));
|
||||
}
|
||||
|
||||
[HttpPut("{userId}")]
|
||||
[Authorize(Roles = "admin")]
|
||||
[Consumes(MediaTypeNames.Application.Json)]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(PurseDTO))]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
public async Task<IActionResult> SetBalanceOfUser(string userId, [FromBody] PurseDTO pause)
|
||||
{
|
||||
try
|
||||
{
|
||||
var obj = await _purseService.SetBalanceOfUser(userId, pause.Balance);
|
||||
return Ok(obj);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("{userId}")]
|
||||
[Authorize(Roles = "admin")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(PurseDTO))]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
public async Task<IActionResult> GetPauseById(string userId)
|
||||
{
|
||||
var purse = await _purseService.GetBalanceOfUser(userId);
|
||||
if (purse == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
return Ok(purse);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,11 +1,14 @@
|
||||
using HanyadikHetVan.DTO;
|
||||
using HanyadikHetVan.Data.Entities;
|
||||
using HanyadikHetVan.DTO;
|
||||
using HanyadikHetVan.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Mime;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HanyadikHetVan.Controllers.V2
|
||||
@ -16,10 +19,12 @@ namespace HanyadikHetVan.Controllers.V2
|
||||
public class WeeklyTimeSpanController: Controller
|
||||
{
|
||||
private readonly WeeklyTimeSpanService _weeklytimespanService;
|
||||
private readonly UserManager<User> _userManager;
|
||||
|
||||
public WeeklyTimeSpanController(WeeklyTimeSpanService weeklytimespanService)
|
||||
public WeeklyTimeSpanController(WeeklyTimeSpanService weeklytimespanService, UserManager<User> userManager)
|
||||
{
|
||||
_weeklytimespanService = weeklytimespanService;
|
||||
_userManager = userManager ?? throw new ArgumentNullException(nameof(userManager));
|
||||
}
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
@ -31,7 +36,7 @@ namespace HanyadikHetVan.Controllers.V2
|
||||
{
|
||||
try
|
||||
{
|
||||
var obj = await _weeklytimespanService.AddWeeklyTimeSpan(weeklytimespan);
|
||||
var obj = await _weeklytimespanService.AddWeeklyTimeSpan(this.User.FindFirst(ClaimTypes.NameIdentifier).Value,weeklytimespan);
|
||||
return CreatedAtAction(nameof(GetWeeklyTimeSpanById), new { weeklytimespanId = obj.Id }, obj);
|
||||
}
|
||||
catch (Exception)
|
||||
|
Reference in New Issue
Block a user