Skip to content
Permalink
Browse files

Initial commit

  • Loading branch information
aborrego3 committed Mar 12, 2021
0 parents commit 5cc76c8ee9aaa5332a207d149db8e1dca7c1511e
@@ -0,0 +1,160 @@
# Created by https://www.toptal.com/developers/gitignore/api/python,visualstudiocode,flask
# Edit at https://www.toptal.com/developers/gitignore?templates=python,visualstudiocode,flask

### Flask ###
instance/*
!instance/.gitignore
.webassets-cache

### Flask.Python Stack ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
pytestdebug.log

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/
doc/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
pythonenv*

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# profiling data
.prof

### VisualStudioCode ###
.vscode/
.vscode/*
!.vscode/tasks.json
!.vscode/launch.json
*.code-workspace

### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide

# End of https://www.toptal.com/developers/gitignore/api/python,visualstudiocode,flask
@@ -0,0 +1,2 @@
# Sample project
This project contains an example project that is downloaded by default using the `silence new` command.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
@@ -0,0 +1,11 @@
'use strict';

import { sessionManager } from '../utils/session.js';

const BASE_URL = "/api/v1";

const requestOptions = {
headers: { Token: sessionManager.getToken() },
};

export { BASE_URL, requestOptions };

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

@@ -0,0 +1,46 @@
"use strict";

import { parseHTML } from "/js/utils/parseHTML.js";

// Aux function to get the div in which to display messages
// It's centralized here so we can change it easily in the case its ID changes
const msgsDivID = "errors";

function getErrorsDiv() {
return document.getElementById(msgsDivID);
}

const messageRenderer = {

showMessageAsAlert: function (message, bootClass) {
let html = `<div class="alert alert-${bootClass} alert-dismissible col-md-12">
<button type="button" class="close" data-dismiss="alert">&times;</button>
${message}
</div>`;
let errorsDiv = getErrorsDiv();

if (errorsDiv === null) {
console.error('You tried to render the following message, however, a ' +
`<div id="${msgsDivID}"> could not be found in your view to show it there:`);
console.error(message);
return;
}

let messageElem = parseHTML(html);
errorsDiv.appendChild(messageElem);
},

showErrorMessage: function (message) {
this.showMessageAsAlert(message, "danger");
},

showWarningMessage: function (message) {
this.showMessageAsAlert(message, "warning");
},

showSuccessMessage: function (message) {
this.showMessageAsAlert(message, "success");
},
}

export { messageRenderer };
@@ -0,0 +1,17 @@
'use strict';

let include = (htmlFile, selector) => {
let xhr = new XMLHttpRequest();
xhr.open('GET', htmlFile, false); //Turns synchronous
xhr.addEventListener('load', () => {
if (xhr.readyState == 4 && xhr.status == "200") {
document.querySelector(selector).innerHTML += xhr.responseText;
}
else {
console.error(htmlFile + " does not exist");
}
});
xhr.send();
}

window.include = include;
@@ -0,0 +1,9 @@
'use strict';

function parseHTML(str) {
let tmp = document.implementation.createHTMLDocument();
tmp.body.innerHTML = str;
return tmp.body.children[0];
}

export { parseHTML };
@@ -0,0 +1,52 @@
'use strict';

// Time in seconds during which the session token is valid
const TOKEN_VALIDITY_TIME = 86400;

const sessionManager = {

login: function (sessionToken, userData) {
localStorage.setItem("sessionToken", sessionToken);
localStorage.setItem("sessionTokenTime", new Date().getTime());
localStorage.setItem("loggedUserData", JSON.stringify(userData));
},

logout: function () {
localStorage.removeItem("sessionToken");
localStorage.removeItem("sessionTokenTime");
localStorage.removeItem("loggedUserData");
},

getToken: function () {
let token = localStorage.getItem("sessionToken");

// Logout if the token has expired
if (token !== null) {
let currentDate = new Date().getTime();
let tokenDate = localStorage.getItem("sessionTokenTime");
let diff = currentDate - tokenDate;

if (diff > TOKEN_VALIDITY_TIME * 1000) {
console.error("The session has expired, logging out.");
this.logout();
token = null;
}
}

return token;
},

isLogged: function () {
return this.getToken() !== null;
},

getLoggedUser: function () {
return JSON.parse(localStorage.getItem("loggedUserData"));
},

getLoggedId: function () {
return this.isLogged() ? this.getLoggedUser().userId : null;
}
};

export { sessionManager };
@@ -0,0 +1,55 @@
from silence.decorators import endpoint

@endpoint(
route="/photos",
method="GET",
sql="SELECT * FROM Photos"
)
def get_all():
pass

###############################################################################

@endpoint(
route="/photos/$photoId",
method="GET",
sql="SELECT * FROM Photos WHERE photoId = $photoId"
)
def get_by_id():
pass

###############################################################################

@endpoint(
route="/photos",
method="POST",
sql="INSERT INTO Photos (title, description, url, visibility, userId) VALUES ($title, $description, $url, $visibility, $userId)",
description="Creates a new photo",
auth_required=True,
)
def create(title, description, url, visibility, userId):
pass

###############################################################################

@endpoint(
route="/photos/$photoId",
method="PUT",
sql="UPDATE Photos SET title = $title, description = $description, url = $url, visibility = $visibility WHERE photoId = $photoId",
description="Updates an existing photo",
auth_required=True,
)
def update(title, description, url, visibility):
pass

###############################################################################

@endpoint(
route="/photos/$photoId",
method="DELETE",
sql="DELETE FROM Photos WHERE photoId = $photoId",
description="Removes a photo",
auth_required=True,
)
def delete():
pass
@@ -0,0 +1,9 @@
from silence.decorators import endpoint

@endpoint(
route="/users/$userId",
method="GET",
sql="SELECT * FROM Users WHERE userId = $userId"
)
def get_by_id():
pass

0 comments on commit 5cc76c8

Please sign in to comment.