示例#1
0
        public async Task <Option> Delete([FromQuery] Guid id)
        {
            using var client = new HttpClient();
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
                JwtBearerDefaults.AuthenticationScheme,
                this.HttpContext.Request.Headers[HeaderNames.Authorization].ToString().Replace("Bearer ", ""));
            var tweetClient = new TweetClient(this.externals.Tweet, client);

            var jwtGuid = this.HttpContext.User.Claims.Single(x => x.Type == "Id").Value.Replace("\"", string.Empty);
            var actor   = Guid.Parse(jwtGuid);

            try
            {
                var res = await tweetClient.TweetcommandDeleteAsync(
                    new DeleteTweetRequest
                {
                    Actor = actor,
                    Tweet = id,
                });

                if (res.HasFailed)
                {
                    return(Option.FromError(res.Error));
                }
                return(Option.Success);
            }
            catch (Exception e)
            {
                return(Option <TimedData <TweetDto> > .FromError(e.Message));
            }
        }
示例#2
0
        public async Task <Option <TimedData <TweetDto> > > GetFromUser(Guid id, Guid?from, bool ascending, int count)
        {
            using var client = new HttpClient();
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
                JwtBearerDefaults.AuthenticationScheme,
                this.HttpContext.Request.Headers[HeaderNames.Authorization].ToString().Replace("Bearer ", ""));
            var tweetClient = new TweetClient(this.externals.Tweet, client);

            try
            {
                return((await tweetClient.TweetqueryGetfromuserAsync(id, from, ascending, count)).DeserializeOption());
            }
            catch (Exception e)
            {
                return(Option <TimedData <TweetDto> > .FromError(e.Message));
            }
        }
示例#3
0
        public async Task <Option <TweetDto> > Post(PostTweetRequest postTweetRequest)
        {
            using var client = new HttpClient();
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
                JwtBearerDefaults.AuthenticationScheme,
                this.HttpContext.Request.Headers[HeaderNames.Authorization].ToString().Replace("Bearer ", ""));
            var tweetClient = new TweetClient(this.externals.Tweet, client);

            try
            {
                return((await tweetClient.TweetcommandPostAsync(postTweetRequest)).DeserializeOption());
            }
            catch (Exception e)
            {
                return(Option <TweetDto> .FromError(e.Message));
            }
        }
示例#4
0
        public async Task <Option <TimedData <TweetDto> > > GetAll(Guid?from, bool ascending, int count)
        {
            using var client = new HttpClient();
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
                JwtBearerDefaults.AuthenticationScheme,
                this.HttpContext.Request.Headers[HeaderNames.Authorization].ToString().Replace("Bearer ", ""));
            var tweetClient = new TweetClient(this.externals.Tweet, client);

            this.logger.LogInformation($"Tweet client: {this.externals.Tweet}");

            try
            {
                return(Option <TimedData <TweetDto> > .FromResult(
                           (await tweetClient.TweetqueryGetallAsync(from, ascending, count)).DeserializeTimedData()));
            }
            catch (Exception e)
            {
                this.logger.LogError(e, "Error during query.");
                return(Option <TimedData <TweetDto> > .FromError(e.Message));
            }
        }