-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add trading feature and to-watch or to-play position
* First commit: add back-end * some corrections * trading history screen ok * deletion ok * trading history done * ordering to do and to watch is done * done * add new SQL dump
- Loading branch information
Showing
23 changed files
with
521 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Estimated list of changes in the V4 | ||
|
||
* Front app is no longer included. | ||
* To watch serious and to watch background are merged. | ||
* True REST APIs: | ||
* endpoint are reflecting resources and no longer screens ; | ||
* using HTTP verbs instead of different endpoints for each action. | ||
* Games are no longer duplicated (one entry per platform). We link them to the platforms instead. |
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,53 @@ | ||
""" Trading controller for the GMG project """ | ||
from flask import jsonify, request, render_template, session | ||
from src.repository.trade_repository import TradeRepository | ||
|
||
class TradeController: | ||
""" Trading controller for the GMG project """ | ||
@classmethod | ||
def get_list(cls, mysql): | ||
"""Return the whole trading history.""" | ||
trade_repo = TradeRepository(mysql) | ||
games_list = trade_repo.get_all() | ||
return jsonify( | ||
games=[game.serialize() for game in games_list] | ||
) | ||
|
||
@classmethod | ||
def add(cls, mysql): | ||
"""Add a new trade.""" | ||
if request.method == 'GET': | ||
form = render_template( | ||
'general/trading-history-form.html', | ||
token=session['csrfToken'] | ||
) | ||
|
||
return jsonify(form=form, title="Ajouter une transaction") | ||
|
||
if request.form['_token'] != session['csrfToken']: | ||
return jsonify(), 400 | ||
|
||
game_id = request.form['game_id'] | ||
year = request.form['year'] | ||
month = request.form['month'] | ||
day = request.form['day'] | ||
operation = request.form['type'] | ||
|
||
if game_id == '' or year == '' or month == '' or day == '' or operation == '': | ||
return "Form is incomplete" | ||
|
||
trade_repo = TradeRepository(mysql) | ||
trade_repo.insert(game_id, year, month, day, operation) | ||
|
||
return jsonify(), 200 | ||
|
||
@classmethod | ||
def delete(cls, mysql, entry_id): | ||
"""Delete a trading entry.""" | ||
if request.form['_token'] != session['csrfToken']: | ||
return jsonify(), 400 | ||
|
||
history_repo = TradeRepository(mysql) | ||
history_repo.delete(entry_id) | ||
|
||
return jsonify(), 204 |
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,81 @@ | ||
""" Trading entity for the GMG project """ | ||
import json | ||
|
||
class Trade: | ||
""" This class represent a trading entry, for instance I sell or bought a game """ | ||
def __init__( | ||
self, | ||
entity_id, | ||
game_id, | ||
title, | ||
platform, | ||
year, | ||
month, | ||
day, | ||
operation | ||
): | ||
self.entity_id = entity_id | ||
self.game_id = game_id | ||
self.title = title | ||
self.platform = platform | ||
self.year = year | ||
self.month = month | ||
self.day = day | ||
self.type = operation | ||
|
||
def get_id(self): | ||
"""Return the id entry.""" | ||
|
||
return self.entity_id | ||
|
||
def get_game_id(self): | ||
"""Return the id of the game, for instance "125".""" | ||
|
||
return self.game_id | ||
|
||
def get_title(self): | ||
"""Return the title of the game, for instance "Fifa 98".""" | ||
|
||
return self.title | ||
|
||
def get_platform(self): | ||
"""Platform?""" | ||
|
||
return self.platform | ||
|
||
def get_year(self): | ||
"""Return the year""" | ||
|
||
return self.year | ||
|
||
def get_month(self): | ||
"""Return the month.""" | ||
|
||
return self.month | ||
|
||
def get_day(self): | ||
"""Return the day.""" | ||
|
||
return self.day | ||
|
||
def get_type(self): | ||
"""0: sold, 1: bought""" | ||
|
||
return self.type | ||
|
||
def to_json(self): | ||
"""Jsonify the object""" | ||
return json.dumps(self, default=lambda o: o.__dict__) | ||
|
||
def serialize(self): | ||
"""serialize the object""" | ||
return { | ||
'id': self.entity_id, | ||
'game_id': self.game_id, | ||
'title': self.title, | ||
'platform': self.platform, | ||
'year': self.year, | ||
'month': self.month, | ||
'day': self.day, | ||
'type': self.type | ||
} |
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
Oops, something went wrong.