Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
2089170
Create Hello world endpoint
Lakorthus Jun 20, 2023
1571f0a
tested and updated readme instructions for running app
piratejas Jun 20, 2023
ea1d499
test: test_hello_world controller function.
Lakorthus Jun 20, 2023
0af031b
test: routes on hello_world
Lakorthus Jun 20, 2023
b0d5802
Merge pull request #2 from methods/feat_hello_world
Lakorthus Jun 20, 2023
63c02ba
feat: added and manually tested post route for bid
piratejas Jun 21, 2023
ac87d4e
feat: saving data in memory and separating logic
Lakorthus Jun 22, 2023
d1f230c
wip: add phase info to success/failed
piratejas Jun 22, 2023
53d3913
feat: field validation, set status enum
piratejas Jun 22, 2023
3d0dc1c
test: add post bid route tests
piratejas Jun 22, 2023
7641b4b
Merge pull request #3 from methods/feat/create-new-bid
piratejas Jun 22, 2023
2d6d8cf
fix: renamed files and folders for readability
piratejas Jun 23, 2023
65901b1
Merge pull request #4 from methods/fix/filenames-improvement
piratejas Jun 23, 2023
027cc43
fix: changed set_status
piratejas Jun 23, 2023
817cd3d
wip: swagger spec config
piratejas Jun 23, 2023
cc3763c
docs: Update contribution guidelines to incl. release and tagging
nshumoogum Jun 23, 2023
34c1a45
fix: installed flask_swagger_ui; created swagger_config.yml
piratejas Jun 26, 2023
44145f6
chore: flask-ui added to the requirements
Lakorthus Jun 27, 2023
4a35b21
Merge branch 'feat/swagger-spec' into fix/set-status-enum
Lakorthus Jun 27, 2023
03520b5
Merge pull request #7 from methods/fix/set-status-enum
Lakorthus Jun 27, 2023
2d2d28f
fix: swagger config structure
piratejas Jun 27, 2023
5f10e67
refactor: swagger config components and refs
piratejas Jun 27, 2023
cd2bc74
feat: completed swagger spec for post bid endpoint
piratejas Jun 28, 2023
0e0677e
Merge pull request #8 from methods/feat/swagger-spec
piratejas Jun 28, 2023
9249e09
refactor: success and failed phase info
piratejas Jun 28, 2023
6d1fdbc
refactor: added helper function and logic for feedback
piratejas Jun 28, 2023
3ac5bd2
Merge pull request #9 from methods/refactor/post-bid-endpoint
piratejas Jun 29, 2023
8d7aaac
refactor: added marshmallow schemas; renamed classes and fixed import…
piratejas Jun 29, 2023
1b48bc2
refactor: handling ValidationError with marshmallow and outputting cu…
piratejas Jun 30, 2023
ed395ce
refactor: added test request bodies to check validation
piratejas Jun 30, 2023
a430451
refactor: removed unused imports
piratejas Jun 30, 2023
22e3002
refactor: moved class declarations to models folder; updated swagger …
piratejas Jul 3, 2023
29ac930
refactor: updated readme with swagger instructions
piratejas Jul 3, 2023
1e147e5
Merge pull request #10 from methods/refactor/implementing-marshmallow
piratejas Jul 3, 2023
042e4f2
feat: connect to mongodb instance; refactored post
piratejas Jul 3, 2023
b099087
Update README.md
piratejas Jul 3, 2023
3de2be9
Update README.md
piratejas Jul 3, 2023
efc5e00
refactor: added information to readme; changed db name to bidsAPI
piratejas Jul 3, 2023
15c2663
refactor: updated swagger _id fields
piratejas Jul 4, 2023
927bbb9
wip: tests for post route mocking db response
piratejas Jul 4, 2023
3a6bd89
Merge pull request #11 from methods/feat/mongodb-connection
piratejas Jul 4, 2023
4b3df65
feat: added swagger spec for get_all_bids endpoint
piratejas Jul 4, 2023
ebe66dd
feat: swagger spec created for get bid/id
Lakorthus Jul 4, 2023
81b1635
Merge pull request #12 from methods/feat/swagger_spec-get_bid/{id}
piratejas Jul 4, 2023
3c74327
feat: incorporated julio changes to swag
piratejas Jul 4, 2023
1a56618
Merge pull request #13 from methods/feat/get-all-bids-swagger
piratejas Jul 4, 2023
6d2e3f8
feat: phase schema validation and enum added
Lakorthus Jul 4, 2023
f43b88b
fix: validation for the phase schema
Lakorthus Jul 5, 2023
70f9c77
Merge pull request #14 from methods/feat/phase-enum
Lakorthus Jul 5, 2023
cca05b2
feat: get all bids from MongoDB
Lakorthus Jul 5, 2023
f0cca03
fix: format return bids
Lakorthus Jul 5, 2023
61a0331
feat: added get by id and handling error responses
piratejas Jul 5, 2023
f4a0bf4
refactor: removed unused imports and added comments
piratejas Jul 5, 2023
31a5ad7
test: get all bids and check connection failure
Lakorthus Jul 5, 2023
b5daebf
test: post bid test
Lakorthus Jul 6, 2023
12a47d5
test: error if you are not able to retrive bids
Lakorthus Jul 6, 2023
a43e8ca
test: test suite for get_bid_by_id
piratejas Jul 6, 2023
a532235
test: added validation error test
piratejas Jul 6, 2023
8d88c70
Merge pull request #15 from methods/feat/get-bid-by-id
piratejas Jul 6, 2023
4f1c3e7
Merge branch 'develop' into feat/get_all
Lakorthus Jul 6, 2023
918d4e9
Merge pull request #16 from methods/feat/get_all
Lakorthus Jul 6, 2023
3b2c8d4
fix: debugged valid_bid_id_schema
piratejas Jul 11, 2023
eab3874
test: bid model and schema validation
piratejas Jul 11, 2023
e15ee6d
refactor: removed unused import
piratejas Jul 11, 2023
078695d
feat: Route for delete added Swag spec and test
Lakorthus Jul 11, 2023
90269e5
Merge pull request #17 from methods/feat/delete-route
Lakorthus Jul 11, 2023
87c5c2c
Update all_fields.http
piratejas Jul 11, 2023
d5f9a18
Merge pull request #18 from methods/test/bid-request-schema-validation
piratejas Jul 11, 2023
cc8904f
test: delete by id validation error
Lakorthus Jul 12, 2023
1bac2b9
Merge pull request #19 from methods/feat/delete_bid
Lakorthus Jul 12, 2023
06adef2
feat: added query to get_all to filter by status not equals to deleted
piratejas Jul 12, 2023
49ad68a
refactor: testing without magicMock
Lakorthus Jul 13, 2023
b5add45
fix: updated soft delete method from PUT to DELETE
piratejas Jul 13, 2023
1a7ba79
feat: added swag spec and endpoint for update bid route; changed bid …
piratejas Jul 13, 2023
c841aeb
refactor: updated examples in swagger spec
piratejas Jul 13, 2023
6ceb406
Merge pull request #20 from methods/feat/filtering-out-deleted
piratejas Jul 17, 2023
222f5a2
Merge pull request #21 from methods/refactor/test-magicMock
Lakorthus Jul 17, 2023
700d658
Merge branch 'develop' into feat/update-bid-by-id
piratejas Jul 17, 2023
8b26e55
Merge pull request #22 from methods/feat/update-bid-by-id
piratejas Jul 17, 2023
b3b574b
test: update bid by id tests; refactored to add helper functions for …
piratejas Jul 17, 2023
6f2f6a2
refactor: removed unused imports
piratejas Jul 17, 2023
f9ae9e9
refactor: cleaned up controller
piratejas Jul 18, 2023
1238a99
refactor: changed find and replace to update one; wip: adding last_up…
piratejas Jul 18, 2023
1c986c2
test: updating tests after refactor
piratejas Jul 18, 2023
dcd3f6a
test: updated tests after refactoring
piratejas Jul 18, 2023
386a13b
Merge pull request #23 from methods/test/update-bid-by-id
piratejas Jul 18, 2023
a9f169c
feat: Makefile
Lakorthus Jul 18, 2023
f573dcb
refactor: README and req.txt updated with Makefile
Lakorthus Jul 18, 2023
99d5a63
feat: vulnerability check using safety
Lakorthus Jul 18, 2023
8859be2
refactor: added custom error message to path param validation
piratejas Jul 19, 2023
8329de6
feat: commit script Makefile
Lakorthus Jul 19, 2023
b6f3e0e
feat: commit message to gitignore
Lakorthus Jul 19, 2023
738434a
refactor: makefile check
Lakorthus Jul 19, 2023
d642f7a
test: testing commit msg
Lakorthus Jul 19, 2023
eea3c3b
test: test commit msg
Lakorthus Jul 19, 2023
9a4b05c
test:
Lakorthus Jul 19, 2023
b648ac0
Merge pull request #25 from methods/feat/gmakefile
Lakorthus Jul 19, 2023
cc28971
refactor: updated swagger to include additional error responses
piratejas Jul 19, 2023
b7a95d4
Merge pull request #26 from methods/refactor/error-handling
piratejas Jul 19, 2023
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

Expand Down Expand Up @@ -127,6 +126,9 @@ venv/
ENV/
env.bak/
venv.bak/
commit_message.txt
./commit_message.txt


# Spyder project settings
.spyderproject
Expand Down
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.formatting.provider": "none"
}
59 changes: 55 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,61 @@
Contributing guidelines
=======================
# Contributing guidelines

### Git workflow
## Git workflow

* Use git-flow - create a feature branch from `develop`, e.g. `feature/new-feature`
* Use git-flow - create a feature branch from `develop`, e.g. `feat/new-feature`
* Pull requests must contain a succinct, clear summary of what the user need is driving this feature change
* Ensure your branch contains logical atomic commits before sending a pull request
* You may rebase your branch after feedback if it's to include relevant updates from the develop branch. It is preferable to rebase here then a merge commit as a clean and straight history on develop with discrete merge commits for features is preferred
* To find out more about contributing click [here](https://contributing.md/)

## Commit messages

Please use the following format for commit messages:

```textbox
* fix: for a bug fix
* feat: for a new feature
* docs: for documentation changes
* style: for changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
* refactor: for refactoring production code
* test: for adding tests
* chore: for updating build tasks, package manager configs, etc
* build: for changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
```

## Pull requests

* Pull requests should be made to the `develop` branch
* Pull requests should be made from a feature branch, not `develop`
* Pull requests should be made with a succinct, clear summary of what the user need is driving this feature change
* An automated template will be provided to help with this process, please fill it out as best you can

## Release branches and Tagging

* Once a single or set of changes has been made that can be released, we create a release branch off develop
* Releases should be as small as possible so that it is easier to fix issues and rollback code in production environment without losing many features at once
* Release branches should be of the following structure:

```sh
release/0.1.0
```

* The release name should abide by [semantic versioning (semver)](https://semver.org/)
* Once release branch has been created, a pull request should be made against the `main` branch
* Once approved, the release branch can be merged locally :warning: **WARNING - Do not push to remote** :warning:
* Tag the release and push to remote - [see tagging](#tagging)

## Tagging

* Tag latest commit on branch, this should be the local merge commit
* Check latest local commit, run: `git show HEAD`
* Create tag, run: `tag -s <tag> -m <message>`
* where `tag` is the semver value (should be taken from the release branch name) and `<message>` is a general, short and concise message of the change
* Push release merge and tag to remote, run: `git push --follow-tags`
* Once pushed, go to the Github releases page for the repository in question, which can be found by clicking on the <> Code tab and clicking on Releases on the right hand side:
* Select Tags
* Click on the v0.1.0 tag that you just created
* Choose Create release from tag
* Copy the release name and make human-friendly (capitalise, remove /) to create a release title (e.g. release/0.1.0 -> Release 0.1.0)
* Add relevant release notes, this can be expanded from initial message created against the tag. Advised to use bullet points to list out changes
* Hit Publish release
53 changes: 53 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
.ONESHELL:

.DEFAULT_GOAL := run
TOPICS := fix - feat - docs - style - refactor - test - chore - build


PYTHON = ./.venv/bin/python3
PIP = ./.venv/bin/pip


.PHONY: run test clean check help commit

venv/bin/activate: requirements.txt
python3 -m venv .venv
$(PIP) install -r requirements.txt

venv: venv/bin/activate
. ./.venv/bin/activate

run: venv
$(PYTHON) app.py

test: venv
$(PYTHON) -m pytest

commit:
@echo "Available topics:"
@echo "$(TOPICS)"
@read -p "Enter the topic for the commit: " topic; \
read -p "Enter the commit message: " message; \
echo "$${topic}: $${message}" > commit_message.txt; \
git add .; \
git commit -F commit_message.txt; \
git push; \
rm commit_message.txt

check: venv
$(PIP) install safety
$(PIP) freeze | $(PYTHON) -m safety check --stdin

clean:
@echo "Cleaning up..."
@find . -name "__pycache__" -type d -exec rm -rf {} +
@find . -name ".pytest_cache" -exec rm -rf {} +
@find . -name ".venv" -exec rm -rf {} +

help:
@echo "gmake run - run the application"
@echo "gmake test - run the tests"
@echo "gmake clean - remove all generated files"
@echo "gmake check - check for security vulnerabilities"
@echo "gmake commit - commit changes to git"
@echo "gmake help - display this help"
199 changes: 89 additions & 110 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,135 +1,114 @@
# tdse-accessForce-bids-api
Bids API training project with Python and MongoDB
# API Documentation

# Bid Library
This API provides an endpoint to post a new bid document.

## Contents
## Prerequisites

- [Background](#background)
- [Before working on a bid](#before-working-on-a-bid)
- [Bid phases](#phases)
- [Brief](#brief)
- [Acceptance Criteria](#acceptance-criteria)
- [Iterations](#iterations)
- Python 3.x
- Flask
- Homebrew

## Background
## Running the API

Methods being a consultancy agency to win new work we make to make bids on client tenders.
1. Clone the repository to your local machine:

- A tender is a piece of work that an organisation (potential client) needs an external team to work on or to supplement an existing team
- A bid can comprise of several stages to win a tender, usually there are two phases which comprise of phase 1 and phase 2
```bash
git clone
```
2. Navigate to the root directory of the project:

### Before working on a bid
```bash
cd tdse-accessForce-bids-api
```
3. Install python 3.x if not already installed. You can check if it is installed by running the following command:

Before phase 1, there is time for bidders like Methods to ask questions of the client tender. These questions are open to all those looking to bid on the tender and all questions and answers are available to all bidders on a single tender.
```bash
python3 --version
```
4. Install Makefile if not already installed. You can check if it is installed by running the following command:

This step is a necessary is really important for Methods to understand whether we really want to bid on a particular tender. Some considerations before bidding:
```bash
make --version
```
5. Version 3.81 or higher is required. If you do not have Make installed, you can install it with Homebrew:

- Do we like the project and hence want it?
- Is it good value?
- Will this get us known with a new client and give Methods leverage in future work?
- Is the tender something different that would expand our portfolio?
- Can we do it?
```bash
brew install make
```
6. Run the following command to have all the commands to use the API with Makefile:

### Phases
```bash
gmake help
```
7. Run the following command to start the API:

**Phase 1** compromises of a list of questions set by the tender; in government the scoring system for each question is out of 3, so if there are 6 questions a bidder can achieve a maximum score of 18. The answers to the questions usually have a word limit of 100 or 200 (in this phase).

The client that puts out a tender decides the pass rate in phase 1 to progress to phase 2. The pass rate may not be known until results of all bids are completed for each of the bidders. The list below are common pass criteria you might come across on a bid (remember this can vary from client to client and even within multiple tenders by the same client):

- All questions must have a score greater than 1, (so 2 minimum)
- A minimum overall score, e.g. 14 out of 18
- The 3 highest bids assuming the bids met criteria 1 or/and 2

**Phase 2** is a lot more involved than phase 1, it can comprise of a face to face (or virtual) presentation alongside answers to questions limited to x number of words (limit set by client). These questions will cover team culture and technical solution.

There are usually 3 categories that Methods are scored on and these are weighted by the client. The categories are:

- Technical - questions from presentation or form and results from phase 1
- Culture - questions in phase 2
- Cost (a.k.a. Rate)

The overall score is worked out as a percentage, (out of 100). Whichever bidder scores highest wins the bid and that is the end of the tendering process.

Next steps: Statement of Work (SoW, the contract) is put together by the client, handing over CVs of potential staff Methods are going to supply and agreement on project start dates.
```bash
gmake run
```
8. The API will be available at http://localhost:8080/api/bids

--------------

## Brief

Currently Methods store all the information for tenders and bids in Sharepoint, the way the documents are stored and the information available can vary quite a lot making it hard for the bid team to find good answers to questions and successful bids for reuse. We currently do not store who helped answering questions against a bid and in some cases where Methods have done so it only informs us of their initials.

What intend to build is an API that can store tender/bid information in a structured way to facilitate finding successful bids and high scoring questions.

### Acceptance Criteria

**Must** have:

1. Ability to access all bid data, see list of data below:

- tender title
- tender short description (problem statement)
- client
- date of the tender
- were Methods successful
- what phase did we get to
- how well we did in each of the phases
- any technologies or skills reuired by client tender
- tender questions and Methods answers and the respective scores
- who helped answer a question
- provide links to further information on bids stored in sharepoint
- when was the data last updated
- any skills or technologies listed in the answers to questions

1. Ability to find any bid
1. Ability to add new bids
1. Ability to update a bid that is still in progress
1. Ability to delete a bid and associated
1. Ability to recover deleted bid data within 4 weeks of deletion
1. Ability to filter bids and questions based on success and score
1. Ability to sort bids and questions alphanumerically and page through the results
1. Ability to secure access to changing the data to certain users

**Should** have:
## Accessing API Documentation (Swagger Specification)

1. Ability to search for bids containing particular text
1. Ability to search for questions containing particular text
1. Run the following command to start the API:

**Could** have:

1. Ability to control different user access (permissions) based on roles

- Admin
- Bid writers
- Bid viewers

1. Ability to access this software anywhere in the UK

**Would not** have:

1. Due to size of some answers and the content not being soley text but images, diagrams etc. Methods does not wish to duplicate this information from Sharepoint into a filesystem like AWS S3 or Azure Storage

### Iterations

**Iteration 1** Build API and initial storage system to find, add, update and remove. Steps 1 to 8 from Must section

**Iteration 2** Secure the API to users who need access, based on the "Principle least priviledge principle. Step 9 from Must section

**Iteration 3** Build search engine to allow for a more sophisticated way of finding questions and bids related to your needs. Steps 1 and 2 from Should section

**Iteration 4** Expand on access control to bid library based on roles, users and teams where necessary. Step 1 of Could section

**Iteration 5** Host the bid library to be accessed by users across the country. Step 2 of Could section

**Iteration 6** Build a web app to integrate with the bids API, create user journeys that allow users to find, add and update bid content

--------------
```bash
python app/app.py
```
2. The Swagger Specification will be available at http://localhost:8080/api/docs

**Note:** If this is part of your training, you should look for guidance by your mentor of how to progress this project. Your coach can use the [generic project rest API doc](/training/generic-projects/rest-api/README.md) to setup your initial project that will cover iteration 1.

--------------

Return to the [internal projects](https://github.com/methods/tdse-projects/blob/main/internal/README.md) for additional options and information.
## Installing and running an instance of MongoDB on your local machine (MacOS)

### To install on Windows please see [here](https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-windows/)

1. Install Homebrew if not already installed. You can check if it is installed by running the following command:

```bash
brew --version
```
2. Install MongoDB by running the following commands:

```bash
brew tap mongodb/brew
brew install mongodb-community
```
3. To run MongoDB (i.e. the mongod process) as a macOS service, run:

```bash
brew services start [email protected]
```
4. To verify that MongoDB is running, run:

```bash
brew services list
```
You should see the service `mongodb-community` listed as `started`.
5. Run the following command to stop the MongoDB instance, as needed:

```bash
brew services stop [email protected]
```
6. To begin using MongoDB, connect the MongoDB shell (mongosh) to the running instance. From a new terminal, issue the following:

```bash
mongosh
```
7. To create a new database called `bidsAPI`, run:

```bash
use bidsAPI
```
8. To exit the MongoDB shell, run the following command:

```bash
exit
```
OPTIONAL - Download MongoDB Compass to view the database in a GUI. You can download it from [here](https://www.mongodb.com/try/download/compass)

--------------

Expand Down
Empty file added api/controllers/__init__.py
Empty file.
Loading