From 494677881ac50438af19009b5996cb8548026d61 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 21 May 2021 19:33:48 -0400 Subject: Add MomentTagType, Add logic to fetch tags for each moment --- src/services/MomentService.ts | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src/services/MomentService.ts') diff --git a/src/services/MomentService.ts b/src/services/MomentService.ts index 2354d18e..a26a1abb 100644 --- a/src/services/MomentService.ts +++ b/src/services/MomentService.ts @@ -1,7 +1,11 @@ import AsyncStorage from '@react-native-community/async-storage'; import RNFetchBlob from 'rn-fetch-blob'; -import {MOMENTS_ENDPOINT, MOMENT_THUMBNAIL_ENDPOINT} from '../constants'; -import {MomentType} from '../types'; +import { + MOMENTS_ENDPOINT, + MOMENT_TAGS_ENDPOINT, + MOMENT_THUMBNAIL_ENDPOINT, +} from '../constants'; +import {MomentTagType, MomentType} from '../types'; import {checkImageUploadStatus} from '../utils'; export const postMoment: ( @@ -116,3 +120,25 @@ export const loadMomentThumbnail = async (momentId: string) => { return undefined; } }; + +export const loadMomentTags = async (moment_id: string) => { + try { + const token = await AsyncStorage.getItem('token'); + const response = await fetch( + MOMENT_TAGS_ENDPOINT + `?moment_id=${moment_id}`, + { + method: 'GET', + headers: { + Authorization: 'Token ' + token, + }, + }, + ); + if (response.status === 200) { + const tags: MomentTagType[] = await response.json(); + return tags; + } + } catch (error) { + console.error(error); + return []; + } +}; -- cgit v1.2.3-70-g09d2