public ActionResult <List <BlockDTO> > GetAllBlocks([FromHeader] string key) { if (!_authService.Authorize(key)) { return(StatusCode(StatusCodes.Status401Unauthorized, "User authorization failed!")); } var types = _blockingService.GetAllBlocks(); if (types == null || types.Count == 0) { return(StatusCode(StatusCodes.Status404NotFound, "No blocks found...")); } logger.LogInformation("Successfully returned list of blocks."); return(Ok(types)); }
public ActionResult <List <ForumDTO> > GetAllForums([FromHeader] string key) { if (!_authorizationService.AuthorizeUser(key)) { return(StatusCode(StatusCodes.Status401Unauthorized, "User authorization failed!")); } var forums = _forumService.GetAllForums(); if (forums == null || forums.Count == 0) { return(StatusCode(StatusCodes.Status404NotFound, "No forums found...")); } logger.LogInformation("Successfully returned list of all forums."); return(Ok(forums)); }
public ActionResult <List <RatingDTO> > GetAllRatings([FromHeader] string key) { if (!_authService.Authorize(key)) { return(StatusCode(StatusCodes.Status401Unauthorized, "User authorization failed!")); } var ratings = _ratingService.GetAllRatings(); if (ratings == null || ratings.Count == 0) { return(StatusCode(StatusCodes.Status404NotFound, "No raitings found...")); } logger.LogInformation("Successfully returned list of all ratings."); return(Ok(ratings)); }
public ActionResult <List <MessageDTO> > GetAllMessages([FromHeader] string key) { if (!key.Equals("Bearer URIS2021")) { return(StatusCode(StatusCodes.Status401Unauthorized, "User authorization failed!")); } var mess = _messageService.GetAllMessages(); if (mess == null || mess.Count == 0) { return(StatusCode(StatusCodes.Status404NotFound, "No messages found...")); } logger.LogInformation("Successfully returned list of all messsages."); return(Ok(mess)); }
public ActionResult <PostDto> CreateNewPost([FromHeader] string secretToken, [FromBody] PostCreationDto newPost) { if (authorizationMockService.AuthorizeToken(secretToken)) { try { var toBeCreated = postService.CreatePost(newPost); loggerRepository.LogInformation("New post successfuly created!"); return(StatusCode(201, toBeCreated)); } catch (Exception ex) { if (ex.Message == "User not found!" || ex.Message == "Type not found!") { return(StatusCode(404, ex.Message)); } return(StatusCode(500, ex.Message)); } } return(StatusCode(StatusCodes.Status401Unauthorized, "Authorization failed!")); }