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.cs59
1 files changed, 59 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..1ef8234
--- /dev/null
+++ b/Backend/Api/Api/Controllers/UserController.cs
@@ -0,0 +1,59 @@
+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;
+ private readonly IPostService _postService;
+ public UserController(IUserService userService, IJwtService jwtService, IPostService postService)
+ {
+ _userService = userService;
+ _jwtService = jwtService;
+ _postService = postService;
+ }
+ [HttpPost("profile/pfp")]
+ [Authorize(Roles = "User")]
+ public async Task<ActionResult<User>> setPfp([FromForm]IFormFile image)
+ {
+ var id = await _userService.UserIdFromJwt();
+ 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();
+ }
+ [HttpGet("posts")]
+ [Authorize(Roles = "User")]
+ public async Task<ActionResult<List<PostSend>>> SelfPosts()
+ {
+ var id = await _userService.UserIdFromJwt();
+ var rez = await _postService.GetUsersPosts(id);
+ if (rez != null)
+ return Ok(rez);
+ return BadRequest();
+ }
+ }
+}