Skip to content

Commit

Permalink
Fixed create event controller request and added it to header
Browse files Browse the repository at this point in the history
  • Loading branch information
berkaydoner committed Dec 14, 2021
1 parent f0f721d commit 01ff583
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
31 changes: 19 additions & 12 deletions frontend/src/Controllers/EventController.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,36 @@
import {getToken, getUserInfoLoggedIn} from "./AuthInfo";

export function postEvent(params){
export async function postEvent(params) {
let key;
await getToken().then(d => {
key = d
})
const options = {
headers: { 'Content-Type': 'application/json' , "Authorization": getToken()},
headers: {'Content-Type': 'application/json', 'Authorization': 'JWT ' + key},
method: 'POST',
body: JSON.stringify({
owner: getUserInfoLoggedIn().user_id,
content: params.content?params.content:"",
content: params.content ? params.content : "",
title: params.title,
location: params.location,
date: params.date,
duration: params.duration,
sport: params.sport,
min_age: params.min_age?params.min_age:18,
max_age: params.max_age?params.max_age:80,
player_capacity: params.player_capacity?params.player_capacity:2,
spec_capacity: params.spec_capacity?params.spec_capacity:0,
min_skill_level: params.min_skill_level?params.min_skill_level:0,
max_skill_level: params.max_skill_level?params.max_skill_level:0,
min_age: params.min_age ? params.min_age : 18,
max_age: params.max_age ? params.max_age : 80,
player_capacity: params.player_capacity ? params.player_capacity : 2,
spec_capacity: params.spec_capacity ? params.spec_capacity : 0,
min_skill_level: params.min_skill_level ? params.min_skill_level : 0,
max_skill_level: params.max_skill_level ? params.max_skill_level : 0,
latitude: params.latitude,
longitude: params.longitude
})
}
console.log(options)
return fetch("/api/events/",options)
.then(response=>response.json())
.then(r=>{console.log(r); return r})
return fetch("/api/posts/", options)
.then(response => response.json())
.then(r => {
console.log(r);
return r
})
}
2 changes: 1 addition & 1 deletion frontend/src/Views/Login/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default function LoginPage(props){
setState(newState)
}
else{
setHeaders(r.refresh, r.access)
setHeaders(r.access, r.refresh)
getUserInfo(state.username.value).then(r => console.log(r))
navigate("/")
}
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/Views/Shared/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,19 @@ const Header = props => {
/>
</Search>
</Toolbar>

<Button
component={Link} to="/createevent"
color="primary"
variant="outlined"
style={{marginRight:10}}>
Create a new event
</Button>
<Button
component={Link} to="/home"
color="primary"
variant="outlined"
startIcon={<HomeOutlinedIcon />} >
startIcon={<HomeOutlinedIcon />}
style={{marginRight:10}}>
Home
</Button>
<Button
Expand Down

0 comments on commit 01ff583

Please sign in to comment.