Enabled Repository
This commit is contained in:
@@ -4,16 +4,25 @@ import API_DTO from '../../DTOs/api.dto';
|
||||
import ReportingRepository from '../../Repositories/ReportingRepository';
|
||||
|
||||
export default class Dashboard extends React.Component<{
|
||||
history: any
|
||||
history: any,
|
||||
location: any
|
||||
}, {
|
||||
dto: API_DTO,
|
||||
ReportingRepository: ReportingRepository
|
||||
}> {
|
||||
constructor(props: any) {
|
||||
super(props);
|
||||
if (props.location.state.dto !== undefined) {
|
||||
if (this.props.location.state.dto !== undefined) {
|
||||
// If the state exists being routed from /, fill in Dashboard State.
|
||||
this.setState({ dto: props.location.state.dto });
|
||||
const DTO = new API_DTO();
|
||||
DTO.setApiLink(this.props.location.state.dto.API_Link);
|
||||
DTO.setApiToken(this.props.location.state.dto.API_Token);
|
||||
DTO.setFirstDate(localStorage.getItem("First_Date") || "");
|
||||
DTO.setSecondDate(localStorage.getItem("Second_Date") || "");
|
||||
this.state = {
|
||||
dto: DTO,
|
||||
ReportingRepository: new ReportingRepository(DTO)
|
||||
}
|
||||
} else if (localStorage.getItem("APILink") !== null &&
|
||||
localStorage.getItem("AccessToken") !== null) {
|
||||
// Check if localStorage has valid items, if this is the case, we can use those.
|
||||
@@ -21,11 +30,17 @@ export default class Dashboard extends React.Component<{
|
||||
const DTO = new API_DTO();
|
||||
DTO.setApiLink(localStorage.getItem("APILink"));
|
||||
DTO.setApiToken(localStorage.getItem("AccessToken"));
|
||||
this.setState({ dto: DTO });
|
||||
DTO.setFirstDate(localStorage.getItem("First_Date") || "");
|
||||
DTO.setSecondDate(localStorage.getItem("Second_Date") || "");
|
||||
this.state = {
|
||||
dto: DTO,
|
||||
ReportingRepository: new ReportingRepository(DTO)
|
||||
}
|
||||
} else {
|
||||
// Route back to / if neither is the case.
|
||||
this.props.history.push('/');
|
||||
}
|
||||
|
||||
this.checkFirstDate = this.checkFirstDate.bind(this);
|
||||
this.checkSecondDate = this.checkSecondDate.bind(this);
|
||||
this.getItemsFromApi = this.getItemsFromApi.bind(this);
|
||||
@@ -41,6 +56,7 @@ export default class Dashboard extends React.Component<{
|
||||
|
||||
getItemsFromApi() {
|
||||
// TODO: Connect to ReportingRepository.
|
||||
console.log(this.state.ReportingRepository.Read(this.state.dto));
|
||||
}
|
||||
|
||||
render () {
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
export default interface IDTO { };
|
||||
+1
-3
@@ -1,6 +1,4 @@
|
||||
import IDTO from './IDTO';
|
||||
|
||||
export default class API_DTO implements IDTO {
|
||||
export default class API_DTO {
|
||||
API_Link: string;
|
||||
API_Token: string;
|
||||
First_Date: string;
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
export default interface IRepository {
|
||||
Create(t: any): any;
|
||||
Read(t: any): any;
|
||||
Update(t: any): any;
|
||||
Delete(t: any): any;
|
||||
}
|
||||
@@ -1,15 +1,38 @@
|
||||
import IRepository from './IRepository';
|
||||
import API_DTO from '../DTOs/api.dto';
|
||||
import axios, { AxiosInstance } from 'axios';
|
||||
|
||||
export default class ReportingRepository {
|
||||
private instance: AxiosInstance | undefined;
|
||||
|
||||
constructor(t: API_DTO) {
|
||||
this.instance = axios.create({
|
||||
baseURL: t.getApiLink(),
|
||||
headers: {
|
||||
'Authorization': 'Bearer ' + t.getApiToken(),
|
||||
'Access-Control-Allow-Origin': '*'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export default class ReportingRepository implements IRepository {
|
||||
Create(_t: any) {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
Read(_t: any) {
|
||||
throw new Error("Method not implemented.");
|
||||
|
||||
Read(_t: API_DTO) {
|
||||
if (this.instance === undefined)
|
||||
throw new Error("[ReportingRepository]: Please initiate the constructor first before calling a subfunction.");
|
||||
this.instance.get("api/reporting/v1/rooms/84e0fefa-5675-11e7-a349-00163efdd8db/chat-stats/daily/", {
|
||||
params: { "start_date": _t.getFirstDate(), "end_date": _t.getFirstDate() }
|
||||
})
|
||||
.then((res) => {
|
||||
return res.data;
|
||||
});
|
||||
}
|
||||
|
||||
Update(_t: any) {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
Delete(_t: any) {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user