Skip to content

Commit

Permalink
[feat]: change api services endpoints to map with refactored backend
Browse files Browse the repository at this point in the history
  • Loading branch information
llucasspot committed Jan 23, 2024
1 parent c08b656 commit a7090dd
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
4 changes: 1 addition & 3 deletions expo-boomboomapp/src/api/MatchApiService/MatchApiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ export class MatchApiService extends ApiService implements MatchApiServiceI {
@inject(ServiceInterface.ErrorService)
protected errorService: ErrorService,
) {
super("matches", storageService, configurationService, errorService);
super("users", storageService, configurationService, errorService);
}

async getProfiles(): Promise<StackProfileI[]> {
const res = await this.apiRequester.get<StackProfileI[]>("/");
console.log(res.data[0].user);
console.log(res.data[0].songs);
return res.data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class ProfileApiService
@inject(ServiceInterface.ErrorService)
protected errorService: ErrorService,
) {
super("profile", storageService, configurationService, errorService);
super("auth/profile", storageService, configurationService, errorService);
}

async createProfile(createProfileBody: CreateProfileBody) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type CreateProfileBody = {
dateOfBirth: string;
description: string;
preferedGenderId: Gender;
genderId: Gender;
trackIds: string[];
name: string;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class SpotifyApiService
}

async fetchTop5Tracks() {
const res = await this.apiRequester.get<Track[]>("/tracks");
const res = await this.apiRequester.get<Track[]>("/top-five-tracks");
return res.data;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,16 @@ export default function FavoriteSongs({

setStepperLayoutCallback(async () => {
try {
await profileApiService.uploadAvatar(user.profilePicture.uri as string);
await profileApiService.createProfile({
dateOfBirth: user.dateOfBirth,
description: user.description,
preferedGenderId: user.gender,
// TODO add genderId in form
genderId: user.gender,
trackIds: mySongs.map((song) => song.trackId),
name: user.fullName,
});
await profileApiService.uploadAvatar(user.profilePicture.uri as string);
navigation.navigate(RegisterStackScreen.WELCOME_SCREEN);
} catch (err) {
// TODO handle error better
Expand Down
32 changes: 29 additions & 3 deletions expo-boomboomapp/src/services/StorageService/StorageService.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
import AsyncStorage from "@react-native-async-storage/async-storage";
import { singleton } from "tsyringe";
import { inject, singleton } from "tsyringe";

import LocalStorageItem from "./LocalStorageItem";
import ServiceInterface from "../../tsyringe/ServiceInterface";
import { Token } from "../../utils/sessionUtils";
import ConfigurationService from "../ConfigurationService/ConfigurationService";
import { GenericService } from "../GenericService";
import { SupportedLanguages } from "../LanguageService/LanguageServiceI";

@singleton()
export default class StorageService {
export default class StorageService extends GenericService {
constructor(
@inject(ServiceInterface.ConfigurationService)
private configurationService: ConfigurationService,
) {
super();
if (this.configurationService.isAppInDebugMode()) {
this.getAuthenticateToken()
.then((token) => {
this.logger.debug("authToken : ", token);
})
.catch(this.logger.error);
}
}

private async logAuthToken(_token: string) {
if (!this.configurationService.isAppInDebugMode()) {
return;
}
const token = _token ?? (await this.getAuthenticateToken());
this.logger.debug("authToken : ", token);
}

getAuthenticateToken(): Promise<Token | null> {
return AsyncStorage.getItem(LocalStorageItem.BEARER_TOKEN);
}

setAuthenticateToken(token: Token): Promise<void> {
async setAuthenticateToken(token: Token): Promise<void> {
await this.logAuthToken(token);
return AsyncStorage.setItem(LocalStorageItem.BEARER_TOKEN, token);
}

Expand Down

0 comments on commit a7090dd

Please sign in to comment.