64 lines
2.0 KiB
C#
64 lines
2.0 KiB
C#
|
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]
|
|||
|
[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]
|
|||
|
[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);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|