コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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));
        }
コード例 #5
0
 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!"));
 }