-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #204 from xnought/tutorials
Tutorials Table and Database Retrieval
- Loading branch information
Showing
11 changed files
with
148 additions
and
26 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,39 @@ | ||
from fastapi import APIRouter | ||
from ..api_types import CamelModel | ||
from ..db import Database | ||
import logging as log | ||
|
||
router = APIRouter() | ||
|
||
|
||
class Tutorial(CamelModel): | ||
class Link(CamelModel): | ||
url: str | ||
title: str | ||
|
||
|
||
@router.get("/tutorials", response_model=list[Tutorial]) | ||
class Tutorial(CamelModel): | ||
header: str | None = None | ||
title: str | None = None | ||
description: str | None = None | ||
# links: list[Link] | None = None | ||
|
||
|
||
class MultipleTutorials(CamelModel): | ||
tutorials: list[Tutorial] | None = None | ||
|
||
|
||
@router.get("/tutorials", response_model=MultipleTutorials | None) | ||
def get_all_tutorials(): | ||
return [ | ||
Tutorial(title="Tutorial 1"), | ||
Tutorial(title="Tutorial 2"), | ||
Tutorial(title="Tutorial 3"), | ||
Tutorial(title="Tutorial 4"), | ||
] | ||
with Database() as db: | ||
try: | ||
query = """SELECT header, title, description FROM tutorials""" | ||
entries = db.execute_return(query) | ||
if entries: | ||
return MultipleTutorials( | ||
tutorials=[ | ||
Tutorial(header=header, title=title, description=description) | ||
for header, title, description in entries | ||
] | ||
) | ||
except Exception as e: | ||
log.error(e) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* generated using openapi-typescript-codegen -- do no edit */ | ||
/* istanbul ignore file */ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
import type { Tutorial } from './Tutorial'; | ||
export type MultipleTutorials = { | ||
tutorials?: (Array<Tutorial> | null); | ||
}; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,68 @@ | ||
<script lang="ts"> | ||
import { onMount } from "svelte"; | ||
import { Backend, type Tutorial } from "../lib/backend"; | ||
import { Backend, type Tutorial, type MultipleTutorials } from "../lib/backend"; | ||
let tutorials: Tutorial[] | null = []; | ||
let error = false; | ||
let tutorials: Tutorial[] = []; | ||
onMount(async () => { | ||
tutorials = await Backend.getAllTutorials(); | ||
console.log("Onmount") | ||
const result = await Backend.getAllTutorials(); | ||
tutorials = result.tutorials | ||
console.log("Tutorials=", tutorials) | ||
if (tutorials == null) error = true; | ||
console.log("Received", tutorials); | ||
}); | ||
</script> | ||
|
||
<div> | ||
{#each tutorials as tutorial} | ||
<div> | ||
<h2>{tutorial.title}</h2> | ||
</div> | ||
{/each} | ||
<div class="page"> | ||
<div class="tutorials-container"> | ||
|
||
{#each tutorials as tutorial} | ||
<div class="tutorial"> | ||
|
||
|
||
<h2 class="title">{tutorial.title}</h2> | ||
<p class="summary">{tutorial.description}</p> | ||
<!-- <ul> --> | ||
<!-- {#each tutorial.links as link} --> | ||
<!-- add the anchor tags back in when problem gets figured out --> | ||
<!-- <li><a href={link.url}>{link.title}</a></li> --> | ||
<!-- <a href={link.url}>{link.title}</a> --> | ||
<!-- <p class="header">{link.url}</p> --> | ||
<!-- {/each} --> | ||
<!-- </ul> --> | ||
|
||
</div> | ||
{/each} | ||
</div> | ||
</div> | ||
|
||
<style> | ||
/* put stuff here */ | ||
.page { | ||
background-color: #f0f0f0; | ||
padding: 40px; | ||
} | ||
.tutorials-container { | ||
background-color: white; | ||
padding: 30px; | ||
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2); | ||
} | ||
.tutorial { | ||
margin-bottom: 5px; | ||
} | ||
.title { | ||
font-size: 24px; | ||
margin-bottom: 5px; | ||
} | ||
.summary { | ||
font-size: 18px; | ||
margin-left: 40px; | ||
margin-right: 40px; | ||
} | ||
</style> |
10 changes: 10 additions & 0 deletions
10
frontend/vite.config.ts.timestamp-1710099491738-507fb678492d4.mjs
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// vite.config.ts | ||
import { defineConfig } from "file:///app/node_modules/vite/dist/node/index.js"; | ||
import { svelte } from "file:///app/node_modules/@sveltejs/vite-plugin-svelte/src/index.js"; | ||
var vite_config_default = defineConfig({ | ||
plugins: [svelte()] | ||
}); | ||
export { | ||
vite_config_default as default | ||
}; | ||
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsidml0ZS5jb25maWcudHMiXSwKICAic291cmNlc0NvbnRlbnQiOiBbImNvbnN0IF9fdml0ZV9pbmplY3RlZF9vcmlnaW5hbF9kaXJuYW1lID0gXCIvYXBwXCI7Y29uc3QgX192aXRlX2luamVjdGVkX29yaWdpbmFsX2ZpbGVuYW1lID0gXCIvYXBwL3ZpdGUuY29uZmlnLnRzXCI7Y29uc3QgX192aXRlX2luamVjdGVkX29yaWdpbmFsX2ltcG9ydF9tZXRhX3VybCA9IFwiZmlsZTovLy9hcHAvdml0ZS5jb25maWcudHNcIjtpbXBvcnQgeyBkZWZpbmVDb25maWcgfSBmcm9tICd2aXRlJ1xyXG5pbXBvcnQgeyBzdmVsdGUgfSBmcm9tICdAc3ZlbHRlanMvdml0ZS1wbHVnaW4tc3ZlbHRlJ1xyXG5cclxuLy8gaHR0cHM6Ly92aXRlanMuZGV2L2NvbmZpZy9cclxuZXhwb3J0IGRlZmF1bHQgZGVmaW5lQ29uZmlnKHtcclxuICBwbHVnaW5zOiBbc3ZlbHRlKCldLFxyXG59KVxyXG4iXSwKICAibWFwcGluZ3MiOiAiO0FBQThMLFNBQVMsb0JBQW9CO0FBQzNOLFNBQVMsY0FBYztBQUd2QixJQUFPLHNCQUFRLGFBQWE7QUFBQSxFQUMxQixTQUFTLENBQUMsT0FBTyxDQUFDO0FBQ3BCLENBQUM7IiwKICAibmFtZXMiOiBbXQp9Cg== |
10 changes: 10 additions & 0 deletions
10
frontend/vite.config.ts.timestamp-1710126135921-7f3f0ed4d967a.mjs
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// vite.config.ts | ||
import { defineConfig } from "file:///app/node_modules/vite/dist/node/index.js"; | ||
import { svelte } from "file:///app/node_modules/@sveltejs/vite-plugin-svelte/src/index.js"; | ||
var vite_config_default = defineConfig({ | ||
plugins: [svelte()] | ||
}); | ||
export { | ||
vite_config_default as default | ||
}; | ||
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsidml0ZS5jb25maWcudHMiXSwKICAic291cmNlc0NvbnRlbnQiOiBbImNvbnN0IF9fdml0ZV9pbmplY3RlZF9vcmlnaW5hbF9kaXJuYW1lID0gXCIvYXBwXCI7Y29uc3QgX192aXRlX2luamVjdGVkX29yaWdpbmFsX2ZpbGVuYW1lID0gXCIvYXBwL3ZpdGUuY29uZmlnLnRzXCI7Y29uc3QgX192aXRlX2luamVjdGVkX29yaWdpbmFsX2ltcG9ydF9tZXRhX3VybCA9IFwiZmlsZTovLy9hcHAvdml0ZS5jb25maWcudHNcIjtpbXBvcnQgeyBkZWZpbmVDb25maWcgfSBmcm9tICd2aXRlJ1xuaW1wb3J0IHsgc3ZlbHRlIH0gZnJvbSAnQHN2ZWx0ZWpzL3ZpdGUtcGx1Z2luLXN2ZWx0ZSdcblxuLy8gaHR0cHM6Ly92aXRlanMuZGV2L2NvbmZpZy9cbmV4cG9ydCBkZWZhdWx0IGRlZmluZUNvbmZpZyh7XG4gIHBsdWdpbnM6IFtzdmVsdGUoKV0sXG59KVxuIl0sCiAgIm1hcHBpbmdzIjogIjtBQUE4TCxTQUFTLG9CQUFvQjtBQUMzTixTQUFTLGNBQWM7QUFHdkIsSUFBTyxzQkFBUSxhQUFhO0FBQUEsRUFDMUIsU0FBUyxDQUFDLE9BQU8sQ0FBQztBQUNwQixDQUFDOyIsCiAgIm5hbWVzIjogW10KfQo= |