Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions API/app/Questions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,38 @@
from flask import request, jsonify, abort
from . import Questions

@app.route('/questions/<int:id>', methods=['GET', 'PUT', 'DELETE'])

@questions.route('/api/v1/questions/', methods=['POST', 'GET'])
def get_questions():
"""This function handles request to the questions resource"""
if request.method == 'GET':
# return all questions in the db
response = jsonify(data['questions'])
response.status_code = 200
else:
# POST request: Returns a new question with its id
question_id = int(data["questions"][-1]['id']) + 1
req_data = json.loads(request.data.decode('utf-8').replace("'", '"'))
question = req_data['question']
posted_by = req_data['namr']
date = '{:%B %d, %Y}'.format(datetime.now())
new_question = {
"id": question_id,
"text": question_text,
"posted_by": posted_by,
"date": date,
"answers": []
}
data['questions'].append(new_question)
response = jsonify(new_question)
response.status_code = 201

return response


@app.route('api/v1/questions/<int:id>', methods=['GET', 'PUT', 'DELETE'])
def question(id, **kwargs):
# GET request: Retrieve a buckelist using it's ID
# GET request: Retrieve a question using it's ID
question = Questions.query.filter_by(id=id).first()
if not :
# Raise an HTTPException with a 404 not found status code
Expand Down Expand Up @@ -36,7 +65,7 @@ def question(id, **kwargs):
'id': question.id,
'name': question.name,
'date_created': question.date_created,
'date_modified': bucketlist.date_modified
'date_modified': question.date_modified
})
response.status_code = 200
return response
Expand Down
2 changes: 1 addition & 1 deletion API/app/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def Login():

error = None
if request.method =="POST":
if request.form['username'] != 'admin' or request.form["password"] != 'admin':
if request.form['username'] != 'flaskuser' or request.form["password"] != 'flaskuser2018':
error = "Invalid credentials. Please try again."
else:
return redirect(url_for("UserAccount"))
Expand Down
28 changes: 0 additions & 28 deletions API/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,6 @@ def locate(id, items):
return None


@questions.route('/api/v1/questions/', methods=['POST', 'GET'])
def get_questions():
"""This function handles request to the questions resource"""
if request.method == 'GET':
# return all questions in the db
response = jsonify(data['questions'])
response.status_code = 200
else:
# handles a POST request
# return the new question with the question id
question_id = int(data["questions"][-1]['id']) + 1
req_data = json.loads(
request.data.decode('utf-8').replace("'", '"'))
question_text = req_data['text']
asked_by = req_data['asked_by']
date = '{:%B %d, %Y}'.format(datetime.now())
new_question = {
"id": question_id,
"text": question_text,
"asked_by": asked_by,
"date": date,
"answers": []
}
data['questions'].append(new_question)
response = jsonify(new_question)
response.status_code = 201

return response


@questions.route('/api/v1/questions/<int:id>', methods=['GET', 'PUT', 'DELETE'])
Expand Down
20 changes: 19 additions & 1 deletion API/run.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
from flask import Flask

from flask_restful import Api




def create_app(env="dev"):
app = Flask(__name__)
api = Api(app)


)



return app
from app import run


from app import app


if __name__ == '__main__':
Expand Down
6 changes: 5 additions & 1 deletion API/tests/test_Questions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
import os
import json





class BaseTestCase(TestCase):

def setUp(self):

"""Configure test enviroment."""

os.environ['APP_SETTINGS'] = 'Testing'
self.app = create_app("Testing")
self.app_context = self.app.app_context()
Expand Down
134 changes: 133 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,138 @@
# StackOverflow-Lite


