stc

a simple time card webapp
git clone _git@git.brennen.work:stc.git
Log | Files | Refs | README

commit 67adb0b33f9bac1ef059a622a7c424034ffe1ceb
parent 53e2e80601597cfe3c53163c0ed062d08bbece36
Author: Brennen T. Mazur <brennen@madis.cool>
Date:   Wed, 18 Jan 2023 18:23:44 -0700

Merge branch 'backend' of git.brennen.work:stc into backend

Diffstat:
Mapp.py | 12++++++++++++
Amodels.py | 140+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aroutes.py | 10++++++++++
3 files changed, 162 insertions(+), 0 deletions(-)

diff --git a/app.py b/app.py @@ -6,6 +6,8 @@ from flask_login import UserMixin, login_user, LoginManager, login_required, log from pymongo import MongoClient; from flask_bcrypt import Bcrypt; +# import routes + OrganizationName = "Youth Employment Program" app = Flask(__name__) @@ -104,5 +106,15 @@ def knowlegebase(): # return render_template("index.html") # Routes +# import routes +from models import Users + + +@app.route('/user/signup', methods=['GET']) +def signup(): + return Users().signup() + + + if __name__ == '__main__': app.run(debug=True) diff --git a/models.py b/models.py @@ -0,0 +1,139 @@ +# Test enviroment added validators username +# removed BaseModel +# added jsonify +# fixed datetime + +import datetime +from flask import Flask, jsonify + +from fastapi.encoders import jsonable_encoder +from typing import List, Optional +from pydantic import BaseModel, Field, ValidationError, validator + +class Users: + + def signup(self): + users = { + '_id': '', + 'username': '', + 'password': '', + 'confirm_password': '', + 'role': '', + 'location': '', + 'phone': '', + 'email': '', + 'active': '', + 'pay_period': '', + 'pay_value': '', + } + + return jsonify(users), 200 + + def to_json(self): + return jsonable_encoder(self, exclude_none=True) + + def to_bson(self): + data = self.dict(by_alias=True, exclude_none=True) + + if data["_id"] is None: + data.pop("_id") + return data + + @validator('username') + def username_alphanumeric(cls, v): + assert v.isalnum(), 'Username must be alphanumeric' + return v + + @validator('confirm_password') + def password_confirmed(cls, v, values, **kwargs): + if 'password' in values and v != values['password']: + raise ValueError('Passwords do not match') + return v + +class Time: + + def clockin(self): + clockin = { + '_id': int, + 'clock_in': Optional[datetime.datetime.utcnow], + 'date': Optional[datetime.date], + 'project': str, + 'note': str, + } + + return jsonify(clockin), 200 + + def clockout(self): + clockout = { + '_id': int, + # 'clock_out': Optional[datetime.now], + 'date': Optional[datetime.date], + 'project': str, + 'note': Optional[str], + 'total_time': int + } + + return jsonify(clockout), 200 + + _id: int + # forign key + clock_in: Optional[datetime.datetime.utcnow] #System time + modified_by: str #link to _id of user + date: Optional [datetime.date] + project: str + clock_out: Optional[datetime.datetime.utcnow] #System time + note: str + perdium: bool + total_time: int #clock_out - clock_in + + def to_json(self): + return jsonable_encoder(self, exclude_none=True) + + def to_bson(self): + data = self.dict(by_alias=True, exclude_none=True) + + if data["_id"] is None: + data.pop("_id") + return data + + +class Fleet: + _id: int + date: Optional[datetime.datetime.utcnow] + operator: int #forign key to userID + safety_checks: bool #array for different safety checks + additional_notes: str + vehicle: int #vehicleID + incident_report: str + mileage: int + + def to_json(self): + return jsonable_encoder(self, exclude_none=True) + + def to_bson(self): + data = self.dict(by_alias=True, exclude_none=True) + + if data["_id"] is None: + data.pop("_id") + return data + + +class Agreement: + _id: int #forign key to user + start_date: int + end_date: int + bid_document: str #Filepath to document + budget: float + cost: int + +class Projects:#Projects references agreement + project_id: int + project_name: str + project_budget: List[float] = [ + # labor_budget: float | Indexed 0 + # travel_budget: float | Indexed 1 + # supplies_budget: float | Indexed 2 + # contact_budget: float | Indexed 3 + # equipment_budget: float | Indexed 4 + # other: float | Indexed 5 + ] +\ No newline at end of file diff --git a/routes.py b/routes.py @@ -0,0 +1,9 @@ +# Won't properly import to app.py + +from flask import Flask +from app import app +from models import Users, Time, Fleet, Agreement, Projects + +@app.route('/user/signup', methods=['GET']) +def signup(): + return Users().signup() +\ No newline at end of file