generated from lucien/api-template
Fix owner ID reference in share purchase logic; clean up comments and add sleep in main execution
This commit is contained in:
parent
9b0985c33c
commit
f351b4c31f
3 changed files with 3 additions and 35 deletions
|
@ -51,7 +51,7 @@ router.post('/buy', async (req, res) => {
|
||||||
|
|
||||||
await addTransaction(connection, price, share[0].owner_id, buyer_id, share_id)
|
await addTransaction(connection, price, share[0].owner_id, buyer_id, share_id)
|
||||||
await setShareOwner(connection, share_id, buyer_id)
|
await setShareOwner(connection, share_id, buyer_id)
|
||||||
if (share[0].owner != -1) {
|
if (share[0].owner_id != -1) {
|
||||||
const seller = await getShareholder(connection, share[0].owner_id)
|
const seller = await getShareholder(connection, share[0].owner_id)
|
||||||
await setShareholderCapital(connection, share[0].owner_id, seller[0].capital + price)
|
await setShareholderCapital(connection, share[0].owner_id, seller[0].capital + price)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,36 +4,22 @@ from random import randint
|
||||||
|
|
||||||
HOST = "http://192.168.200.15/"
|
HOST = "http://192.168.200.15/"
|
||||||
|
|
||||||
"""Affichage des actions mises en vente par une entreprise
|
|
||||||
input :
|
|
||||||
- idComp : Identifiant de l'entreprise
|
|
||||||
"""
|
|
||||||
def getShares(idComp):
|
def getShares(idComp):
|
||||||
url = HOST + 'api/companies/'+idComp+'/shares'
|
url = HOST + 'api/companies/'+idComp+'/shares'
|
||||||
r = requests.get(url)
|
r = requests.get(url)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
"""Création d'une action par une entreprise
|
|
||||||
input :
|
|
||||||
- idComp : identifiant de l'entreprise
|
|
||||||
- price : prix de l'action sur le marché
|
|
||||||
"""
|
|
||||||
def emitShare(idComp, price):
|
def emitShare(idComp, price):
|
||||||
url = HOST + 'api/shares/emit'
|
url = HOST + 'api/shares/emit'
|
||||||
obj={'company_id':idComp,'price':price}
|
obj={'company_id':idComp,'price':price}
|
||||||
r = requests.post(url, json=obj)
|
r = requests.post(url, json=obj)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
"""Affichage des informations d'une enteprise
|
|
||||||
input :
|
|
||||||
- idComp : identifiant de l'entreprise
|
|
||||||
"""
|
|
||||||
def getCompany(idComp):
|
def getCompany(idComp):
|
||||||
url = HOST + 'api/companies/'+idComp
|
url = HOST + 'api/companies/'+idComp
|
||||||
r=requests.get(url)
|
r=requests.get(url)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
"""Affichage les enteprises """
|
|
||||||
def getCompanies():
|
def getCompanies():
|
||||||
url = HOST + 'api/companies/'
|
url = HOST + 'api/companies/'
|
||||||
r=requests.get(url)
|
r=requests.get(url)
|
||||||
|
@ -46,6 +32,7 @@ if __name__ == "__main__":
|
||||||
price = randint(20, 2000)
|
price = randint(20, 2000)
|
||||||
for i in range(randint(0, 4)):
|
for i in range(randint(0, 4)):
|
||||||
emitShare(randint(0, len(companies) - 1), price)
|
emitShare(randint(0, len(companies) - 1), price)
|
||||||
|
sleep(1)
|
||||||
|
|
||||||
sleep(30)
|
sleep(30)
|
||||||
|
|
||||||
|
|
|
@ -4,59 +4,40 @@ from random import randint
|
||||||
|
|
||||||
HOST = "http://192.168.200.15/"
|
HOST = "http://192.168.200.15/"
|
||||||
|
|
||||||
"""Achat d'une action par un actionnaire à une entreprise
|
|
||||||
input :
|
|
||||||
- idBuyer : identifiant de l'actionnaire
|
|
||||||
- idShare : identifiant de l'action
|
|
||||||
"""
|
|
||||||
def buyShare(idBuyer, idShare, price):
|
def buyShare(idBuyer, idShare, price):
|
||||||
url = HOST + 'api/shares/buy'
|
url = HOST + 'api/shares/buy'
|
||||||
obj={'buyer_id':idBuyer,'share_id':idShare, 'price': price}
|
obj={'buyer_id':idBuyer,'share_id':idShare, 'price': price}
|
||||||
r = requests.post(url, json=obj)
|
r = requests.post(url, json=obj)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
"""Affichage les actions possédées par un actionnaire
|
|
||||||
input :
|
|
||||||
- idBuyer : identifiant de l'actionnaire
|
|
||||||
"""
|
|
||||||
def getSharesOf(idBuyer):
|
def getSharesOf(idBuyer):
|
||||||
url = HOST + 'api/shareholders/'+idBuyer+'/shares'
|
url = HOST + 'api/shareholders/'+idBuyer+'/shares'
|
||||||
r = requests.get(url)
|
r = requests.get(url)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
"""Affichage les informations d'une actions
|
|
||||||
input :
|
|
||||||
- idShare : identifiant de l'action
|
|
||||||
"""
|
|
||||||
def getShare(idShare):
|
def getShare(idShare):
|
||||||
url = HOST + 'api/shares/'+idShare
|
url = HOST + 'api/shares/'+idShare
|
||||||
r = requests.get(url)
|
r = requests.get(url)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
"""Affichage les actions en circulation sur le marché (possédées ou en vente) """
|
|
||||||
def getAllShares():
|
def getAllShares():
|
||||||
url = HOST + 'api/shares'
|
url = HOST + 'api/shares'
|
||||||
r = requests.get(url)
|
r = requests.get(url)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
"""Affichage les informations sur un actionnaire
|
|
||||||
input :
|
|
||||||
- idBuyer : identifiant de l'actionnaire
|
|
||||||
"""
|
|
||||||
def getInfoBuyer(idBuyer):
|
def getInfoBuyer(idBuyer):
|
||||||
url = HOST + 'api/shareholders/'+idBuyer
|
url = HOST + 'api/shareholders/'+idBuyer
|
||||||
r=requests.get(url)
|
r=requests.get(url)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
"""Affichage tous les actionnaires """
|
|
||||||
def getAllBuyers():
|
def getAllBuyers():
|
||||||
url = HOST + 'api/shareholders/'
|
url = HOST + 'api/shareholders/'
|
||||||
r=requests.get(url)
|
r=requests.get(url)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
shareholders = getAllBuyers()
|
||||||
while True:
|
while True:
|
||||||
shareholders = getAllBuyers()
|
|
||||||
shares = getAllShares()
|
shares = getAllShares()
|
||||||
|
|
||||||
shareId = randint(0, len(shares) - 1)
|
shareId = randint(0, len(shares) - 1)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue