diff options
| author | Ashm Walia <40498934+ashmgarv@users.noreply.github.com> | 2020-12-30 11:36:44 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-30 14:36:44 -0500 |
| commit | 38661e00281363b0f4ad32f0b29d739e1ca09164 (patch) | |
| tree | 316cd837b6cc6ae24783f1d93d6c9ee7fb898f68 /src/services | |
| parent | bd2f89805d0bb1c2f1d08fe8d91099aa4f109d35 (diff) | |
[TMA - 457]Change followers to friends (#149)
* One commit to replace followers with friends
* Move block unblock to drawer and some cosmetic changes
* Options to edit own profile when viewing
* Changes for University Class
* Small fix
* Made ProfileOnboarding a scroll view and other small changes
* Small fix
* Small fix thanks to ivan and tanmay
* Add ?
Diffstat (limited to 'src/services')
| -rw-r--r-- | src/services/UserFollowServices.ts | 85 | ||||
| -rw-r--r-- | src/services/UserFriendsServices.ts | 63 | ||||
| -rw-r--r-- | src/services/UserProfileService.ts | 22 | ||||
| -rw-r--r-- | src/services/index.ts | 2 |
4 files changed, 84 insertions, 88 deletions
diff --git a/src/services/UserFollowServices.ts b/src/services/UserFollowServices.ts deleted file mode 100644 index f0f176fc..00000000 --- a/src/services/UserFollowServices.ts +++ /dev/null @@ -1,85 +0,0 @@ -//Abstracted common user follow api calls out here - -import {Alert} from 'react-native'; -import { - FOLLOWERS_ENDPOINT, - FOLLOW_USER_ENDPOINT, - UNFOLLOW_USER_ENDPOINT, - FOLLOWING_ENDPOINT, -} from '../constants'; - -export const loadFollowers = async (userId: string, token: string) => { - try { - const response = await fetch(FOLLOWERS_ENDPOINT + `?user_id=${userId}`, { - method: 'GET', - headers: { - Authorization: 'Token ' + token, - }, - }); - if (response.status === 200) { - const body = await response.json(); - return body; - } else { - throw new Error(await response.json()); - } - } catch (error) { - console.log(error); - } -}; - -export const loadFollowing = async (userId: string, token: string) => { - try { - const response = await fetch(FOLLOWING_ENDPOINT + `?user_id=${userId}`, { - method: 'GET', - headers: { - Authorization: 'Token ' + token, - }, - }); - if (response.status === 200) { - const body = await response.json(); - return body; - } else { - throw new Error(await response.json()); - } - } catch (error) { - console.log(error); - } -}; - -export const followOrUnfollowUser = async ( - follower: string, - followed: string, - token: string, - isFollowed: boolean, -) => { - try { - const endpoint = isFollowed ? UNFOLLOW_USER_ENDPOINT : FOLLOW_USER_ENDPOINT; - const response = await fetch(endpoint, { - method: 'POST', - headers: { - Authorization: 'Token ' + token, - }, - body: JSON.stringify({ - follower, - followed, - }), - }); - if (Math.floor(response.status / 100) === 2) { - return true; - } else { - console.log(await response.json()); - Alert.alert( - 'Something went wrong! ðŸ˜', - "Would you believe me if I told you that I don't know what happened?", - ); - return false; - } - } catch (error) { - console.log(error); - Alert.alert( - 'Something went wrong! ðŸ˜', - "Would you believe me if I told you that I don't know what happened?", - ); - return false; - } -}; diff --git a/src/services/UserFriendsServices.ts b/src/services/UserFriendsServices.ts new file mode 100644 index 00000000..0b138fc3 --- /dev/null +++ b/src/services/UserFriendsServices.ts @@ -0,0 +1,63 @@ +//Abstracted common friends api calls out here + +import {Alert} from 'react-native'; +import {FRIENDS_ENDPOINT} from '../constants'; + +export const loadFriends = async (userId: string, token: string) => { + try { + const response = await fetch(FRIENDS_ENDPOINT + `?user_id=${userId}`, { + method: 'GET', + headers: { + Authorization: 'Token ' + token, + }, + }); + if (response.status === 200) { + const body = await response.json(); + return body; + } else { + throw new Error(await response.json()); + } + } catch (error) { + console.log(error); + } +}; + +export const friendOrUnfriendUser = async ( + user: string, + friend: string, + token: string, + isFriend: boolean, +) => { + try { + const endpoint = FRIENDS_ENDPOINT + (isFriend ? `${user}/` : ''); + const response = await fetch(endpoint, { + method: isFriend ? 'DELETE' : 'POST', + headers: { + 'Content-Type': 'application/json', + Authorization: 'Token ' + token, + }, + body: JSON.stringify({ + user, + friend, + }), + }); + const status = response.status; + if (Math.floor(status / 100) === 2) { + return true; + } else { + console.log(await response.json()); + Alert.alert( + 'Something went wrong! ðŸ˜', + "Would you believe me if I told you that I don't know what happened?", + ); + return false; + } + } catch (error) { + console.log(error); + Alert.alert( + 'Something went wrong! ðŸ˜', + "Would you believe me if I told you that I don't know what happened?", + ); + return false; + } +}; diff --git a/src/services/UserProfileService.ts b/src/services/UserProfileService.ts index 8c88f0ab..75042830 100644 --- a/src/services/UserProfileService.ts +++ b/src/services/UserProfileService.ts @@ -29,9 +29,27 @@ export const loadProfileInfo = async (token: string, userId: string) => { const status = response.status; if (status === 200) { const info = await response.json(); - let {name, biography, website, birthday, gender, snapchat, tiktok} = info; + let { + name, + biography, + website, + birthday, + gender, + snapchat, + tiktok, + university_class, + } = info; birthday = birthday && moment(birthday).format('YYYY-MM-DD'); - return {name, biography, website, birthday, gender, snapchat, tiktok}; + return { + name, + biography, + website, + birthday, + gender, + snapchat, + tiktok, + university_class, + }; } else { throw 'Unable to load profile data'; } diff --git a/src/services/index.ts b/src/services/index.ts index 7e6b836a..7ea5bf5d 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -2,7 +2,7 @@ export * from './UserProfileService'; export * from './SocialLinkingService'; export * from './MomentServices'; export * from './ExploreServices'; -export * from './UserFollowServices'; +export * from './UserFriendsServices'; export * from './ReportingService'; export * from './BlockUserService'; export * from './MomentCategoryService'; |
