diff options
author | TAMARA JERINIC <tamara.jerinic@gmail.com> | 2022-12-06 04:17:14 +0100 |
---|---|---|
committer | TAMARA JERINIC <tamara.jerinic@gmail.com> | 2022-12-06 04:17:14 +0100 |
commit | 8e563f959c168a9778658c5fa2a2b143730d44fa (patch) | |
tree | e2a7c889e72dfa081d058e2132d10c9b7f5affc4 /Backend | |
parent | 1c70cfa2fd9fa455cabd9b05d354bdde56aca5fa (diff) |
Dodate funkcije za izmenu korisničkog imena i imena na back-u. Dodata aktivnost za izmenu korisničkog naloga. Izmenjen fragment myProfileInfo. Izmenjen FragmentProfile.
Diffstat (limited to 'Backend')
-rw-r--r-- | Backend/Api/Api/Controllers/UserController.cs | 18 | ||||
-rw-r--r-- | Backend/Api/Api/Interfaces/IUserService.cs | 4 | ||||
-rw-r--r-- | Backend/Api/Api/Services/UserService.cs | 50 |
3 files changed, 72 insertions, 0 deletions
diff --git a/Backend/Api/Api/Controllers/UserController.cs b/Backend/Api/Api/Controllers/UserController.cs index 97f2f8b..4937467 100644 --- a/Backend/Api/Api/Controllers/UserController.cs +++ b/Backend/Api/Api/Controllers/UserController.cs @@ -146,5 +146,23 @@ namespace Api.Controllers return Ok(tosend); return BadRequest(); } + + [HttpGet("{newUsername}/profile/changeMyUsername")] + [Authorize(Roles = "User")] + public async Task<ActionResult<int>> ChangeMyProfileUsername(string newUsername) + { + return await _userService.ChangeMyProfileUsername(newUsername); + } + + + [HttpGet("{id}/changeMyName")] + [Authorize(Roles = "User")] + public async Task<ActionResult<bool>> ChangeMyProfileName(string newName) + { + return Ok(await _userService.ChangeMyProfileName(newName)); + } + + + } } diff --git a/Backend/Api/Api/Interfaces/IUserService.cs b/Backend/Api/Api/Interfaces/IUserService.cs index 95dd46d..f4954e0 100644 --- a/Backend/Api/Api/Interfaces/IUserService.cs +++ b/Backend/Api/Api/Interfaces/IUserService.cs @@ -37,5 +37,9 @@ namespace Api.Interfaces Task<List<UserSend>> GetMyFollowers(); + Task<int> ChangeMyProfileUsername(String newUsername); + Task<bool> ChangeMyProfileName(String newUsername); + + } } diff --git a/Backend/Api/Api/Services/UserService.cs b/Backend/Api/Api/Services/UserService.cs index 666dd98..8597503 100644 --- a/Backend/Api/Api/Services/UserService.cs +++ b/Backend/Api/Api/Services/UserService.cs @@ -664,6 +664,56 @@ namespace Api.Services return null; } + public async Task<int> ChangeMyProfileUsername(string newUsername) + { + string myId = null; + + if (_httpContext.HttpContext.User.FindFirstValue("id") != null) + { + myId = _httpContext.HttpContext.User.FindFirstValue("id").ToString(); + } + User u = await _users.Find(user => user._id == myId).FirstOrDefaultAsync(); + if (u != null) + { + + //da li username vec postoji? + if (await _users.Find(x => x.username == newUsername).FirstOrDefaultAsync() != null) + { + //vec postoji korisnik sa navedenim korisnickim imenom + return -1; + } + else + { + u.username = newUsername; + await _users.ReplaceOneAsync(x => x._id == u._id, u); + return 1; + } + + } + return -2; + + } + + public async Task<bool> ChangeMyProfileName(string newName) + { + string myId = null; + if (_httpContext.HttpContext.User.FindFirstValue("id") != null) + { + myId = _httpContext.HttpContext.User.FindFirstValue("id").ToString(); + } + User u = await _users.Find(user => user._id == myId).FirstOrDefaultAsync(); + if (u != null) + { + + u.name = newName; + await _users.ReplaceOneAsync(x => x._id == u._id, u); + return true; + + } + return false; + } + + } } |