Example #1
0
        public async Task <OneOf <DbVote, NotFound> > GetAsync(string userId, nhitomiObject obj, CancellationToken cancellationToken = default)
        {
            var vote = await _client.GetAsync <DbVote>(DbVote.MakeId(userId, obj.Id), cancellationToken);

            if (vote?.Target != obj.Type)
            {
                return(new NotFound());
            }

            return(vote);
        }
Example #2
0
        public async Task <OneOf <Success, NotFound> > UnsetAsync(string userId, nhitomiObject obj, CancellationToken cancellationToken = default)
        {
            var entry = await _client.GetEntryAsync <DbVote>(DbVote.MakeId(userId, obj.Id), cancellationToken);

            do
            {
                if (entry.Value?.Target != obj.Type)
                {
                    return(new NotFound());
                }
            }while (await entry.TryDeleteAsync(cancellationToken));

            return(new Success());
        }