diff --git a/src/Services/AllApiCalls.js b/src/Services/AllApiCalls.js new file mode 100644 index 0000000..f1e41e0 --- /dev/null +++ b/src/Services/AllApiCalls.js @@ -0,0 +1,14 @@ +import GetApis from "@/Services/GetApis.js"; +import PutApis from "@/Services/PutApis.js"; +export default { + mixins: [GetApis, PutApis], + data() { + return { + + } + }, + methods: { + + + }, +} \ No newline at end of file diff --git a/src/Services/ApiCalls.js b/src/Services/ApiCalls.js new file mode 100644 index 0000000..d70d284 --- /dev/null +++ b/src/Services/ApiCalls.js @@ -0,0 +1,195 @@ +import http from "@/Services/http.js"; +import Rules from "@/pages/Common/rules.js" +export default { + mixins: [Rules], + data() { + return { + + // LOADER + showLoader: false, + loading: false, + // SNACKBAR + snackbar: false, + snackbarColor: '', + text: '', + timeout: 4000, + y: "top", + x: "right", + mode: "", + + // PAGINATION + size: 10, + elements: "", + pageCount: "", + pageNumber: 0 + + } + }, + methods: { + // SNACKBAR + seeSnackbar(message, color) { + this.text = message; + this.showLoader = false; + this.snackbarColor = color; + this.snackbar = true; + }, + + // SET PAGINATION + setPagination(response) { + this.elements = response.data.totalElements; + var l = this.elements; + var s = this.size; + var floor = (l / s); + this.pageCount = Math.floor(floor); + if (this.pageCount == floor) { + this.pageCount -= 1 + } + this.showLoader = false; + this.loading = false; + }, + + generateError(error) { + var customError + const errorNo = error.response.status + // console.log("satus code errorNo", errorNo) + switch (errorNo) { + case 400: + let er = error + if (er.response.data.error) { + customError = error.response.data.error + } + if (er.response.data.errorMessage) { + customError = error.response.data.errorMessage + } + if (er.response.data.message) { + customError = error.response.data.message + } + return customError + break; + case 401: + customError = "Session expired" + return customError + break; + case 404: + customError = error.response.data.errorMessage + return customError + break; + case 409: + customError = error.response.data.errorMessage + return customError + break; + case 500: + customError = error.response.data.message + return customError + break; + default: + customError = "unknown error" + return customError + } + + }, + + // GET + getMethod(url, params) { + this.showLoader = true + return http() + .get(url, { + params: params, + + headers: { + // headers: { Authorization: "Bearer " + this.token } + } + }) + .then(response => { + this.showLoader = false + return response + }) + .catch(error => { + this.showLoader = false + // console.log("error in getMethod = ", error.response) + const message = this.generateError(error) + if (message == "Session expired") { + this.$store.dispatch("setToken", null); + this.$router.push({ + name: 'Login' + }); + } else { + throw new Error(message); + } + + }); + }, + + // POST + postMethod(url, payload) { + this.showLoader = true + return http() + .post(url, payload, { + // headers: { Authorization: "Bearer " + this.token } + }) + .then(response => { + this.showLoader = false + return response + }) + .catch(error => { + this.showLoader = false + console.log("error in postMethod = ", error.response) + const message = this.generateError(error) + if (message == "Session expired") { + this.$store.dispatch("setToken", null); + this.$router.push({ + name: 'Login' + }); + } else { + throw new Error(message); + } + + }); + }, + + // PUT + putMethod(url, payload) { + return http() + .put(url, payload, { + // headers: { + // // Authorization: 'Bearer ' + this.token + // } + }) + .then(response => { + return response + }) + .catch(error => { + console.log("error in putMethod = ", error.response) + const message = this.generateError(error) + if (message == "Session expired") { + this.$store.dispatch("setToken", null); + this.$router.push({ + name: 'Login' + }); + } else { + throw new Error(message); + } + + }) + } + + }, + computed: { + displayedPageNumber() { + return this.pageNumber + 1; + }, + // managerIsADMIN_VIEW: { + // get() { + // if (this.$store.state.roleName == "ADMIN_VIEW") { + // return true; + // } else { + // return false + // } + // }, + // set(newValue) { + // this.managerIsADMIN_VIEW = newValue; + // } + + // } + }, +} \ No newline at end of file diff --git a/src/Services/GetApis.js b/src/Services/GetApis.js new file mode 100644 index 0000000..d4039ea --- /dev/null +++ b/src/Services/GetApis.js @@ -0,0 +1,40 @@ +import ApiCalls from "@/Services/ApiCalls.js"; +export default { + mixins: [ApiCalls], + data() { + return { + courseData: [], + + + } + }, + methods: { + /* getParticularCourseDetail */ + async getParticularCourseDetail(courseId) { + + try { + let response = await this.getMethod("/getParticularCourseDetail", { + courseId: courseId + }) + return response + } catch (error) { + console.log("error in getParticularCourseDetail - ", error.message) + } + }, + + /* getStudentCourses - to get courseData */ + async getStudentCourses(params) { + try { + let response = await this.getMethod("/getStudentCourses", { + classId: params.classId, + studentId: params.studentId + }) + this.courseData = response.data.data; + console.log("coursesData - ", this.courseData) + } catch (error) { + console.log("error in getStudentCourses - ", error.message) + } + } + + }, +} \ No newline at end of file diff --git a/src/Services/PutApis.js b/src/Services/PutApis.js new file mode 100644 index 0000000..ad72e42 --- /dev/null +++ b/src/Services/PutApis.js @@ -0,0 +1,14 @@ +import ApiCalls from "@/Services/ApiCalls.js"; +export default { + mixins: [ApiCalls], + data() { + return { + + } + }, + methods: { + + + + }, +} \ No newline at end of file diff --git a/src/components/pageHeader/AppToolbar.vue b/src/components/pageHeader/AppToolbar.vue index 2d6b3ee..5582e58 100644 --- a/src/components/pageHeader/AppToolbar.vue +++ b/src/components/pageHeader/AppToolbar.vue @@ -1,5 +1,5 @@