Skip to content

Commit

Permalink
enroll working
Browse files Browse the repository at this point in the history
  • Loading branch information
jap19015 committed Nov 25, 2023
1 parent 4f3aba7 commit a19a2c5
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 69 deletions.
51 changes: 40 additions & 11 deletions src/views/ClassSearch.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<template>
<div>
<!-- Search Form -->
<section class="search-form">
<div v-if="isAuthenticated">
<p>Name: {{ parsedName }}</p>
<p>Email: {{ parsedEmail }}</p>
</div>

<!-- Search Form -->
<section class="search-form">
<h3>Class Search</h3>
<form @submit.prevent="searchClasses">
<label for="courseName">Course Name:</label>
Expand Down Expand Up @@ -50,17 +53,31 @@ import { useAuth0 } from '@auth0/auth0-vue';
import axios from 'axios';
export default {
setup() {
const { user, isAuthenticated } = useAuth0();
const userJsonString = JSON.stringify(user, null, 2);
const parsedUser = JSON.parse(userJsonString);
const parsedName = parsedUser._value.name;
const parsedEmail = parsedUser._value.email;
return {
isAuthenticated,
parsedName,
parsedEmail,
};
},
data() {
return {
courseName: '',
professor: '',
courseID: '',
results: null
results: null,
};
},
methods: {
searchClasses() {
const url = `https://8dbuywnj95.execute-api.us-east-1.amazonaws.com/Final_stage_course/search?name=${this.courseName}`;
let url = `https://8dbuywnj95.execute-api.us-east-1.amazonaws.com/Final_stage_course/search?name=${this.courseName}`;
if (this.professor) {
url += `&professor=${this.professor}`;
Expand All @@ -71,24 +88,36 @@ export default {
}
fetch(url)
.then(response => response.json())
.then(data => {
.then((response) => response.json())
.then((data) => {
this.results = data;
console.log(this.results.name.S);
})
.catch(error => {
.catch((error) => {
console.error('Error:', error);
});
},
formatValue(value) {
if (value && value.S) return value.S;
if (value && value.N) return value.N;
// Add other types here if needed
return value || 'N/A';
},
enrollClass() {
},
},
};
const courseData = {
name: this.parsedName,
courseName: this.results.name.S,
};
axios.post('https://xb55sqy2kf.execute-api.us-east-1.amazonaws.com/prod/enroll', courseData)
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(error);
});
},
}
}
</script>

<style>
Expand Down
103 changes: 45 additions & 58 deletions src/views/Profile.vue
Original file line number Diff line number Diff line change
@@ -1,60 +1,47 @@
<template>
<div>
<h2>User Profile</h2>
<div v-if="isAuthenticated">
<p>Name: {{ parsedName }}</p>
<p>Email: {{ parsedEmail }}</p>
<button @click="sendUserData">Send User Data</button>
</div>
<div>
<h2>User Profile</h2>
<div v-if="isAuthenticated">
<p>Name: {{ parsedName }}</p>
<p>Email: {{ parsedEmail }}</p>
<button @click="sendUserData">Send User Data</button>
</div>
</template>

<script>
import { useAuth0 } from '@auth0/auth0-vue';
import axios from 'axios';
export default {
setup() {
const { user, isAuthenticated } = useAuth0();
// Save user data as a JSON string
const userJsonString = JSON.stringify(user, null, 2);
// Parse userJsonString to get name and email
const parsedUser = JSON.parse(userJsonString);
const parsedName = parsedUser._value.name; // Access name from _value
const parsedEmail = parsedUser._value.email; // Access email from _value
// Print name and email to the console
console.log('Parsed Name:', parsedName);
console.log('Parsed Email:', parsedEmail);
// Function to send user data via POST request
const sendUserData = async () => {
try {
// Send POST request to the specified endpoint
const response = await axios.post('https://5ctsolryl1.execute-api.us-east-1.amazonaws.com/prod/create', {
name: parsedName,
email: parsedEmail
});
// Log the response
console.log('POST Request Response:', response.data);
} catch (error) {
// Log any errors
console.error('Error sending POST request:', error);
}
};
return {
user,
userJsonString,
isAuthenticated,
parsedName,
parsedEmail,
sendUserData
};
}
};
</script>

</div>
</template>

<script>
import { useAuth0 } from '@auth0/auth0-vue';
import axios from 'axios';
export default {
setup() {
const { user, isAuthenticated } = useAuth0();
console.log(user);
const userJsonString = JSON.stringify(user, null, 2);
console.log(userJsonString);
const parsedUser = JSON.parse(userJsonString);
const parsedName = parsedUser._value.name;
const parsedEmail = parsedUser._value.email;
const sendUserData = async () => {
try {
const response = await axios.post('https://5ctsolryl1.execute-api.us-east-1.amazonaws.com/prod/create', {
name: parsedName,
email: parsedEmail
});
console.log('POST Request Response:', response.data);
} catch (error) {
console.error('Error sending POST request:', error);
}
};
return {
isAuthenticated,
parsedName,
parsedEmail,
sendUserData
};
}
};
</script>

0 comments on commit a19a2c5

Please sign in to comment.