Skip to content

Commit

Permalink
feat: add tutorials from call
Browse files Browse the repository at this point in the history
  • Loading branch information
xnought committed Feb 9, 2024
1 parent d8d2125 commit 39c342a
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 2 deletions.
21 changes: 21 additions & 0 deletions backend/src/api/tutorials.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from fastapi import APIRouter
from fastapi.exceptions import HTTPException
import logging as log
from ..db import Database
from ..api_types import CamelModel

router = APIRouter()


class Tutorial(CamelModel):
title: str


@router.get("/tutorials", response_model=list[Tutorial])
def get_all_tutorials():
return [
Tutorial(title="Tutorial 1"),
Tutorial(title="Tutorial 2"),
Tutorial(title="Tutorial 3"),
Tutorial(title="Tutorial 4"),
]
4 changes: 2 additions & 2 deletions backend/src/server.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os
from .setup import disable_cors, init_fastapi_app, serve_endpoints
from .api import users, search, protein
from .api import users, search, protein, tutorials


app = init_fastapi_app()
disable_cors(app, origins=[os.environ["PUBLIC_FRONTEND_URL"]])
serve_endpoints(app, modules=[users, search, protein])
serve_endpoints(app, modules=[users, search, protein, tutorials])


def export_app_for_docker():
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/Router.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Protein from "./routes/Protein.svelte";
import Error from "./routes/Error.svelte";
import Edit from "./routes/Edit.svelte";
import Tutorials from "./routes/Tutorials.svelte";
</script>

<Router>
Expand All @@ -19,6 +20,7 @@
<Route path="/search"><Search /></Route>
<Route path="/upload"><Upload /></Route>
<Route path="/login"><Login /></Route>
<Route path="/tutorials"><Tutorials /></Route>
<Route path="/protein/:id" let:params
><Protein urlId={params.id} /></Route
>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/openapi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type { ProteinEntry } from './models/ProteinEntry';
export type { RangeFilter } from './models/RangeFilter';
export type { SearchProteinsBody } from './models/SearchProteinsBody';
export type { SearchProteinsResults } from './models/SearchProteinsResults';
export type { Tutorial } from './models/Tutorial';
export type { UploadBody } from './models/UploadBody';
export { UploadError } from './models/UploadError';
export type { ValidationError } from './models/ValidationError';
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/lib/openapi/models/Tutorial.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
export type Tutorial = {
title: string;
};

12 changes: 12 additions & 0 deletions frontend/src/lib/openapi/services/DefaultService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { LoginResponse } from '../models/LoginResponse';
import type { ProteinEntry } from '../models/ProteinEntry';
import type { SearchProteinsBody } from '../models/SearchProteinsBody';
import type { SearchProteinsResults } from '../models/SearchProteinsResults';
import type { Tutorial } from '../models/Tutorial';
import type { UploadBody } from '../models/UploadBody';
import type { UploadError } from '../models/UploadError';
import type { CancelablePromise } from '../core/CancelablePromise';
Expand Down Expand Up @@ -205,4 +206,15 @@ export class DefaultService {
},
});
}
/**
* Get All Tutorials
* @returns Tutorial Successful Response
* @throws ApiError
*/
public static getAllTutorials(): CancelablePromise<Array<Tutorial>> {
return __request(OpenAPI, {
method: 'GET',
url: '/tutorials',
});
}
}
21 changes: 21 additions & 0 deletions frontend/src/routes/Tutorials.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<script lang="ts">
import { onMount } from "svelte";
import { Backend, type Tutorial } from "../lib/backend";
let tutorials: Tutorial[] = [];
onMount(async () => {
tutorials = await Backend.getAllTutorials();
});
</script>

<div>
{#each tutorials as tutorial}
<div>
<h2>{tutorial.title}</h2>
</div>
{/each}
</div>

<style>
/* put stuff here */
</style>

0 comments on commit 39c342a

Please sign in to comment.