add a new API route and getSpots ✅
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
f761028031
commit
bc612f98dd
@ -1,5 +1,5 @@
|
||||
export interface IMusic {
|
||||
idMusic: string;
|
||||
idUser: string;
|
||||
musicId: string;
|
||||
userId: string;
|
||||
date: Date;
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
export interface IPerson {
|
||||
_id: string;
|
||||
name: string;
|
||||
image: string;
|
||||
}
|
@ -1,22 +1,31 @@
|
||||
import Music from "./Music";
|
||||
import { Person } from "./Person";
|
||||
|
||||
export class Spot {
|
||||
private _id: string;
|
||||
private _user: string;
|
||||
private _music: Music;
|
||||
private _date: Date;
|
||||
|
||||
constructor(userId: string, music: Music, date: Date) {
|
||||
this._user = userId;
|
||||
constructor(id: string, user: string, music: Music, date: Date) {
|
||||
this._id = id;
|
||||
this._user = user;
|
||||
this._music = music;
|
||||
this._date = date;
|
||||
}
|
||||
|
||||
get userSpotifyId(): string {
|
||||
get id(): string {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
set id(value: string) {
|
||||
this._id = value;
|
||||
}
|
||||
|
||||
get user(): string {
|
||||
return this._user;
|
||||
}
|
||||
|
||||
set userSpotifyId(value: string) {
|
||||
set user(value: string) {
|
||||
this._user = value;
|
||||
}
|
||||
|
@ -1,9 +1,49 @@
|
||||
import axios from "axios";
|
||||
const key = 'userToken';
|
||||
import configs from "../../constants/config";
|
||||
import * as SecureStore from 'expo-secure-store';
|
||||
import qs from "qs";
|
||||
import { setSpotList } from "../actions/spotActions";
|
||||
import { MusicServiceProvider } from "../../models/MusicServiceProvider";
|
||||
import { SpotMapper } from "../../models/mapper/SpotMapper";
|
||||
|
||||
export const getSpotList = () => {
|
||||
export const getSpotList = (longitude: string, latitude: string, music: string) => {
|
||||
//@ts-ignore
|
||||
return async dispatch => {
|
||||
try {
|
||||
let token: string | null = await SecureStore.getItemAsync(configs.key);
|
||||
const body: Record<string, string | boolean | number | (string | boolean | number)[]> = {
|
||||
longitude: longitude,
|
||||
latitude: latitude,
|
||||
currentMusic: music
|
||||
}
|
||||
const resp = await axios({
|
||||
url: configs.API_URL + '/user/nextTo?' + qs.stringify(body),
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
const musicIds = resp.data.data.map((music: any) => music.musicId);
|
||||
const musics = await MusicServiceProvider.musicService.getMusicsWithIds(musicIds);
|
||||
const result = resp.data.data
|
||||
.filter((spot: any) => musics.some((m: any) => m.id === spot.musicId))
|
||||
.map((spot: any) => {
|
||||
const matchingMusic = musics.find((m: any) => m.id === spot.musicId);
|
||||
return {
|
||||
...spot,
|
||||
music: matchingMusic,
|
||||
};
|
||||
});
|
||||
dispatch(setSpotList(result.map((item: any) => SpotMapper.toModel(item))));
|
||||
|
||||
} catch (error: any) {
|
||||
switch (error.response.status) {
|
||||
default:
|
||||
console.error("Error retrieving spots : " + error);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
export const spotTypes = {
|
||||
FETCH_SPOT: 'FETCH_SPOT',
|
||||
ADD_SPOT_MOCK: 'ADD_SPOT_MOCK',
|
||||
REMOVE_SPOT: 'REMOVE_SPOT'
|
||||
}
|
Loading…
Reference in new issue