예제 #1
0
        public FavoritesModule(IFavoritesRepository favorites, IRepository documents)
            : base("/favorites")
        {
            this.RequiresAuthentication();

            Get["/"] = _ => favorites.GetFavorites(Context.GetUserInfo()).Select(MapToDto).ToArray();

            Delete["/{documentId}"] = args =>
            {
                var document = documents.GetDocument(args.documentId, true);

                favorites.RemoveFavorite(document, Context.GetUserInfo());
                
                return new RequestReplyDto { Success = true };
            };

            Put["/{documentId}"] = args =>
            {
                var document = documents.GetDocument(args.documentId, true);
                favorites.AddFavorite(document, Context.GetUserInfo());

                return new RequestReplyDto { Success = true };
            };
        }