Skip to content
Snippets Groups Projects
Commit 06a19ba2 authored by aapekaur's avatar aapekaur
Browse files

some issues with db connection

parent 0c481e13
No related branches found
No related tags found
1 merge request!6Datatodb
......@@ -98,7 +98,7 @@ flask_app = create_app()
api = Api(flask_app)
# added auction item resource
api.add_resource(items.AuctionItem, "/auction_item/<id>")
api.add_resource(items.AuctionItem, "/auction_item/<id>", "/auction_item")
@flask_app.route("/server-info")
......@@ -114,7 +114,7 @@ def server_info() -> Response:
database_ping = False
try:
from .db import db # pylint: disable=import-outside-toplevel
database_ping = db.connection.admin.command('ping').get("ok", False) and True
database_ping = db.connection.admin.command('ping').get("ok", False) #and True
except Exception as exc: # pylint: disable=broad-except
logger.warning("Error querying mongodb server: %r", exc,
exc_info=True,
......
......@@ -28,7 +28,9 @@ class AuctionItem (Resource):
item = items.Item()
if not id:
logger.info("retriving item without id!")
query_result = item.get_all()
query_result =item.get_all()
print(query_result)
print(list(query_result))
temp = json.dumps(query_result, default=str)
return temp
......@@ -42,8 +44,11 @@ class AuctionItem (Resource):
def post(self):
print("HERE")
print(request.form)
data = request.get_json()
print(data)
item = items.Item(**data)
item.add()
#json.dump
......
......@@ -293,6 +293,18 @@ const addSubCats = (cat) =>{
}
//Change keys of an object according to the dictionary object argument
const keyTranslate = (dictionary, translateThis) =>{
let ans = {}
console.log(translateThis)
for (let [orig_key, new_key] of Object.entries(dictionary)){
console.log(orig_key, new_key)
ans[new_key]=translateThis.get(orig_key)
}
return ans
}
//Reusable function to add options to select fields
......@@ -327,17 +339,49 @@ const aaFormEventListenersInitializers = ()=>{
//Submit button click
const aadButton = document.getElementById("aadButton")
aadButton.addEventListener('click', (e) => {
aadButton.addEventListener('click', async (e) => {
e.preventDefault()
console.log("Button clicked. TODO: rest...")
let form = e.target.form
let isValid = form.reportValidity()
console.log(form)
//JUST TESTING DELETE LATER
let a =await fetch('/auction_item')
.then((r) =>r.json())
.then((a)=> console.log(a))
//U TO HERE
if (isValid){
console.log("SUBMIT TO BACKEND")
const data = new FormData(form)
console.log("DATA:", data)
const newKeys = {
'aafName': 'name',
'aafCat': 'category',
'aafSubCat': 'subcategory',
'aafStartPrice': 'starting_price',
'aafDesc': 'description'//,
// 'aafContinents': 'area'
}
let dataWithRightKeys = keyTranslate( newKeys, data)
console.log("DATA:", dataWithRightKeys)
// Send auction data to backend.
let newAucReq = {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(dataWithRightKeys)
}
console.log("läh", newAucReq)
let url = "/auction_item"
let response = await fetch(url, newAucReq)
console.log(response)
}
})
......
......@@ -52,3 +52,13 @@ li > div {
li > div:nth-child(1) {
width: 25%;
}
.left {
display: inline-block;
width: 40%;
}
.right {
display: inline-block;
width: 40%;
}
{# Template file is in Jinja syntax:
https://jinja.palletsprojects.com/en/3.1.x/
#}
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="../frontend/styles/style.css" type="text/css" >
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{title}}</title>
</head>
<body>
"{{ url_for('static', filename='styles/style.css') }}"
<h1>NIMI:</h1>
<h2>Auction closes in: <span id="bestbefore"></span></h2>
<div>
<div class="left">
<div>
<span>cat</span> <span>cat</span>
</div>
<div>
<span>Owner:</span> <span>Joku</span>
</div>
</div>
<div class="right">
<h2>Bids:</h2>
<ul>
<li>toka</li>
<li>eka</li>
</ul>
</div>
</div>
<label for="newbid"> Make a bid: </label>
<input type="number" value="0" name="newbid" id="newbid"/>
<!-- Load main frontend script -->
<script type="module" src="{{ url_for('static', filename='mainfront.js') }}" charset="utf-8">
</script>
</body>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment