Beispiel #1
0
        public IActionResult Delete([FromBody] TwitterProfileApi profile)
        {
            if (profile == null)
            {
                return(BadRequest("No profile was given"));
            }

            if (!_repository.Exists(profile))
            {
                return(BadRequest($"Profile does not exist: {profile.Name}"));
            }

            TwitterProfile prolife = null;

            try
            {
                prolife = _repository.Remove(profile);
            }
            catch (Exception e)
            {
                return(StatusCode(500));
            }

            if (prolife == null)
            {
                return(BadRequest());
            }

            return(Ok("Remove complete"));
        }
Beispiel #2
0
        public IActionResult GetProfile(Guid?id)
        {
            if (id == null)
            {
                return(BadRequest());
            }

            var profile = _repository.Get(new TwitterProfile()
            {
                Id = id
            });

            if (profile == null)
            {
                return(NotFound());
            }
            else
            {
                var data = new TwitterProfileApi();
                data.Name  = profile.Name;
                data.Words = profile.Vocabulary.ToList();

                return(Ok(data));
            }
        }
Beispiel #3
0
        public async Task <IActionResult> GetTrainData([FromBody] TwitterProfileApi apiprofile)
        {
            if (apiprofile == null)
            {
                return(BadRequest());
            }

            if (apiprofile.Name == null)
            {
                return(BadRequest());
            }

            var profile = _repository.Get(apiprofile);

            if (profile == null)
            {
                return(NotFound());
            }
            try
            {
                var tweets = await _twitterService.GetAllTweetsFromProfile(profile);

                if (tweets == null)
                {
                    return(BadRequest());
                }
                return(Ok(tweets));
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }
Beispiel #4
0
        public async Task <IActionResult> Post([FromBody] TwitterProfileApi profile)
        {
            _logger.Log("Adding profile to list");
            if (profile == null)
            {
                _logger.Error("No profile recieved");
                _logger.Separator();
                return(BadRequest("Sum ting wong"));
            }

            if (profile.Name == null)
            {
                _logger.Error("No profilename");
                _logger.Separator();
                return(BadRequest("Name not given"));
            }

            if (await _twitterService.DoesTwitterUserExist(profile) == false)
            {
                _logger.Error("Profile doesn't match a twitter profile");
                _logger.Separator();
                return(NotFound("Twitter user does not exist"));
            }

            if (_twitterService.ProfileTimeLineHasTweets(profile) == false)
            {
                _logger.Error("Profile doesn't have any tweets");
                _logger.Separator();
                return(BadRequest("Twitter user does not have any tweets."));
            }

            TwitterProfile prolife = null;

            try
            {
                profile.Name = await _twitterService.GetTwitterUserName(profile);

                prolife = _repository.Add(profile);
                _logger.Log($"Profile {profile.Name} added to database");
            }
            catch (Exception e)
            {
                if (prolife != null)
                {
                    _repository.Remove(prolife);
                }
                _logger.Error("Something went wrong adding to db");
                _logger.Error(e.Message);
                _logger.Separator();
                return(BadRequest());
            }

            _logger.Separator();
            return(Ok(prolife));
        }
Beispiel #5
0
        public async Task <IActionResult> CheckTwitterHandle([FromBody] TwitterProfileApi handle)
        {
            if (handle == null)
            {
                return(BadRequest("No handle given"));
            }

            if (string.IsNullOrWhiteSpace(handle.Name))
            {
                return(BadRequest("Handle is empty"));
            }

            var result = (await _twitterService.DoesTwitterUserExist(handle));

            if (result)
            {
                return(Ok("Twitterhandle found"));
            }
            else
            {
                return(NotFound($"Twitterhandle not found"));
            }
        }