Ejemplo n.º 1
0
        public static IServiceCollection AddMangasMvc(
            this IServiceCollection services,
            MangasRoleConfiguration roles)
        {
            services.AddMvcCore()
            .AddJsonFormatters()
            .AddAuthorization(options =>
                              options.AddPolicy("admin", builder => builder.RequireRole(roles.Admin)))
            .AddApiExplorer()
            .AddPhemaRouting(routing => routing.AddMangasController(roles)
                             .AddChaptersController(roles)
                             .AddPagesController(roles)
                             .AddTypesController(roles)
                             .AddTagsController(roles)
                             .AddTranslatorsController(roles)
                             .AddAuthorsController(roles)
                             .AddBookmarksController(roles)
                             .AddVersionController())
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            return(services);
        }
Ejemplo n.º 2
0
        public static IRoutingBuilder AddTypesController(this IRoutingBuilder builder, MangasRoleConfiguration roles)
        {
            builder.AddController <TypesController>(controller =>
            {
                controller.AddRoute("types", c => c.Read(From.Body <FilterRequest>()))
                .HttpGet();

                controller.AddRoute("admin/types", c => c.AdminCreate(From.Body <AdminCreateTypeRequest>()))
                .HttpPost()
                .Authorize(roles.Admin);

                controller.AddRoute("admin/types/{typeId}",
                                    c => c.AdminUpdate(From.Route <int>(), From.Body <AdminUpdateTypeRequest>()))
                .HttpPut()
                .Authorize(roles.Admin);

                controller.AddRoute("admin/types/{typeId}", c => c.AdminDelete(From.Route <AdminDeleteTypeRequest>()))
                .HttpDelete()
                .Authorize(roles.Admin);
            });

            return(builder);
        }
Ejemplo n.º 3
0
        public static IRoutingBuilder AddBookmarksController(this IRoutingBuilder builder, MangasRoleConfiguration roles)
        {
            builder.AddController <BookmarksController>(controller =>
            {
                controller.AddRoute("bookmarks", c => c.Read(From.Query <FilterByMangaChapterAndPageIdRequest>()))
                .HttpGet()
                .Authorize();

                controller.AddRoute("bookmarks", c => c.Create(From.Body <CreateBookmarkRequest>()))
                .HttpPost()
                .Authorize();

                controller.AddRoute("bookmarks/{bookmarkId}", c => c.Delete(From.Route <DeleteBookmarkRequest>()))
                .HttpDelete()
                .Authorize();

                controller.AddRoute("admin/bookmarks/{accountId}",
                                    c => c.AdminReadById(From.Route <int>(), From.Query <FilterByMangaChapterAndPageIdRequest>()))
                .HttpGet()
                .Authorize(roles.Admin);

                controller.AddRoute("admin/bookmarks/{bookmarkId}",
                                    c => c.AdminDeleteById(From.Route <AdminDeleteByIdBookmarkRequest>()))
                .HttpDelete()
                .Authorize(roles.Admin);
            });

            return(builder);
        }
        public static IRoutingBuilder AddPagesController(this IRoutingBuilder builder, MangasRoleConfiguration roles)
        {
            builder.AddController <PagesController>(controller =>
            {
                controller.AddRoute("pages/{chapterId}", c => c.Read(From.Route <int>(), From.Query <FilterRequest>()))
                .HttpGet();

                // TODO:
                // controller.AddRoute("pages/{pageId}", c => c.ReadById(From.Route<int>()))
                //  .HttpGet();

                controller.AddRoute("admin/{chapterId}/pages",
                                    c => c.AdminCreate(From.Route <int>(), From.Body <AdminCreatePageRequest>()))
                .HttpPost()
                .Authorize(roles.Admin);

                controller.AddRoute("admin/pages/{pageId}",
                                    c => c.AdminUpdate(From.Route <int>(), From.Body <AdminUpdatePageRequest>()))
                .HttpPut()
                .Authorize(roles.Admin);

                controller.AddRoute("admin/pages/{pageId}", c => c.AdminDelete(From.Route <AdminDeletePageRequest>()))
                .HttpDelete()
                .Authorize(roles.Admin);
            });

            return(builder);
        }
        public static IRoutingBuilder AddMangasController(this IRoutingBuilder builder, MangasRoleConfiguration roles)
        {
            builder.AddController <MangasController>(controller =>
            {
                controller.AddRoute("mangas", c => c.Read(From.Query <FilterByMangaRequest>()))
                .HttpGet();

                controller.AddRoute("mangas/{mangaId}", c => c.ReadById(From.Route <int>()))
                .HttpGet();

                controller.AddRoute("admin/mangas", c => c.AdminCreate(From.Body <AdminCreateMangaRequest>()))
                .HttpPost()
                .Authorize(roles.Admin);

                controller.AddRoute("admin/mangas/{mangaId}",
                                    c => c.AdminUpdate(From.Route <int>(), From.Body <AdminUpdateMangaRequest>()))
                .HttpPut()
                .Authorize(roles.Admin);

                controller.AddRoute("admin/mangas/{mangaId}", c => c.AdminDelete(From.Route <AdminDeleteMangaRequest>()))
                .HttpDelete()
                .Authorize(roles.Admin);
            });

            return(builder);
        }