aboutsummaryrefslogtreecommitdiff
path: root/Backend/Api/Api/Controllers/UserController.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Backend/Api/Api/Controllers/UserController.cs')
-rw-r--r--Backend/Api/Api/Controllers/UserController.cs51
1 files changed, 51 insertions, 0 deletions
diff --git a/Backend/Api/Api/Controllers/UserController.cs b/Backend/Api/Api/Controllers/UserController.cs
new file mode 100644
index 0000000..4e0f0a3
--- /dev/null
+++ b/Backend/Api/Api/Controllers/UserController.cs
@@ -0,0 +1,51 @@
+using Api.Interfaces;
+using Api.Models;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+
+namespace Api.Controllers
+{
+ [Route("api/user/")]
+ public class UserController : Controller
+ {
+ private readonly IUserService _userService;
+ private readonly IJwtService _jwtService;
+ public UserController(IUserService userService, IJwtService jwtService)
+ {
+ _userService = userService;
+ _jwtService = jwtService;
+ }
+ [HttpPost("profile/pfp")]
+ [Authorize(Roles = "User")]
+ public async Task<ActionResult<User>> setPfp([FromBody] IFormFile image)
+ {
+ if (image == null)
+ return BadRequest();
+ var id = await _userService.UserIdFromJwt();
+ if (id == null)
+ return Unauthorized();
+ if(await _userService.AddOrChangePfp(id,image))
+ return Ok();
+ return BadRequest();
+ }
+ [HttpGet("profile")]
+ [Authorize(Roles = "User")]
+ public async Task<ActionResult<UserSend>> SelfProfile()
+ {
+ var id = await _userService.UserIdFromJwt();
+ var rez = await _userService.GetSelfUserData(id);
+ if (rez != null)
+ return Ok(rez);
+ return BadRequest();
+ }
+ [HttpGet("{username}/profile")]
+ [Authorize(Roles = "User")]
+ public async Task<ActionResult<UserSend>> GetProfile(string username)
+ {
+ var rez = await _userService.GetUserData(username);
+ if (rez != null)
+ return Ok(rez);
+ return BadRequest();
+ }
+ }
+}