Skip to content

Commit dc42750

Browse files
committed
Merge branch 'develop' into routes
# Conflicts: # Pipfile # Pipfile.lock # README.md # src/api/controllers/userController.py # src/api/views/__init__.py # src/api/views/userView.py
2 parents 03db9c3 + 4f8ad8c commit dc42750

File tree

14 files changed

+323
-93
lines changed

14 files changed

+323
-93
lines changed

.circleci/config.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
version: 2.1
2+
3+
jobs:
4+
docker-build:
5+
machine: true
6+
steps:
7+
- checkout
8+
# Build the application image to make sure it works
9+
- run:
10+
command: docker build -t programmingbuddies/programmingbuddies-api .
11+
name: Build docker image
12+
13+
docker-push:
14+
machine: true
15+
steps:
16+
- checkout
17+
# Log into dockerhub using docker cli.
18+
# Credentials are stored in the UI using env variables (They are kept secret don't worry)
19+
# https://circleci.com/docs/2.0/env-vars/#secrets-masking
20+
- run:
21+
command: echo "$DOCKER_PASS" | docker login --username $DOCKER_USER --password-stdin
22+
name: Dockerhub login
23+
24+
# Build the image.
25+
# We could use something like $CIRCLE_BRANCH to correctly tag images,
26+
# but latest is probably fine for now.
27+
- run:
28+
command: docker build -t programmingbuddies/programmingbuddies-api:latest .
29+
name: Build docker image
30+
31+
# Push the built image to the dockerhub organization
32+
- run:
33+
command: docker push programmingbuddies/programmingbuddies-api:latest
34+
name: Push image to registry
35+
36+
workflows:
37+
main:
38+
jobs:
39+
- docker-build
40+
- docker-push:
41+
filters:
42+
branches:
43+
only:
44+
- develop
45+
requires:
46+
- docker-build

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,4 +347,8 @@ healthchecksdb
347347

348348
# Visual Studio Code
349349
.vscode/
350-
*.pem
350+
*.pem
351+
352+
353+
# Sqlite
354+
db.sqlite3

Pipfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ pyopenssl = "*"
1616
flask-swagger = "*"
1717
flask-swagger-ui = "*"
1818
pytest = "*"
19+
flask-cors = "*"
20+
flask-login = "*"
21+
blinker = "*"
1922

2023
[requires]
2124
python_version = "3.7"

Pipfile.lock

Lines changed: 62 additions & 37 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,40 @@
11
# Programming Buddies API
2-
API backend for Programming Buddies (projects management)
32

