First commit

This commit is contained in:
AndrewTrieu
2023-03-09 11:21:18 +02:00
commit be427eda10
27 changed files with 262 additions and 0 deletions

0
.Rhistory Normal file
View File

7
README.md Normal file
View File

@@ -0,0 +1,7 @@
# Project 2: XXX
Write the documentation of your project here. Do not include your personal
details (e.g. name or student number).
Remember to include the address of the online location where your project is
running as it is a key part of the submission.

43
docker-compose.yml Normal file
View File

@@ -0,0 +1,43 @@
version: "3.4"
services:
drill-and-practice:
build: drill-and-practice
image: drill-and-practice
restart: "no"
volumes:
- ./drill-and-practice/:/app
ports:
- 7777:7777
depends_on:
- database
- flyway
env_file:
- project.env
database:
container_name: database-p2-e8774b8e-c7a9-4cce-a779-3b59be02206d
image: postgres:14.1
restart: "no"
env_file:
- project.env
flyway:
image: flyway/flyway:9.11.0-alpine
depends_on:
- database
volumes:
- .:/flyway/sql
command: -connectRetries=60 -baselineOnMigrate=true migrate
env_file:
- project.env
e2e-playwright:
entrypoint: "/bin/true" # Prevent startup on docker-compose up
build: e2e-playwright
image: e2e-playwright
network_mode: host
depends_on:
- drill-and-practice
volumes:
- ./e2e-playwright/tests:/e2e-playwright/tests

View File

@@ -0,0 +1,13 @@
FROM denoland/deno:alpine-1.29.2
EXPOSE 7777
WORKDIR /app
COPY deps.js .
RUN deno cache deps.js
COPY . .
CMD [ "run", "--unstable", "--watch", "--allow-net", "--allow-read", "--allow-env", "--no-check", "app-launch.js" ]

View File

@@ -0,0 +1,3 @@
import { app } from "./app.js";
app.listen({ port: 7777 });

14
drill-and-practice/app.js Normal file
View File

@@ -0,0 +1,14 @@
import { Application } from "./deps.js";
import { errorMiddleware } from "./middlewares/errorMiddleware.js";
import { renderMiddleware } from "./middlewares/renderMiddleware.js";
import { serveStaticMiddleware } from "./middlewares/serveStaticMiddleware.js";
import { router } from "./routes/routes.js";
const app = new Application();
app.use(errorMiddleware);
app.use(serveStaticMiddleware);
app.use(renderMiddleware);
app.use(router.routes());
export { app };

View File

@@ -0,0 +1 @@
You could add project configuration files here.

View File

@@ -0,0 +1,10 @@
import { postgres } from "../deps.js";
let sql;
if (Deno.env.get("DATABASE_URL")) {
sql = postgres(Deno.env.get("DATABASE_URL"));
} else {
sql = postgres({});
}
export { sql };

View File

@@ -0,0 +1,11 @@
export { configure, renderFile } from "https://deno.land/x/eta@v2.0.0/mod.ts";
export {
Application,
Router,
send,
} from "https://deno.land/x/oak@v11.1.0/mod.ts";
import postgres from "https://deno.land/x/postgresjs@v3.3.3/mod.js";
export { postgres };
export { Session } from "https://deno.land/x/oak_sessions@v4.0.5/mod.ts";
export * as bcrypt from "https://deno.land/x/bcrypt@v0.4.1/mod.ts";
export * as validasaur from "https://deno.land/x/validasaur@v0.15.0/mod.ts";

View File

@@ -0,0 +1,9 @@
const errorMiddleware = async (context, next) => {
try {
await next();
} catch (e) {
console.log(e);
}
};
export { errorMiddleware };

View File

@@ -0,0 +1,16 @@
import { configure, renderFile } from "../deps.js";
const renderMiddleware = async (context, next) => {
configure({
views: `${Deno.cwd()}/views/`,
});
context.render = async (file, data) => {
context.response.headers.set("Content-Type", "text/html; charset=utf-8");
context.response.body = await renderFile(file, data);
};
await next();
};
export { renderMiddleware };

View File

@@ -0,0 +1,15 @@
import { send } from "../deps.js";
const serveStaticMiddleware = async (context, next) => {
if (context.request.url.pathname.startsWith("/static")) {
const path = context.request.url.pathname.substring(7);
await send(context, path, {
root: `${Deno.cwd()}/static`,
});
} else {
await next();
}
};
export { serveStaticMiddleware };

View File

@@ -0,0 +1 @@
You could add api-related endpoints here.

View File

@@ -0,0 +1,5 @@
const showMain = ({ render }) => {
render("main.eta");
};
export { showMain };

View File

@@ -0,0 +1,8 @@
import { Router } from "../deps.js";
import * as mainController from "./controllers/mainController.js";
const router = new Router();
router.get("/", mainController.showMain);
export { router };

View File

@@ -0,0 +1 @@
You could add services here

View File

@@ -0,0 +1 @@
You could add static content here. Note that you cannot currently submit binary data.

View File

@@ -0,0 +1 @@
Implement tests here.

View File

@@ -0,0 +1 @@
<%~ it.body %>

View File

@@ -0,0 +1,3 @@
<% layout("./layouts/layout.eta") %>
<h1>Hello world!</h1>

View File

@@ -0,0 +1 @@
Add any necessary partials here.

View File

@@ -0,0 +1,9 @@
FROM mcr.microsoft.com/playwright:v1.29.2-focal
COPY . /e2e-playwright
WORKDIR /e2e-playwright
RUN npm install
CMD [ "npx", "playwright", "test", "--reporter=list" ]

View File

@@ -0,0 +1,8 @@
{
"name": "e2e-playwright-in-docker",
"version": "1.0.0",
"dependencies": {
"playwright": "^1.29.2",
"@playwright/test": "^1.29.2"
}
}

View File

@@ -0,0 +1,19 @@
module.exports = {
timeout: 10000,
retries: 0,
reporter: "list",
workers: 5,
use: {
baseURL: "http://localhost:7777",
headless: true,
ignoreHTTPSErrors: true,
},
projects: [
{
name: "e2e-headless-chromium",
use: {
browserName: "chromium",
},
},
],
};

View File

@@ -0,0 +1,5 @@
const { test, expect } = require("@playwright/test");
test("Empty test", async ({ page }) => {
});

View File

@@ -0,0 +1,41 @@
CREATE TABLE users (
id SERIAL PRIMARY KEY,
email VARCHAR(255) UNIQUE,
password CHAR(60),
admin BOOLEAN DEFAULT FALSE
);
CREATE TABLE topics (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id),
name VARCHAR(255) UNIQUE
);
CREATE TABLE questions (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id),
topic_id INTEGER REFERENCES topics(id),
question_text TEXT NOT NULL
);
CREATE TABLE question_answer_options (
id SERIAL PRIMARY KEY,
question_id INTEGER REFERENCES questions(id),
option_text TEXT NOT NULL,
is_correct BOOLEAN DEFAULT FALSE
);
CREATE TABLE question_answers (
id SERIAL PRIMARY KEY,
user_id INTEGER REFERENCES users(id),
question_id INTEGER REFERENCES questions(id),
question_answer_option_id INTEGER REFERENCES question_answer_options(id)
);
CREATE UNIQUE INDEX ON users((lower(email)));
INSERT INTO users (email, password, admin)
VALUES ('admin@admin.com','$2a$10$IML8QCf6xA.alRbW.CG5PuvYc3Qs94vJvoTwbsSehs8s515cUMuZa', true);
INSERT INTO topics (user_id, name)
VALUES ((SELECT id FROM users WHERE email = 'admin@admin.com'), 'Finnish language');

16
project.env Normal file
View File

@@ -0,0 +1,16 @@
# Database configuration for PostgreSQL (running in container called "database-p2-e8774b8e-c7a9-4cce-a779-3b59be02206d")
POSTGRES_USER=username
POSTGRES_PASSWORD=password
POSTGRES_DB=database
# Database configuration for Flyway (used for database migrations)
FLYWAY_USER=username
FLYWAY_PASSWORD=password
FLYWAY_URL=jdbc:postgresql://database-p2-e8774b8e-c7a9-4cce-a779-3b59be02206d:5432/database
# Database configuration for Deno's PostgreSQL driver
PGUSER=username
PGPASSWORD=password
PGHOST=database-p2-e8774b8e-c7a9-4cce-a779-3b59be02206d
PGPORT=5432
PGDATABASE=database