-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CSS facelift for the Hello app and the schema-specific templates (#617)
Mostly copying over what P&Q did for the Python app but with more direct links to send the user to the right docs in each case. --------- Signed-off-by: Alex Poliakov <alex.poliakov@dbos.dev> Co-authored-by: Peter Kraft <peter.kraft@dbos.dev>
- Loading branch information
Showing
5 changed files
with
158 additions
and
80 deletions.
There are no files selected for viewing
56 changes: 37 additions & 19 deletions
56
packages/create/templates/hello-drizzle/src/operations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,52 @@ | ||
// Welcome to DBOS! | ||
|
||
// This is the Quickstart Drizzle template app. It greets visitors, counting how many total greetings were made. | ||
// To learn how to run this app, visit the Drizzle tutorial: https://docs.dbos.dev/tutorials/using-drizzle | ||
|
||
import { HandlerContext, TransactionContext, Transaction, GetApi } from '@dbos-inc/dbos-sdk'; | ||
import { dbosHello } from './schema'; | ||
import { NodePgDatabase } from 'drizzle-orm/node-postgres'; | ||
|
||
const app_notes = ` | ||
To learn how to run this app on your computer, visit the | ||
<a href="https://docs.dbos.dev/getting-started/quickstart" >DBOS Quickstart</a>.<br> | ||
After that, to learn how to build apps, visit the | ||
<a href="https://docs.dbos.dev/getting-started/quickstart-programming" >DBOS Programming Guide</a>.`; | ||
|
||
export class Hello { | ||
|
||
@GetApi('/') // Serve a quick readme for the app | ||
static async readme(_ctxt: HandlerContext) { | ||
const readme = `<html><body><p> | ||
Welcome to the DBOS Hello App!<br><br> | ||
Visit the route /greeting/:name to be greeted!<br> | ||
For example, visit <a href="/greeting/dbos">/greeting/dbos</a>.<br> | ||
The counter increments with each page visit.<br><br> | ||
${app_notes} | ||
</p></body></html>`; | ||
return Promise.resolve(readme); | ||
} | ||
|
||
// Serve this function from HTTP GET requests at the /greeting endpoint with 'user' as a path parameter | ||
@GetApi('/greeting/:user') | ||
@Transaction() | ||
static async helloTransaction(ctxt: TransactionContext<NodePgDatabase>, user: string) { | ||
const greeting = `Hello, ${user}!`; | ||
const greetings_output = await ctxt.client.insert(dbosHello).values({greeting}).returning({greet_count: dbosHello.greet_count}); | ||
const greeting_message = `${greeting} We have made ${greetings_output[0].greet_count} greetings.`; | ||
const page = `<html><body><p>${greeting_message}<br><br>${app_notes}</p></body></html>`; | ||
return Hello.makeHTML(greeting_message); | ||
} | ||
|
||
// Serve a quick readme for the app at the / endpoint | ||
@GetApi('/') | ||
static async readme(_ctxt: HandlerContext) { | ||
const message = Hello.makeHTML( | ||
`Visit the route <code class="bg-gray-100 px-1 rounded">/greeting/{name}</code> to be greeted!<br> | ||
For example, visit <code class="bg-gray-100 px-1 rounded"><a href="/greeting/Mike" class="text-blue-600 hover:underline">/greeting/Mike</a></code><br> | ||
The counter increments with each page visit.` | ||
); | ||
return Promise.resolve(message); | ||
} | ||
|
||
// A helper function to create HTML pages with some styling | ||
static makeHTML(message: string) { | ||
const page = ` | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>DBOS Template App</title> | ||
<script src="https://cdn.tailwindcss.com"></script> | ||
</head> | ||
<body class="font-sans text-gray-800 p-6 max-w-2xl mx-auto"> | ||
<h1 class="text-3xl font-semibold mb-4">Welcome to DBOS!</h1> | ||
<p class="mt-8 mb-8">` + message + `</p> | ||
<p class="mb-2"> | ||
This is the Drizzle quickstart template app. Read the documentation for it <a href="https://docs.dbos.dev/tutorials/using-drizzle" class="text-blue-600 hover:underline">here</a>. | ||
</p> | ||
</body> | ||
</html>`; | ||
return page; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters