예제 #1
0
        public async Task <ActionResult <CollectionInfo> > AddOrEditCollection(int postId, [FromQuery] int privacy)
        {
            // 收藏存在则修改,否则添加
            var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;

            if (!int.TryParse(userId, out int uid))
            {
                return(BadRequest(new { error = "Unknow user ID." }));
            }
            var col = await _repo.GetCollection(uid, postId);

            if (col == null)
            {
                try
                {
                    return(CollectionInfo.FromCollection(await _repo.SaveCollection(uid, postId, privacy)));
                }
                catch
                {
                    return(NotFound());
                }
            }
            else
            {
                return(CollectionInfo.FromCollection(await _repo.UpdateCollection(uid, postId, privacy)));
            }
        }
예제 #2
0
        public async Task <ActionResult <CollectionInfo> > DeleteCollection(int postId)
        {
            var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;

            if (!int.TryParse(userId, out int uid))
            {
                return(BadRequest(new { error = "Unknow user ID." }));
            }
            return(CollectionInfo.FromCollection(await _repo.DeleteCollection(uid, postId)));
        }
예제 #3
0
        public async Task <ActionResult <CollectionInfo> > GetCollectionStatus(int postId)
        {
            var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;

            if (!int.TryParse(userId, out int uid))
            {
                return(BadRequest(new { error = "Unknow user ID." }));
            }
            var col = await _repo.GetCollection(uid, postId);

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

            return(CollectionInfo.FromCollection(col));
        }