Exemple #1
0
        public async Task <IActionResult> Get(int userId)
        {
            User user = await _userDataSource.Read(userId);

            if (user == null)
            {
                return(NotFound());
            }

            return(Ok(user));
        }
        public async Task <IActionResult> GetFollowings(int userId)
        {
            if (await _userDataSource.Read(userId) == null)
            {
                return(NotFound());
            }

            IEnumerable <User> users = await _followDataSource.ReadFollowings(userId);

            return(Ok(users));
        }
        public async Task <IActionResult> GetFeed(int userId, int?skip = 0, int?count = 20)
        {
            if (await _userDataSource.Read(userId) == null)
            {
                return(NotFound());
            }

            IEnumerable <Post> posts = await _postDataSource.ReadFeedAsync(
                userId, skip.Value, count.Value);

            return(Ok(posts));
        }
        public async Task <IActionResult> CreatePost([FromBody] PostCreateRequest request)
        {
            int currentUserId = this.GetCurrentUserId();

            if (await _userDataSource.Read(currentUserId) == null)
            {
                return(NotFound());
            }

            Post post = await _postDataSource.Create(currentUserId, request.Text);

            return(Ok(post));
        }
Exemple #5
0
        public async Task <IActionResult> Add(int userId)
        {
            int currentUserId = this.GetCurrentUserId();

            if (await _userDataSource.Read(currentUserId) == null ||
                await _userDataSource.Read(userId) == null)
            {
                return(NotFound());
            }

            if (await _followDataSource.Exists(currentUserId, userId))
            {
                return(StatusCode((int)HttpStatusCode.Conflict));
            }

            await _followDataSource.Create(currentUserId, userId);

            return(Ok());
        }
Exemple #6
0
        public async Task <IActionResult> Get()
        {
            int currentUserId = this.GetCurrentUserId();

            User user = await _userDataSource.Read(currentUserId);

            if (user == null)
            {
                return(NotFound());
            }

            return(Ok(user));
        }