Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed May 1, 2024
1 parent 9c7ccab commit d9c4e87
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 15 deletions.
12 changes: 12 additions & 0 deletions app/Actions/Dashboard/GetDeploymentCount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Action } from '@stacksjs/actions'
import { Deployment } from '@stacksjs/orm'

export default new Action({
name: 'GetDeploymentCount',
description: 'Gets the total number of deployments.',
apiResponse: true,

async handle() {
return Deployment.count()
},
})
12 changes: 12 additions & 0 deletions app/Actions/Dashboard/GetDownloadCount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Action } from '@stacksjs/actions'
import { Library } from '@stacksjs/orm'

export default new Action({
name: 'GetDownloadCount',
description: 'Gets the total number of downloads.',
apiResponse: true,

async handle() {
return Library.downloadCount()
},
})
Empty file.
12 changes: 12 additions & 0 deletions app/Actions/Dashboard/GetRecentCommits.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Action } from '@stacksjs/actions'
import { Commit } from '@stacksjs/orm'

export default new Action({
name: 'GetRecentCommits',
description: 'Gets recent commits.',
apiResponse: true,

async handle() {
return Commit.recent(3)
},
})
12 changes: 12 additions & 0 deletions app/Actions/Dashboard/GetRecentDeployments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Action } from '@stacksjs/actions'
import { Deployment } from '@stacksjs/orm'

export default new Action({
name: 'GetRecentDeployments',
description: 'Gets recent deployments.',
apiResponse: true,

async handle() {
return Deployment.recent(3)
},
})
12 changes: 12 additions & 0 deletions app/Actions/Dashboard/GetSubscriberCount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Action } from '@stacksjs/actions'
import { Subscriber } from '@stacksjs/orm'

export default new Action({
name: 'GetSubscriberCount',
description: 'Gets the total number of subscribers.',
apiResponse: true,

async handle() {
return Subscriber.count()
},
})
12 changes: 12 additions & 0 deletions app/Actions/Dashboard/GetTotalUsers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { User } from '@stacksjs/orm'
import { Action } from '@stacksjs/actions'

export default new Action({
name: 'GetTotalUsers',
description: 'Gets the total number of users.',
apiResponse: true,

async handle() {
return User.count()
},
})
18 changes: 3 additions & 15 deletions routes/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { route } from '@stacksjs/router'

await route.get('/', () => 'hello world') // $APP_URL/api
await route.get('/hello/world', () => 'hello world, buddy') // stacksjs.org/api/hello/world
await route.get('/buddy/versions', 'Actions/Buddy/VersionsAction') // stacksjs.org/api/buddy/versions
await route.get('/buddy/commands', 'Actions/Buddy/CommandsAction') // stacksjs.org/api/buddy/commands
await route.get('/hello-world', () => {
// $APP_URL/api/welcome
return {
Expand All @@ -23,16 +21,6 @@ await route.get('/hello-world', () => {
await route.email('/welcome')
await route.health() // adds an `/api/health` route

// await route.group('/buddy', async () => { // you may group your routes in a few different ways
// await route.get('/commands', 'Actions/Buddy/CommandsAction')

// // nested groups are also supported
// await route.group({ prefix: 'commands' }, async () => {
// await route.get('/example-two', import('Actions/Buddy/CommandsAction')) // or import the action directly
// })

// await route.get('/versions', '../app/Actions/Buddy/VersionsAction') // a relative path is accepted as well
// })

// await route.action('/example') // the equivalent of route.get('/example', 'ExampleAction')
// await route.job('/example-two') // the equivalent of route.get('/example-two', 'ExampleTwoJob')
// await route.group('/some-path', async () => {...})
// await route.action('/example') // equivalent to `route.get('/example', 'ExampleAction')`
// await route.job('/example-two') // equivalent to `route.get('/example-two', 'ExampleTwoJob')`
12 changes: 12 additions & 0 deletions routes/buddy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { route } from '@stacksjs/router'

/**
* This file is the entry point for your application's Buddy routes.
* The routes defined here are automatically registered. Last but
* not least, beware when deleting these pre-configured routes.
*
* @see https://stacksjs.org/docs/routing
*/

await route.get('/versions', 'Actions/Buddy/VersionsAction') // your-domain.com/api/buddy/versions
await route.get('/commands', 'Actions/Buddy/CommandsAction') // your-domain.com/api/buddy/commands
1 change: 1 addition & 0 deletions storage/framework/core/actions/src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface Request {
interface ActionOptions {
name?: string
description?: string
apiResponse?: boolean
fields?: Record<FieldKey, FieldValue>
path?: string
rate?: JobOptions['rate']
Expand Down
31 changes: 31 additions & 0 deletions storage/framework/core/orm/src/generated/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,21 @@ export class UserModel {
return await query.selectAll().execute()
}

async count(options: QueryOptions = {}) {
let query = db.selectFrom('users').select(db.fn.count('*').as('total_count'));

// Apply sorting from options
if (options.sort)
query = query.orderBy(options.sort.column, options.sort.order)

// Apply pagination from options
if (options.limit !== undefined) query = query.limit(options.limit)

if (options.offset !== undefined) query = query.offset(options.offset)

return await query.execute()
}

async first() {
return await db.selectFrom('users').selectAll().executeTakeFirst()
}
Expand Down Expand Up @@ -553,6 +568,21 @@ async function whereIn(
return await query.selectAll().execute()
}

async function count(options: QueryOptions = {}) {
let query = db.selectFrom('users').select(db.fn.count('*').as('total_count'));

// Apply sorting from options
if (options.sort)
query = query.orderBy(options.sort.column, options.sort.order)

// Apply pagination from options
if (options.limit !== undefined) query = query.limit(options.limit)

if (options.offset !== undefined) query = query.offset(options.offset)

return await query.execute()
}

export const User = {
find,
findMany,
Expand All @@ -567,6 +597,7 @@ export const User = {
last,
where,
whereIn,
count,
}

export default User

0 comments on commit d9c4e87

Please sign in to comment.