[![Build Status](https://travis-ci.org/Waitherambugua/StackOverflow-Lite.svg?branch=database_tests)](https://travis-ci.org/Waitherambugua/StackOverflow-Lite)

StackOverflow is a web aplication that allows usere to view and upload questions.

Project Overview
StackOverflowLite is a platform where people can ask questions and provide answers.

Required Features
A user can create an account and log in
A user can post questions
A user can delete the questions they post
A user can post answers
A user can view the answers to the questions
A user can accept answer out of all answers to his/her questions as the preferred answer.

**UI Templates**
Home Page
User Registration
User Login
User Profile Page
Post a question page
View a single questions and answers page
View questions and answers page
StackOverFlowLite Complete UI template on gh-pages
[a link](https://waitherambugua@github.io) link
Getting started
The following instructions will get a copy of StackOverFlowLite up and running on your machine for development and testing purposes

*Requirements*
StackOverFlowLite will require the following:

A computer running on any distribution of Unix or Mac or Windows OS
Installation
Clone the repository to your local machine
$ git clone https://github.com/waitherambugua/StackOverflow-Lite.git
Navigate to the directory
$ cd StackOverflowLite/UI
Open the file
$ pen index.html file with a browser of your choice
Create API endpoints
Getting started
The following instructions will get a copy of StackOverFlowLite up and running on your machine for development and testing purposes

**The API**
**Requirements**
StackOverFlowLite will require the following:

A computer running on any distribution of Windows OS or get some help from your administrator on how to install the application if on another OS
Python 3.5 or higher
Pip
Git
Virtualenv
Installation

To clone and run this application, you will need Git installed on your computer. From your command line:

# Clone this repository to your local machine
$ git clone https://github.com/waitherambugua/StackOverflow-Lite.git

# Navigate to the folder that contains the app
$ cd StackOverflow-Lite

# Create a virtual environment and activate it
$ virtualenv -p python3 venv

# Activate the virtual environment
$ source venv/bin/activate

# Install the requirements
$ pip install -r requirements.txt

# Launch the application
$ python3 run.py

### Run the tests
$ nosetests --with-coverage
API endpoints
Users Endpoints
Method | Endpoint | Functionality
----------------------------------------------------------------------------------
POST | /StackOverFlowLite/api/v1/auth/register | Creates a user account

POST | /StackOverFlowLite/api/v1/auth/login | Logs in a user

POST | /StackOverFlowLite/api/v1/auth/logout | Logs out a user

PUT | /StackOverFlowLite/api/v1/auth/reset-password | Reset a password for a logged user

DELETE | /StackOverFlowLite/api/v1/questions/question-ID | Delete a request of a logged in user

Questions Endpoints

Method | Endpoint | Functionality
----------------------------------------------------------------------------------
POST |/StackOverFlowLite/api/v2/questions | Add a question

POST |/StackOverFlowLite/api/v2/questions/question-ID/answers | Add an answer

GET |/StackOverFlowLite/api/v2/questions | Lists all questions

GET | /StackOverFlowLite/api/v2/questions/questionID | List a question

PUT | /StackOverFlowLite/api/v2/questions/questionID | Edit a question

DELETE | /StackOverFlowLite/api/v2/questions/questionID | Delete a question

Answers Endpoints
Method| Endpoint | Functionality
----------------------------------------------------------------------------------
POST |/StackOverFlowLite/api/v2/questions/question-ID/answers | Add an answer

GET |/StackOverFlowLite/api/v2/questions/questionID/answers | Lists all answers

PUT |/StackOverFlowLite/api/v2/questions/questionID/answer/answerID | Edit an answer


StackOverFlowLite hosted on Heroku

stackoverflowlite on heroku

**Build with**
HTML, CSS, Javascript
Flask RESTful API

**How to Contribute**
Fork repository to your github account
Create a branch
Make changes
Create a pull request


Contributors Linda Mbugua

Gh-pages: https://waitherambugua.github.io
Heroku API link: https://lstackoverflowlite-api-heroku.herokuapp.com/
Heroku API link: https://mstackoverflowlite.herokuapp.com/
45 changes: 6 additions & 39 deletions UI/PostQuestion.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<<<<<<< HEAD

<!DOCTYPE html>
<html>
Expand Down Expand Up @@ -36,44 +35,12 @@ <h1><i class="fas fa-sun"></i>StackOverFlow - Lite</h1>

</div>
</div>

=======

<!DOCTYPE html>
<html>

<body>
<div class = "wrapper">
<div class = "main">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> Post a Question </title>
<link href = "mains.css" rel="stylesheet" type = "text/css" >
<link href="https://fonts.googleapis.com/css?family=Roboto+Slab" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/all.css" integrity="sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ" crossorigin="anonymous">
</head>
<header>
<div class = "container-1">
<h1><i class="fas fa-sun"></i>StackOverFlow - Lite</h1>
<nav >
<ul>
<li><a href="Forum.html" >Forum </a></li>
<li><a href="SignUp.html" >Sign Up </a></li>
</ul>
</nav>
</div>
</header>

<div class = container>
<div class = "RecentQuestions">
<form action="action-page.php">
<input type="text" class = "postAnswer" name="postAnswer" placeholder="Write your question here" >
<br>
<button type="submit" class= "button-2" >Post a Question</button><br>
</form>
</div>
</div>
<footer> &copy 2018 StackOverFlow - Lite. All Rights Reserved. <a href="#">Terms of Service</a>
</footer>

</div>
</div>
</body>
</html>

>>>>>>> 0bfb9e46bf63fafcd0a0d919363fb4198787b71f
5 changes: 5 additions & 0 deletions UI/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
for (const btn of document.querySelectorAll('.vote')) {
btn.addEventListener('click', event => {
event.target.classList.toggle('on');
});
}
11 changes: 11 additions & 0 deletions v2/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from flask import flask
from flask_restful import Api

from api.endpoints.users import (signup, login)
from api.endpoints.questions import (signup, login)

app = Flask(__name__)
api = Api(app)

api.add_resource(UserRegister, '/api/v2/auth/signup')
api.add_resource(UserLogin, '/api/v2/auth/login')
Empty file added v2/api/database/__init__.py
Empty file.
Loading