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 {
|
export interface IMusic {
|
||||||
idMusic: string;
|
musicId: string;
|
||||||
idUser: string;
|
userId: string;
|
||||||
date: Date;
|
date: Date;
|
||||||
}
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
export interface IPerson {
|
||||||
|
_id: string;
|
||||||
|
name: string;
|
||||||
|
image: string;
|
||||||
|
}
|
@ -1,22 +1,31 @@
|
|||||||
import Music from "./Music";
|
import Music from "./Music";
|
||||||
import { Person } from "./Person";
|
|
||||||
|
|
||||||
export class Spot {
|
export class Spot {
|
||||||
|
private _id: string;
|
||||||
private _user: string;
|
private _user: string;
|
||||||
private _music: Music;
|
private _music: Music;
|
||||||
private _date: Date;
|
private _date: Date;
|
||||||
|
|
||||||
constructor(userId: string, music: Music, date: Date) {
|
constructor(id: string, user: string, music: Music, date: Date) {
|
||||||
this._user = userId;
|
this._id = id;
|
||||||
|
this._user = user;
|
||||||
this._music = music;
|
this._music = music;
|
||||||
this._date = date;
|
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;
|
return this._user;
|
||||||
}
|
}
|
||||||
|
|
||||||
set userSpotifyId(value: string) {
|
set user(value: string) {
|
||||||
this._user = value;
|
this._user = value;
|
||||||
}
|
}
|
||||||
|
|
@ -1,9 +1,49 @@
|
|||||||
import axios from "axios";
|
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
|
//@ts-ignore
|
||||||
return async dispatch => {
|
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 = {
|
export const spotTypes = {
|
||||||
FETCH_SPOT: 'FETCH_SPOT',
|
FETCH_SPOT: 'FETCH_SPOT',
|
||||||
ADD_SPOT_MOCK: 'ADD_SPOT_MOCK',
|
|
||||||
REMOVE_SPOT: 'REMOVE_SPOT'
|
REMOVE_SPOT: 'REMOVE_SPOT'
|
||||||
}
|
}
|
Loading…
Reference in new issue