Skip to content

Commit

Permalink
fix: use environmnet files
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoblanc committed Aug 1, 2021
1 parent 795c07d commit 5092df6
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 69 deletions.
75 changes: 37 additions & 38 deletions src/app/provider/content/youtube.service.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import { Injectable } from '@angular/core';
import { Observable, of } from 'rxjs';
import { map } from 'rxjs/operators';
import { ICategories } from '../../models/categories/icategories';
import { ItemVideo } from '../../models/content/youtube/item-video';
import { Page } from '../../models/core/page';
import { HttpService } from '../helper/http.service';
import { MetaMediaService } from '../meta-media/meta-media.service';
import { ContentService } from './content.service';
import { Injectable } from "@angular/core";
import { Observable, of } from "rxjs";
import { map } from "rxjs/operators";
import { environment } from "../../../environments/environment";
import { ICategories } from "../../models/categories/icategories";
import { ItemVideo } from "../../models/content/youtube/item-video";
import { Page } from "../../models/core/page";
import { HttpService } from "../helper/http.service";
import { MetaMediaService } from "../meta-media/meta-media.service";
import { ContentService } from "./content.service";

@Injectable({
providedIn: 'root'
providedIn: "root",
})
export class YoutubeService extends ContentService<ItemVideo> {


private static BASE_URL = 'https://www.athena-app.fr/';
// private static BASE_URL = 'http://localhost:3000/';
private static CONTENT = 'content/';
private static MEDIA_KEY = 'mediakey/';
private static PAGE = 'page/';
private static BASE_URL = environment.apiUrl;
private static CONTENT = "content/";
private static MEDIA_KEY = "mediakey/";
private static PAGE = "page/";

constructor(private http: HttpService, metaMediaService: MetaMediaService) {
super(metaMediaService);
Expand All @@ -33,65 +31,66 @@ export class YoutubeService extends ContentService<ItemVideo> {
return this.findServerContentById(id);
}


findServerContentById(id: number): Observable<ItemVideo> {
const url = this.creatUrl(id);
return this.http.get(url)
.pipe(map((data: any) => {
return this.http.get(url).pipe(
map((data: any) => {
return new ItemVideo(data);
}));
})
);
}


getContents(): Observable<Page<ItemVideo>> {
this.page = new Page<ItemVideo>();
this.page.next = 0;
const url = this.creatUrl();
return this.http.get(url)
.pipe(map((page: Page<ItemVideo>) => {
return this.http.get(url).pipe(
map((page: Page<ItemVideo>) => {
this.page = page;
this.page.objects = this.page.objects.map((itemVideo) => new ItemVideo(itemVideo));
this.page.objects = this.page.objects.map(
(itemVideo) => new ItemVideo(itemVideo)
);
return this.page;
}));
})
);
}

loadMore(): Observable<Page<ItemVideo>> {
const url = this.creatUrl();
return this.http.get(url)
.pipe(map((page: Page<ItemVideo>) => {
return this.http.get(url).pipe(
map((page: Page<ItemVideo>) => {
this.page.objects = [...this.page.objects, ...page.objects];
this.page.next = page.next;
this.page.count = page.count;
return this.page;
}));
})
);
}




private creatUrl(idPart?: number) {
let url = YoutubeService.BASE_URL +
YoutubeService.CONTENT;
let url = YoutubeService.BASE_URL + YoutubeService.CONTENT;
if (idPart) {
// Si on cherche par id
// ex: /content/11
url += idPart;
} else if (this.page && this.page.next !== undefined) {
// SI on cherche par media key
// ex: /content/mediakey/osonscauser
url += YoutubeService.MEDIA_KEY + this.metaMediaService.currentMetaMedia.key + '/';
url +=
YoutubeService.MEDIA_KEY +
this.metaMediaService.currentMetaMedia.key +
"/";
url += YoutubeService.PAGE + this.page.next;
} else {
// SI on cherche par media key
// ex: /content/mediakey/osonscauser
url += YoutubeService.MEDIA_KEY + this.metaMediaService.currentMetaMedia.key;
url +=
YoutubeService.MEDIA_KEY + this.metaMediaService.currentMetaMedia.key;
}
return url;
}

getNotificationCategories(): Observable<ICategories[]> {
return of([]);
}


}
49 changes: 25 additions & 24 deletions src/app/provider/github.service.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { Issue } from '../models/github/github';
import { HttpService } from './helper/http.service';
import { Injectable } from "@angular/core";
import { Observable } from "rxjs";
import { environment } from "../../environments/environment.prod";
import { Issue } from "../models/github/github";
import { HttpService } from "./helper/http.service";

@Injectable({
providedIn: 'root'
providedIn: "root",
})
export class GithubService {
public static BASE_ATHENA_URL = environment.apiUrl;
private static BASE_GITHUB_URL = "https://api.github.com/repos/";
private static ATHENA = "hugoblanc/Athena/";
private static ISSUE = "issues";
private static CLAP = "/clap";

public static BASE_ATHENA_URL = 'https://www.athena-app.fr/github/';
private static BASE_GITHUB_URL = 'https://api.github.com/repos/';
private static ATHENA = 'hugoblanc/Athena/';
private static ISSUE = 'issues';
private static CLAP = '/clap';
private static FULL_GITHUB_URL =
GithubService.BASE_GITHUB_URL + GithubService.ATHENA + GithubService.ISSUE;

private static FULL_GITHUB_URL = GithubService.BASE_GITHUB_URL + GithubService.ATHENA + GithubService.ISSUE;

constructor(public http: HttpService) {

}
constructor(public http: HttpService) {}

getIssueByLabel(label: string): Observable<Issue[]> {
return this.http.get(GithubService.FULL_GITHUB_URL + `?labels=${label}`);
}


getIssueByNumber(issueNumber: number): Observable<Issue> {
return this.http.get(GithubService.FULL_GITHUB_URL + '/' + issueNumber);
return this.http.get(GithubService.FULL_GITHUB_URL + "/" + issueNumber);
}


postIssue(issue: Issue): Observable<Issue> {
return this.http.post(GithubService.BASE_ATHENA_URL + GithubService.ISSUE, issue);
return this.http.post(
GithubService.BASE_ATHENA_URL + GithubService.ISSUE,
issue
);
}


postClapComment(issue: Issue): Observable<Issue> {

const url = GithubService.BASE_ATHENA_URL
+ GithubService.ISSUE + '/' + issue.number
+ GithubService.CLAP;
const url =
GithubService.BASE_ATHENA_URL +
GithubService.ISSUE +
"/" +
issue.number +
GithubService.CLAP;

return this.http.post(url, {});
}
Expand Down
3 changes: 2 additions & 1 deletion src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const environment = {
production: true
production: true,
apiUrl: "https://www.athena-app.fr/",
};
9 changes: 3 additions & 6 deletions src/environments/environment.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// This file can be replaced during build by using the `fileReplacements` array.
// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
// The list of file replacements can be found in `angular.json`.

export const environment = {
production: false
production: false,
apiUrl: "http://localhost:3000/",
};

/*
Expand All @@ -13,4 +10,4 @@ export const environment = {
* This import should be commented out in production mode because it will have a negative impact
* on performance if an error is thrown.
*/
// import 'zone.js/dist/zone-error'; // Included with Angular CLI.
import "zone.js/dist/zone-error"; // Included with Angular CLI.

0 comments on commit 5092df6

Please sign in to comment.