예제 #1
0
        public ActionResult <GetContentsResponse> GetStarredContents()
        {
            try
            {
                var userId = Int32.Parse(User.Identity.Name);
                _userManagementService.CheckUserExists(userId);

                var contents = _contentManagementService.GetStarredContents(userId);

                return(Ok(new GetContentsResponse()
                {
                    Contents = ApiContentMapper.MapContentsData(contents.ToArray()),
                }));
            }
            catch (UserNotExistError)
            {
                return(StatusCode(StatusCodes.Status404NotFound, new
                {
                    message = "Пользователь не найден"
                }));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new { message = e.Message }));
            }
        }
예제 #2
0
        public ActionResult <GetContentResponse> GetContent(int contentId)
        {
            try
            {
                var userId = Int32.Parse(User.Identity.Name);
                _userManagementService.CheckUserExists(userId);

                var content = _contentManagementService.GetContent(contentId);

                GetContentResponse response = new GetContentResponse()
                {
                    Content = ApiContentMapper.MapContentData(content)
                };

                return(Ok(response));
            }
            catch (UserNotExistError)
            {
                return(StatusCode(StatusCodes.Status404NotFound, new
                {
                    message = "Пользователь не найден"
                }));
            }
            catch (ContentNotExistError)
            {
                return(StatusCode(StatusCodes.Status404NotFound, new
                {
                    message = "Материал не найден"
                }));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new { message = e.Message }));
            }
        }