mirror of
https://github.com/wasp-lang/wasp.git
synced 2024-08-17 03:00:59 +03:00
Moves crud routes under /crud
(#2145)
This commit is contained in:
parent
dccc3074e9
commit
a439d8f454
@ -25,7 +25,7 @@ router.use('/auth', middleware, auth)
|
|||||||
{=/ isAuthEnabled =}
|
{=/ isAuthEnabled =}
|
||||||
router.use('/{= operationsRouteInRootRouter =}', middleware, operations)
|
router.use('/{= operationsRouteInRootRouter =}', middleware, operations)
|
||||||
{=# areThereAnyCrudRoutes =}
|
{=# areThereAnyCrudRoutes =}
|
||||||
router.use('/', middleware, rootCrudRouter)
|
router.use('/{= crudRouteInRootRouter =}', middleware, rootCrudRouter)
|
||||||
{=/ areThereAnyCrudRoutes =}
|
{=/ areThereAnyCrudRoutes =}
|
||||||
{=# areThereAnyCustomApiRoutes =}
|
{=# areThereAnyCustomApiRoutes =}
|
||||||
// NOTE: Keep user-defined api routes last so they cannot override our routes.
|
// NOTE: Keep user-defined api routes last so they cannot override our routes.
|
||||||
|
@ -221,7 +221,7 @@
|
|||||||
"file",
|
"file",
|
||||||
"../out/sdk/wasp/client/crud/tasks.ts"
|
"../out/sdk/wasp/client/crud/tasks.ts"
|
||||||
],
|
],
|
||||||
"4947286d60b6652052edd7bc47230481a27ce5cbaa62ed62bac727576ececa43"
|
"083c93c278fe261989cec8a4ea52e0dc706fae1a79aa91d6f1b8c17eca938c40"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
@ -1061,7 +1061,7 @@
|
|||||||
"file",
|
"file",
|
||||||
"server/src/routes/index.js"
|
"server/src/routes/index.js"
|
||||||
],
|
],
|
||||||
"b589a916a4ded52b75af42e299a506cbeb4d56ce2e87bec29f211c3e33865049"
|
"a13d8d47f58b1a4b60a81e31823dc8fcad0dbbbe3e09de129ae8e140f384a7b7"
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
|
@ -9,15 +9,15 @@ import {
|
|||||||
|
|
||||||
function createCrud() {
|
function createCrud() {
|
||||||
const crudGetQuery = createQuery<GetQueryResolved>(
|
const crudGetQuery = createQuery<GetQueryResolved>(
|
||||||
'tasks/get',
|
'crud/tasks/get',
|
||||||
['Task']
|
['Task']
|
||||||
)
|
)
|
||||||
const crudGetAllQuery = createQuery<GetAllQueryResolved>(
|
const crudGetAllQuery = createQuery<GetAllQueryResolved>(
|
||||||
'tasks/get-all',
|
'crud/tasks/get-all',
|
||||||
['Task']
|
['Task']
|
||||||
)
|
)
|
||||||
const crudCreateAction = createAction<CreateActionResolved>(
|
const crudCreateAction = createAction<CreateActionResolved>(
|
||||||
'tasks/create',
|
'crud/tasks/create',
|
||||||
['Task']
|
['Task']
|
||||||
)
|
)
|
||||||
return {
|
return {
|
||||||
|
@ -2,9 +2,9 @@ import { createAction } from "../operations/actions/core.js";
|
|||||||
import { createQuery } from "../operations/queries/core.js";
|
import { createQuery } from "../operations/queries/core.js";
|
||||||
import { makeUseActionFor, makeUseQueryFor } from "./operationsHelpers.js";
|
import { makeUseActionFor, makeUseQueryFor } from "./operationsHelpers.js";
|
||||||
function createCrud() {
|
function createCrud() {
|
||||||
const crudGetQuery = createQuery('tasks/get', ['Task']);
|
const crudGetQuery = createQuery('crud/tasks/get', ['Task']);
|
||||||
const crudGetAllQuery = createQuery('tasks/get-all', ['Task']);
|
const crudGetAllQuery = createQuery('crud/tasks/get-all', ['Task']);
|
||||||
const crudCreateAction = createAction('tasks/create', ['Task']);
|
const crudCreateAction = createAction('crud/tasks/create', ['Task']);
|
||||||
return {
|
return {
|
||||||
get: {
|
get: {
|
||||||
query: crudGetQuery,
|
query: crudGetQuery,
|
||||||
|
@ -1 +1 @@
|
|||||||
{"version":3,"file":"tasks.js","sourceRoot":"","sources":["../../../client/crud/tasks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,eA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C,YAAY,CAAC;SAC1C;QACD,MAAM,EAAE;YACJ,KAAK,EAAE,eAAe;YACtB,QAAQ,EAAE,eAAe,CAAC,eAAe,CAAC;SAC7C;QACD,MAAM,EAAE;YACJ,MAAM,EAAE,gBAAgB;YACxB,SAAS,EAAE,gBAAgB,CAAC,gBAAgB,CAAC;SAChD;KACJ,CAAA;AACL,CAAC;AAED,aAAa;AACb,MAAM,CAAC,MAAM,KAAK,GAAG,UAAU,EAAE,CAAC"}
|
@ -15,7 +15,7 @@ router.get('/', middleware, function (_req, res, _next) {
|
|||||||
|
|
||||||
router.use('/auth', middleware, auth)
|
router.use('/auth', middleware, auth)
|
||||||
router.use('/operations', middleware, operations)
|
router.use('/operations', middleware, operations)
|
||||||
router.use('/', middleware, rootCrudRouter)
|
router.use('/crud', middleware, rootCrudRouter)
|
||||||
// NOTE: Keep user-defined api routes last so they cannot override our routes.
|
// NOTE: Keep user-defined api routes last so they cannot override our routes.
|
||||||
// Additionally, do not add middleware to these routes here. Instead, we add
|
// Additionally, do not add middleware to these routes here. Instead, we add
|
||||||
// it later to allow for middleware customization.
|
// it later to allow for middleware customization.
|
||||||
|
@ -12,7 +12,10 @@ getRoute operation = case operation of
|
|||||||
AS.Crud.Delete -> "delete"
|
AS.Crud.Delete -> "delete"
|
||||||
|
|
||||||
makeFullPath :: String -> AS.Crud.CrudOperation -> String
|
makeFullPath :: String -> AS.Crud.CrudOperation -> String
|
||||||
makeFullPath crudOperationName crudOperation = intercalate "/" [getCrudOperationRouterRoute crudOperationName, getRoute crudOperation]
|
makeFullPath crudOperationName crudOperation = intercalate "/" [crudRouteInRootRouter, getCrudOperationRouterRoute crudOperationName, getRoute crudOperation]
|
||||||
|
|
||||||
getCrudOperationRouterRoute :: String -> String
|
getCrudOperationRouterRoute :: String -> String
|
||||||
getCrudOperationRouterRoute crudOperationName = crudOperationName
|
getCrudOperationRouterRoute crudOperationName = crudOperationName
|
||||||
|
|
||||||
|
crudRouteInRootRouter :: String
|
||||||
|
crudRouteInRootRouter = "crud"
|
||||||
|
@ -39,6 +39,7 @@ import Wasp.Env (envVarsToDotEnvContent)
|
|||||||
import Wasp.Generator.Common
|
import Wasp.Generator.Common
|
||||||
( ServerRootDir,
|
( ServerRootDir,
|
||||||
)
|
)
|
||||||
|
import qualified Wasp.Generator.Crud.Routes as CrudRoutes
|
||||||
import Wasp.Generator.FileDraft (FileDraft, createTextFileDraft)
|
import Wasp.Generator.FileDraft (FileDraft, createTextFileDraft)
|
||||||
import Wasp.Generator.Monad (Generator)
|
import Wasp.Generator.Monad (Generator)
|
||||||
import qualified Wasp.Generator.NpmDependencies as N
|
import qualified Wasp.Generator.NpmDependencies as N
|
||||||
@ -243,6 +244,7 @@ genRoutesIndex spec =
|
|||||||
tmplData =
|
tmplData =
|
||||||
object
|
object
|
||||||
[ "operationsRouteInRootRouter" .= (operationsRouteInRootRouter :: String),
|
[ "operationsRouteInRootRouter" .= (operationsRouteInRootRouter :: String),
|
||||||
|
"crudRouteInRootRouter" .= (CrudRoutes.crudRouteInRootRouter :: String),
|
||||||
"isAuthEnabled" .= (isAuthEnabled spec :: Bool),
|
"isAuthEnabled" .= (isAuthEnabled spec :: Bool),
|
||||||
"areThereAnyCustomApiRoutes" .= (not . null $ AS.getApis spec),
|
"areThereAnyCustomApiRoutes" .= (not . null $ AS.getApis spec),
|
||||||
"areThereAnyCrudRoutes" .= (not . null $ AS.getCruds spec)
|
"areThereAnyCrudRoutes" .= (not . null $ AS.getCruds spec)
|
||||||
|
@ -39,9 +39,9 @@ spec_GeneratorCrudTest = do
|
|||||||
}
|
}
|
||||||
primaryEntityField
|
primaryEntityField
|
||||||
`shouldBe` mkOperationsJson
|
`shouldBe` mkOperationsJson
|
||||||
[ "Get" .= mkOperationJson "get" "tasks/get" NotPublic,
|
[ "Get" .= mkOperationJson "get" "crud/tasks/get" NotPublic,
|
||||||
"GetAll" .= mkOperationJson "get-all" "tasks/get-all" NotPublic,
|
"GetAll" .= mkOperationJson "get-all" "crud/tasks/get-all" NotPublic,
|
||||||
"Create" .= mkOperationJson "create" "tasks/create" NotPublic
|
"Create" .= mkOperationJson "create" "crud/tasks/create" NotPublic
|
||||||
]
|
]
|
||||||
|
|
||||||
it "returns proper JSON for public operations" $ do
|
it "returns proper JSON for public operations" $ do
|
||||||
@ -60,9 +60,9 @@ spec_GeneratorCrudTest = do
|
|||||||
}
|
}
|
||||||
primaryEntityField
|
primaryEntityField
|
||||||
`shouldBe` mkOperationsJson
|
`shouldBe` mkOperationsJson
|
||||||
[ "Get" .= mkOperationJson "get" "tasks/get" Public,
|
[ "Get" .= mkOperationJson "get" "crud/tasks/get" Public,
|
||||||
"GetAll" .= mkOperationJson "get-all" "tasks/get-all" NotPublic,
|
"GetAll" .= mkOperationJson "get-all" "crud/tasks/get-all" NotPublic,
|
||||||
"Create" .= mkOperationJson "create" "tasks/create" Public
|
"Create" .= mkOperationJson "create" "crud/tasks/create" Public
|
||||||
]
|
]
|
||||||
|
|
||||||
it "allows overrides of operations" $ do
|
it "allows overrides of operations" $ do
|
||||||
@ -91,9 +91,9 @@ spec_GeneratorCrudTest = do
|
|||||||
}
|
}
|
||||||
primaryEntityField
|
primaryEntityField
|
||||||
`shouldBe` mkOperationsJson
|
`shouldBe` mkOperationsJson
|
||||||
[ "Get" .= mkOperationJson "get" "tasks/get" Public,
|
[ "Get" .= mkOperationJson "get" "crud/tasks/get" Public,
|
||||||
"GetAll" .= mkOperationJson "get-all" "tasks/get-all" NotPublic,
|
"GetAll" .= mkOperationJson "get-all" "crud/tasks/get-all" NotPublic,
|
||||||
"Create" .= mkOperationJson "create" "tasks/create" Public
|
"Create" .= mkOperationJson "create" "crud/tasks/create" Public
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
crudOperationsName = "tasks"
|
crudOperationsName = "tasks"
|
||||||
|
Loading…
Reference in New Issue
Block a user