public void updateUsername(UpdateUsernameDTO newUser) { // Make sure the object is not empty if (newUser.username == null || newUser.password == null || newUser.email == null || newUser.fullName == null || newUser.accessToken == null || newUser.newUsername == null) { throw new InvalidParametersException("All parameters of UpdateUsernameDTO must be set"); } // If the int is NULL the user does not exist int?userId = _mapper.getUserId(newUser.username); if (userId == null) { throw new InvalidParametersException("No user found"); } // Authenticate, if this equates to True we did not Authenticate with given information if (!_tokenService.validateUserToken(newUser.accessToken, (int)userId)) { throw new InvalidParametersException("To favourite a video you must use a valid token and a valid username"); } // Make a DataLayer Call _mapper.changeUsername((int)userId, newUser.newUsername); }
public IActionResult updateUsername(UpdateUsernameDTO user) { string accessToken = Request.Headers["Authorization"]; user.accessToken = accessToken; // Basic API -> Service Cals // Receive Object Through Post/Get Request // Pass Object Too Service Layer // Catch Defined Errors Else Return 2xx Message try { _userService.updateUsername(user); return(Ok()); } catch (InvalidParametersException e) { return(BadRequest(e.Message)); } catch (DuplicateException e) { return(new BadRequestObjectResult(e.Message)); } }