29 lines
866 B
TypeScript
29 lines
866 B
TypeScript
import { Injectable } from '@angular/core';
|
|
import { Observable } from 'rxjs';
|
|
|
|
import { ApiService } from '@services';
|
|
import { Profile } from '@models';
|
|
import { map } from 'rxjs/operators';
|
|
|
|
@Injectable({ providedIn: 'root' })
|
|
export class ProfilesService {
|
|
private _apiVersion = '/v2';
|
|
constructor(
|
|
private apiService: ApiService
|
|
) { }
|
|
|
|
get(username: string): Observable<Profile> {
|
|
return this.apiService.get(`${this._apiVersion}/profiles/${username}`)
|
|
.pipe(map((data: { profile: Profile }) => data.profile));
|
|
}
|
|
|
|
follow(username: string): Observable<Profile> {
|
|
return this.apiService.post(`${this._apiVersion}/profiles/${username}/follow`);
|
|
}
|
|
|
|
unfollow(username: string): Observable<Profile> {
|
|
return this.apiService.delete(`${this._apiVersion}/profiles/${username}/follow`);
|
|
}
|
|
|
|
}
|