-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backend + Early frontend for Feeds (#170)
* Initialize UI for feed * Add backend route for retrieving a user's feed * Fix bug in handling friend requests * Create helper functions to integrate frontend and backend
- Loading branch information
Showing
6 changed files
with
116 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import prisma from '@/lib/prisma'; | ||
import { verifySession } from '@/lib/session'; | ||
import { NextResponse } from 'next/server'; | ||
|
||
export const GET = async () => { | ||
const session = await verifySession(); | ||
|
||
if (!session.isAuth) { | ||
return NextResponse.json({ error: 'Invalid session.' }, { status: 400 }); | ||
} | ||
|
||
const user = await prisma.user.findFirst({ | ||
where: { | ||
id: session.uid, | ||
}, | ||
include: { | ||
friends: { | ||
include: { | ||
preferences: true, | ||
playlists: true, | ||
likedSongs: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
return NextResponse.json({ friends: user?.friends }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { getFeed } from '@/services/friends'; | ||
import { useEffect } from 'react'; | ||
import { SafeAreaView, StyleSheet, Text, View } from 'react-native'; | ||
|
||
const Feed = () => { | ||
useEffect(() => { | ||
const loadFeed = async () => { | ||
getFeed(); | ||
}; | ||
loadFeed(); | ||
}); | ||
|
||
return ( | ||
<SafeAreaView style={styles.container}> | ||
<View style={styles.header}> | ||
<Text style={styles.title}>Friends</Text> | ||
</View> | ||
</SafeAreaView> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
backgroundColor: 'black', | ||
width: '100%', | ||
height: '100%', | ||
}, | ||
header: { | ||
padding: 15, | ||
backgroundColor: 'black', | ||
}, | ||
title: { | ||
fontSize: 24, | ||
fontWeight: 'bold', | ||
color: 'white', | ||
}, | ||
horizontalLine: { | ||
borderBottomColor: 'white', | ||
borderBottomWidth: 1, | ||
width: '100%', | ||
marginVertical: 10, | ||
marginBottom: 15, | ||
}, | ||
}); | ||
|
||
export default Feed; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { LOCAL_API_ENDPOINT } from '@/constants'; | ||
import { FeedItem } from '@/types'; | ||
import { getCookie } from '@/utils/cookies'; | ||
|
||
export const getFeed = async (): Promise<FeedItem[]> => { | ||
const response = await fetch(`${LOCAL_API_ENDPOINT}/friends/feed`, { | ||
headers: { | ||
Cookie: (await getCookie())!, | ||
}, | ||
}); | ||
const body = await response.json(); | ||
console.log(body); | ||
return body.friends as FeedItem[]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters