|
|
@ -2,6 +2,7 @@ using Microsoft.AspNetCore.Mvc;
|
|
|
|
using Server.Dto.Request;
|
|
|
|
using Server.Dto.Request;
|
|
|
|
using Server.Dto.Response;
|
|
|
|
using Server.Dto.Response;
|
|
|
|
using Asp.Versioning;
|
|
|
|
using Asp.Versioning;
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
using Server.IServices;
|
|
|
|
using Server.IServices;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Server.Controller.v1;
|
|
|
|
namespace Server.Controller.v1;
|
|
|
@ -39,4 +40,39 @@ public class UsersController : ControllerBase
|
|
|
|
var alumni = _dataServices.GetUserById(id);
|
|
|
|
var alumni = _dataServices.GetUserById(id);
|
|
|
|
return alumni.Result == null ? NotFound() : Ok(alumni);
|
|
|
|
return alumni.Result == null ? NotFound() : Ok(alumni);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
|
|
[ProducesResponseType(typeof(ResponseUserDto), StatusCodes.Status201Created)]
|
|
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
|
|
public async Task<IActionResult> CreateUser([FromBody] RequestUserDto request)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!ModelState.IsValid) return BadRequest(ModelState);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var createdUser = await _dataServices.CreateUser(request);
|
|
|
|
|
|
|
|
return CreatedAtAction(nameof(GetAlumniById), new { id = createdUser.Id }, createdUser);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPut("{id}")]
|
|
|
|
|
|
|
|
[ProducesResponseType(typeof(ResponseUserDto), StatusCodes.Status200OK)]
|
|
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
|
|
public async Task<IActionResult> UpdateUser(string id, [FromBody] RequestUserDto request)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!ModelState.IsValid) return BadRequest(ModelState);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var updatedProgram = await _dataServices.UpdateUser(id, request);
|
|
|
|
|
|
|
|
return updatedProgram == null ? NotFound() : Ok(updatedProgram);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpDelete("{id}")]
|
|
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
|
|
public async Task<IActionResult> DeleteUser(string id)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var deleted = await _dataServices.DeleteUser(id);
|
|
|
|
|
|
|
|
return deleted ? NoContent() : NotFound();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|