예제 #1
0
        /// <summary>
        /// Returns a list with all the users who reacted to a given post, in alphabetical order
        /// </summary>
        /// <param name="actualRequest">the client request to be handled</param>
        /// <returns>the response to the given request</returns>
        private ActualRequest GetAllLikesForPostAsync(ActualRequest actualRequest)
        {
            Request request = actualRequest.Request;
            int     postId  = Convert.ToInt32(request.Argument.ToString());
            List <UserShortVersion> users = postRepo.GetAllLikesForPost(postId);
            Request response = new Request
            {
                ActionType = ActionType.POST_GET_LIKES.ToString(),
                Argument   = JsonSerializer.Serialize(users)
            };
            List <byte[]> userAvatars = new List <byte[]>();

            if (users != null && users.Count > 0)
            {
                foreach (var user in users)
                {
                    try {
                        var readAvatarFile = File.ReadAllBytes($"{FILE_PATH}/Users/{user.UserId}/avatar.jpg");
                        userAvatars.Add(ImagesUtil.ResizeImage(readAvatarFile, 20, 20));
                    }
                    catch (Exception e) {
                        Console.WriteLine("No avatar found for user " + user.UserId);
                    }
                }
            }
            return(new ActualRequest
            {
                Request = response,
                Images = userAvatars
            });
        }