forked from shahrk/feature-hunt
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merging Backend and Backend-new (#125)
* added pylint workflow w/artifacts run: pylint --fail-under=1 $(find . -name "*.py" | xargs) note: set the failure threshold as indicated above actions/starter-workflows#636 (comment) * Added CodeQL & Pylint badges, edits * Added CodeQL badge * Added Pylint badge * Minor edits: updated git clone steps * Lowered pylint failure theshold * Update and rename build.yml to coveralls.yml * Added test files to pylint.yml * Updated py files to improve pylint score * Fixed error in coveralls.yml * Removed individual tests in pylint.yml * Added pylint labels * Added test workflow * Update and rename nodejsTest.yml to nodejs.yml * Update nodejs.yml * Update nodejs.yml * Added workflow build badge to README * Added yet another workflow All for the sake of a test badge. * Added test badge * Revert "group25 workflows" * Added post to Service.js and connected login form (incomplete) * Added appropriate error messages and display for errors * Added Sign up form * Added error handling and redirecting for login and sign up * fix to react compile warning * Dashboard and tag edits are now limited by user * New tags can now be saved in the database * Adding Product Controller and Test Cases * Adding more user auth and product auth test cases * Changing gitignore * Fixing test cases for user-auth class * Removing test cases which are not used * Commented out unused tests, added pylint comments * Restored and commented out unused tests * Added pylint skip comments * Removing merging backend and backend-new into a single directory * Increasing Pylint Score * Increasing Pylint score Co-authored-by: Leila Moran <lmmoran@ncsu.edu> Co-authored-by: Emily Tracey <etracey@ncsu.edu> Co-authored-by: peeyush10234 <ptaneja@ncsu.edu>
- Loading branch information
1 parent
c270a16
commit 25488ac
Showing
20 changed files
with
201 additions
and
497 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import pymongo | ||
|
||
client = pymongo.MongoClient("mongodb+srv://bot:bot123@cluster0.xph5e.mongodb.net/myFirstDatabase?retryWrites=true&w=majority") | ||
db = client.get_database('feature-hunt') | ||
records = db.user | ||
product_records = db.products |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,45 @@ | ||
from app import * | ||
# pylint: disable=wrong-import-position,pointless-string-statement,undefined-variable,line-too-long | ||
|
||
from flask import jsonify | ||
from flask import request | ||
from app import app | ||
from db_init import product_records | ||
|
||
|
||
@app.route("/addProduct", methods=['Post']) | ||
def addProduct(): | ||
def add_product(): | ||
try: | ||
product_name = request.form.get("productName") | ||
product_description = request.form.get("productDescription") | ||
image_url = request.form.get("imageUrl") | ||
email = request.form.get("email") | ||
|
||
product_input = {'product_name' : product_name, 'product_desc': project_description, | ||
'image_url' : image_url, 'email' : email} | ||
product_input = {'name': product_name, 'description': product_description, | ||
'image_url': image_url, 'users': [email]} | ||
|
||
product_records.insert_one(product_input) | ||
|
||
return jsonify(success=True) | ||
except: | ||
return jsonify(success=False) | ||
|
||
@app.route("/<productName>/getFeature", method=['Get']) | ||
def getFeature(productName): | ||
result = product_record.find({"productName"}) | ||
return dumps(result) | ||
|
||
|
||
@app.route("/<productName>/addFeature", method=['Post']) | ||
def addFeature(productName): | ||
if request.method == 'POST': | ||
data = request.json | ||
data['_id'] = ObjectId() | ||
print(data) | ||
if data is None or data == {}: | ||
return Response(response=json.dumps({"Error": "Please provide connection information"}), | ||
status=400, | ||
mimetype='application/json') | ||
result = product_records.find_one_and_update({"project_name": productName}, {"$push": {"features": data}}) | ||
|
||
return jsonify(success=True) | ||
|
||
elif request.method == 'GET': | ||
result = mongo.db.products.find({"name": productname}, {"features": 1}) | ||
return dumps(result) | ||
|
||
# @app.route("/<productName>/addFeature", method=['Post']) | ||
# def addFeature(productName): | ||
# if request.method == 'POST': | ||
# data = request.json | ||
# data['_id'] = ObjectId() | ||
# print(data) | ||
# if data is None or data == {}: | ||
# return Response(response=json.dumps({"Error": | ||
# "Please provide connection information"}), | ||
# status=400, | ||
# mimetype='application/json') | ||
# result = product_records.find_one_and_update( | ||
# {"project_name": productName}, {"$push": {"features": data}} | ||
# ) | ||
# | ||
# return jsonify(success=True) | ||
# | ||
# elif request.method == 'GET': | ||
# result = mongo.db.products.find({"name": productname}, {"features": 1}) | ||
# return dumps(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
""" | ||
Copyright (C) 2021 Feature Hunt - All Rights Reserved | ||
You may use, distribute and modify this code under the terms of the MIT license. | ||
You should have received a copy of the XYZ license with | ||
this file. If not, please write to: featurehuntteam@gmail.com | ||
""" | ||
|
||
# pylint: disable=wrong-import-position,poiackend-lontless-string-statement,undefined-variable,line-too-long | ||
|
||
import os | ||
from sys import stderr | ||
from flask import request, jsonify | ||
from flask import json | ||
from app import app | ||
|
||
from bson.json_util import dumps | ||
from bson.objectid import ObjectId | ||
from db_init import product_records | ||
|
||
''' | ||
Function: products | ||
Description: Get/ Add/ Update/ Delete the products from the database | ||
Inputs: | ||
- NA | ||
Outputs: | ||
- NA | ||
''' | ||
|
||
|
||
@app.route('/products', methods=['GET', 'POST', 'DELETE', 'PATCH']) | ||
def products(): | ||
if request.method == 'GET': | ||
data = product_records.find() | ||
return dumps(data) | ||
|
||
data = request.get_json() | ||
|
||
if request.method == 'POST': | ||
if data is None or data == {}: | ||
return Response(response=json.dumps({"Error": "Please provide all necessary input"}), | ||
status=400, | ||
mimetype='application/json') | ||
return jsonify({'ok': True, 'message': 'Product added successfully'}), 200 | ||
|
||
if request.method == 'DELETE': | ||
if data is None or data == {}: | ||
return Response(response=json.dumps({"Error": "Please provide all necessary input"}), | ||
status=400, | ||
mimetype='application/json') | ||
|
||
db_response = product_records.delete_one({'id': data[id]}) | ||
if db_response.deleted_count == 1: | ||
response = {'ok': True, 'message': 'record deleted'} | ||
else: | ||
response = {'ok': True, 'message': 'no record found'} | ||
return jsonify(response), 200 | ||
|
||
if request.method == 'PATCH': | ||
if data.get('query', {}) != {}: | ||
product_records.update_one( | ||
data['query'], {'$set': data.get('payload', {})}) | ||
return jsonify({'ok': True, 'message': 'record updated'}), 200 | ||
else: | ||
return jsonify({'ok': False, 'message': 'Bad request parameters!'}), 400 | ||
|
||
|
||
''' | ||
Function: get_feature | ||
Description: Get the list of all features for given product name | ||
Inputs: | ||
- productName: Name of the product | ||
Outputs: | ||
- results: List of features that are available in that product | ||
''' | ||
|
||
|
||
@app.route('/<productname>/getFeature', methods=['GET', 'POST']) | ||
def get_feature(product_name): | ||
if request.method == 'GET': | ||
data = product_records.find({"name": product_name}) | ||
return dumps(data) | ||
|
||
|
||
''' | ||
Function: features | ||
Description: You can add/get features of a product | ||
Inputs: | ||
- productName: Name of the product | ||
Outputs: | ||
- results: Add features to that product or return feature list | ||
''' | ||
|
||
|
||
@app.route('/<productname>/features', methods=['GET', 'POST']) | ||
def features(product_name): | ||
result = '' | ||
if request.method == 'POST': | ||
data = request.form.get('features') | ||
data = json.loads(data) | ||
print(data, flush=True) | ||
if data is None or data == {}: | ||
return Response(response=json.dumps({"Error": "Please provide connection information"}), | ||
status=400, | ||
mimetype='application/json') | ||
result = product_records.find_one_and_update({"name": productname}, {"$set": {"features": data}}) | ||
|
||
elif request.method == 'GET': | ||
result = product_records.find({"name": product_name}, {"features": 1}) | ||
return dumps(result) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.