4-
## Tech Stack
5-
- Python 3.7
6-
- Flask
7-
- MySql
8-
- pyOpenSSL
3+
API backend for [Programming Buddies](https://github.com/ProgrammingBuddies/programmingbuddies-ui) (projects management)
94

10-
## Set up guide
11-
- Download and install MySQL Community Server from `https://dev.mysql.com/downloads/mysql/`
12-
- `git clone https://github.com/ProgrammingBuddies/programmingbuddies-api.git`
5+
## Set up guide: The simple way
136

14-
### The simple way
7+
- Set up your [environment](#environment)
8+
- Install [docker-compose](https://docs.docker.com/compose/install/) and do `docker-compose up`
159

16-
Install docker-compose and do `docker-compose up`. Don't forget to setup your
17-
.env file.
10+
## Set up guide: The 'bothersome' way
1811

19-
### Pipenv
20-
- run `python -m pip install pipenv` to install pipenv
21-
- run `pipenv install` inside the repository
22-
- - if you have multiple Python versions installed you might need to specify which one to use `pipenv install --python=python3.7`
12+
Requirements:
2313

24-
### SSL
25-
- On Mac or linux install the openssl tool and run `openssl req -x509 -newkey rsa:4096 -nodes -out cert.pem -keyout key.pem -days 365` inside the repository
26-
- On windows ... explanation will follow.
14+
- Set up your [environment](#environment)
15+
- [MySQL Community Server](`https://dev.mysql.com/downloads/mysql/`)
16+
- Add line `CONNECT=mysql+pymysql://<user>:<password>@localhost:3306/<database name>` to your [`.env` file](#environment) to specify connection parameters
17+
- Pipenv
18+
1. Run `python -m pip install pipenv` to install pipenv
19+
2. Run `pipenv install` inside the repository
20+
- If you have multiple Python versions installed you might need to specify which one to use `pipenv install --python=python3.7`
21+
- SSL
22+
1. On Mac or Linux install the openssl tool and run `openssl req -x509 -newkey rsa:4096 -nodes -out cert.pem -keyout key.pem -days 365` inside the repository
23+
2. On Windows ... explanation will follow.
2724

28-
### Environment
29-
- create a file `.env`
30-
- - `.env` in this case is the full filename and not just the extension. `app.env` for example would not be loaded automatically by pipenv
31-
- - add line `FLASK_ENV=development` to have the server automatically restart on file changes
32-
- - add line `CONNECT=mysql+pymysql://<user>:<password>@localhost:3306/<database name>` to specify connection parameters
25+
Run the server:
3326
- `pipenv run python src/runserver.py`
34-
- - run with flag `--reset-db` to recreate all tables on start
35-
- add line `APP_SECRET=somepassword` as app secret. This is used to sign sessions among other things and is required
36-
- Optain credentials for Github
37-
- - Under your github account Settings go to Developer Settings and OAuth Apps
38-
- - create a new one and set the homepage url to `https://localhost:5001/` and Authorization callback to `https://localhost:5001/login/github/authorized`
39-
- - Copy the Client Id and Client Secret from that site and save them in `.env`as `GITHUB_ID` and `GITHUB_SECRET` respectively
27+
- Run with flag `--reset-db` to drop and recreate all tables on start
28+
29+
## Environment
30+
31+
1. Create a file named `.env`
32+
- Add line `FLASK_ENV=development` to have the server automatically restart on file changes
33+
2. Add line `APP_SECRET=somepassword` as app secret. This is used to sign sessions among other things and is required
34+
3. Obtain credentials for GitHub OAuth
35+
- Under your GitHub account Settings go to Developer settings and OAuth Apps
36+
- Create a new one and set the homepage url to `https://localhost:5001/` and Authorization callback to `https://localhost:5001/login/github/authorized`
37+
- Copy the Client Id and Client Secret from that site and save them in `.env` as `GITHUB_ID` and `GITHUB_SECRET` respectively
4038

4139
Your `.env` file should now look something like [example.env](https://github.com/ProgrammingBuddies/programmingbuddies-api/blob/develop/example.env)
4240

@@ -50,3 +48,9 @@ Your `.env` file should now look something like [example.env](https://github.com
5048
- [ ] build DB and endpoints with basic CRUD
5149
- [ ] add security for app (ie - bots, and non-human actors/clients)
5250
- [ ] add users and profile stores as well as registration/management API endpoints for users
51+
## Tech stack:
52+
53+
- Python
54+
- Flask
55+
- MySQL
56+
- pyOpenSSL

src/api/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
"""
44

55
from flask import Flask
6+
from flask_cors import CORS
7+
8+
69
app = Flask(__name__)
10+
cors = CORS(app, origins="*", supports_credentials=True)
711
# Disable sorting of the jsonified data
812
app.config['JSON_SORT_KEYS'] = False
913

src/api/controllers/projectController.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ def update_project(self, id, **kwargs):
3131

3232
return project
3333

34+
def update_project(self, id, **kwargs):
35+
project = Project.query.filter_by(id=id).first()
36+
37+
if project == None:
38+
return project
39+
40+
for key, value in kwargs.items():
41+
setattr(project, key, value)
42+
43+
db.session.commit()
44+
45+
return project
46+
3447
def get_project(self, **kwargs):
3548
project = Project.query.filter_by(**kwargs).first()
3649

src/api/controllers/userController.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
from api.models import db, User, UserHasProject, UserLink, UserFeedback
2+
from flask_login import LoginManager
3+
from api import app
24

35
class UserController:
46
session = db.session()
57

8+
login_manager = LoginManager()
9+
login_manager.init_app(app)
10+
611
# User
712
def create_user(self, **kwargs):
813
try:
@@ -32,6 +37,20 @@ def update_user(self, id, **kwargs):
3237

3338
return user
3439

40+
def update_user(self, id, **kwargs):
41+
user = User.query.filter_by(id=id).first()
42+
43+
if user == None:
44+
return user
45+
46+
for key, value in kwargs.items():
47+
setattr(user, key, value)
48+
49+
db.session.commit()
50+
51+
return user
52+
53+
@login_manager.user_loader
3554
def get_user(self, **kwargs):
3655
user = User.query.filter_by(**kwargs).first()
3756

0 commit comments

Comments
 (0)