Skip to content

Commit

Permalink
Merge pull request #204 from xnought/tutorials
Browse files Browse the repository at this point in the history
Tutorials Table and Database Retrieval
  • Loading branch information
CoraBailey authored Mar 12, 2024
2 parents fa6412c + c7973b7 commit 9b3ea60
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 26 deletions.
29 changes: 24 additions & 5 deletions backend/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ CREATE TABLE species (
CREATE TABLE proteins (
id serial PRIMARY KEY,
name text NOT NULL UNIQUE, -- user specified name of the protein (TODO: consider having a string limit)
description text,
description text,
length integer, -- length of amino acid sequence
mass numeric, -- mass in amu/daltons
content text, -- stored markdown for the protein article (TODO: consider having a limit to how big this can be)
Expand All @@ -48,17 +48,36 @@ CREATE TABLE users (
admin boolean NOT NULL
);


/*
* Tutorials Table
*/
CREATE TABLE tutorials (
id serial PRIMARY KEY,
header text NOT NULL,
title text,
description text
);


/*
* Inserts example species into species table
*/
INSERT INTO species(name) VALUES ('ganaspis hookeri');
INSERT INTO species(name) VALUES ('leptopilina boulardi');
INSERT INTO species(name) VALUES ('leptopilina heterotoma');
INSERT INTO species(name) VALUES ('ganaspis hookeri');
INSERT INTO species(name) VALUES ('leptopilina boulardi');
INSERT INTO species(name) VALUES ('leptopilina heterotoma');
INSERT INTO species(name) VALUES ('unknown');

/*
* Inserts test user into user table
* Email: test
* Password: test
*/
INSERT INTO users(username, email, pword, admin) VALUES ('test', 'test', '$2b$12$PFoNf7YM0KNIPP8WGsJjveIOhiJjitsMtfwRcCjdcyTuqjdk/q//u', '1');
INSERT INTO users(username, email, pword, admin) VALUES ('test', 'test', '$2b$12$PFoNf7YM0KNIPP8WGsJjveIOhiJjitsMtfwRcCjdcyTuqjdk/q//u', '1');


INSERT INTO tutorials(header, title, description) VALUES('Tutorial Page', 'General Information', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce gravida tristique est, a sollicitudin nulla varius ac. Duis sed lacus arcu. Mauris eget condimentum justo. Vestibulum iaculis cursus accumsan. Mauris eget diam consequat, viverra dui malesuada, maximus nisl. Etiam laoreet venenatis odio ut tempus. Praesent risus est, eleifend id purus non, varius rutrum nisi. Fusce sagittis lorem nec tristique efficitur. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam pretium, sapien et volutpat tempus, elit urna congue massa, id consequat leo dolor in ligula. Sed vestibulum tristique eros eu aliquet.');
INSERT INTO tutorials(header, title, description) VALUES('Tutorial 1', 'Biology', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.');
INSERT INTO tutorials(header, title, description) VALUES('Tutorial 2', 'How to Use the Site', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.');
INSERT INTO tutorials(header, title, description) VALUES('Tutorial 3', 'Other Reading', 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.');

1 change: 1 addition & 0 deletions backend/src/api/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def search_proteins(body: SearchProteinsBody):
[text_query, text_query, text_query],
)
if entries_result is not None:
print(entries_result)
return SearchProteinsResults(
protein_entries=[
ProteinEntry(
Expand Down
37 changes: 29 additions & 8 deletions backend/src/api/tutorials.py
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)
1 change: 1 addition & 0 deletions backend/src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ def init_fastapi_app() -> FastAPI:
app = FastAPI(
title="Venome Backend", generate_unique_id_function=custom_generate_unique_id
)
app = disable_cors(app)
return app
1 change: 1 addition & 0 deletions frontend/src/lib/openapi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type { EditBody } from './models/EditBody';
export type { HTTPValidationError } from './models/HTTPValidationError';
export type { LoginBody } from './models/LoginBody';
export type { LoginResponse } from './models/LoginResponse';
export type { MultipleTutorials } from './models/MultipleTutorials';
export type { ProteinEntry } from './models/ProteinEntry';
export type { RangeFilter } from './models/RangeFilter';
export type { SearchProteinsBody } from './models/SearchProteinsBody';
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/lib/openapi/models/MultipleTutorials.ts
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);
};

4 changes: 3 additions & 1 deletion frontend/src/lib/openapi/models/Tutorial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/* tslint:disable */
/* eslint-disable */
export type Tutorial = {
title: string;
header?: (string | null);
title?: (string | null);
description?: (string | null);
};

5 changes: 3 additions & 2 deletions frontend/src/lib/openapi/services/DefaultService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import type { EditBody } from '../models/EditBody';
import type { LoginBody } from '../models/LoginBody';
import type { LoginResponse } from '../models/LoginResponse';
import type { MultipleTutorials } from '../models/MultipleTutorials';
import type { ProteinEntry } from '../models/ProteinEntry';
import type { RangeFilter } from '../models/RangeFilter';
import type { SearchProteinsBody } from '../models/SearchProteinsBody';
Expand Down Expand Up @@ -273,10 +274,10 @@ export class DefaultService {
}
/**
* Get All Tutorials
* @returns Tutorial Successful Response
* @returns any Successful Response
* @throws ApiError
*/
public static getAllTutorials(): CancelablePromise<Array<Tutorial>> {
public static getAllTutorials(): CancelablePromise<(MultipleTutorials | null)> {
return __request(OpenAPI, {
method: 'GET',
url: '/tutorials',
Expand Down
67 changes: 57 additions & 10 deletions frontend/src/routes/Tutorials.svelte
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 frontend/vite.config.ts.timestamp-1710099491738-507fb678492d4.mjs
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 frontend/vite.config.ts.timestamp-1710126135921-7f3f0ed4d967a.mjs
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=

0 comments on commit 9b3ea60

Please sign in to comment.