Skip to content

Commit

Permalink
Update github repos
Browse files Browse the repository at this point in the history
  • Loading branch information
miladsoft committed Sep 18, 2023
1 parent 6acc3fa commit b495f51
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
25 changes: 21 additions & 4 deletions src/app/core/services/profile.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HttpClient, HttpHeaders } from '@angular/common/http'

import { HttpError } from './api.service';
import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment';

Expand All @@ -16,12 +17,28 @@ export class ProfileService {
console.log('service is now ready');
}

getUser() {
return this.http.get("https://api.github.com/users/" + this.username + "?client_id=" + this.clientId + "&client_secret=" + this.clientSecret);
async download(url: string, options = {}) {
const response = await fetch(url, options);
const json = await response.json();

if (response.status !== 200) {
if (json && json.status) {
throw new HttpError(json.status, url, JSON.stringify(json));
} else {
throw new HttpError(response.status, url, response.statusText);
}
}

return json;
}


async getUser() {
return await this.download("https://api.github.com/users/" + this.username + "?client_id=" + this.clientId + "&client_secret=" + this.clientSecret);
}

getUserRepos() {
return this.http.get('https://api.github.com/users/' + this.username + '/repos'+ "?client_id=" + this.clientId + "&client_secret=" + this.clientSecret +"&per_page=1000");
async getUserRepos() {
return await this.download('https://api.github.com/users/' + this.username + '/repos'+ "?client_id=" + this.clientId + "&client_secret=" + this.clientSecret +"&per_page=1000");
}

searchrepos() {
Expand Down
4 changes: 2 additions & 2 deletions src/app/features/github/github-page/github.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="mb-10">
<mat-card class="mb-10">
<!-- <mat-card class="mb-10">
<mat-card-header>
<img mat-card-avatar src="{{user.avatar_url}}" alt="{{user.login}}">
Expand All @@ -13,7 +13,7 @@
</mat-card-content>
<mat-card-actions align="end" class="gitlogo">
</mat-card-actions>
</mat-card>
</mat-card> -->

<div class="flex-container">

Expand Down
13 changes: 4 additions & 9 deletions src/app/features/github/github-page/github.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,13 @@ export class GithubPageComponent implements OnInit {
}


findUser () {
async findUser () {
this.profileService.UpdateUser("block-core");

this.profileService.getUser().subscribe(user => {
console.log(user);
this.user = user;
});
this.user = await this.profileService.getUser();

this.profileService.getUserRepos().subscribe(repos => {
console.log(repos);
this.userRepos = repos;
})
this.userRepos = await this.profileService.getUserRepos();

}

ngOnInit() {
Expand Down
2 changes: 1 addition & 1 deletion src/app/features/github/github.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { SharedModule } from '../../shared/shared.module';
@NgModule({
declarations: [GithubPageComponent],
imports: [
CommonModule,
CommonModule,
SharedModule,
GithubRoutingModule,
FlexLayoutModule
Expand Down

0 comments on commit b495f51

Please sign in to comment.