-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad4adee
commit 640915d
Showing
4 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
backend/src/main/resources/db/migration/V3__Create_followers_table.sql
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,5 @@ | ||
CREATE TABLE followers ( | ||
follower_id TEXT NOT NULL, | ||
followed_id TEXT NOT NULL, | ||
CONSTRAINT followers_pk PRIMARY KEY(follower_id, followed_id) | ||
); |
15 changes: 15 additions & 0 deletions
15
backend/src/main/scala/twitterclone/repositories/domain/FollowRepository.scala
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,15 @@ | ||
package twitterclone.repositories.domain | ||
|
||
import twitterclone.model.Id | ||
import twitterclone.model.user.User | ||
|
||
trait FollowRepository[F[_]] { | ||
|
||
def addFollower(followerId: Id[User], followeeId: Id[User]): F[Unit] | ||
|
||
def removeFollower(followerId: Id[User], followeeId: Id[User]): F[Unit] | ||
|
||
def getFollowers(userId: Id[User]): F[Set[Id[User]]] | ||
|
||
def follows(followerId : Id[User], followeeId: Id[User]) : F[Boolean] | ||
} |
25 changes: 25 additions & 0 deletions
25
...d/src/main/scala/twitterclone/repositories/interpreters/local/LocalFollowRepository.scala
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,25 @@ | ||
package twitterclone.repositories.interpreters.local | ||
|
||
import cats.Applicative | ||
import twitterclone.model.Id | ||
import twitterclone.model.user.User | ||
import twitterclone.repositories.domain.FollowRepository | ||
import cats.implicits._ | ||
|
||
import scala.collection.mutable | ||
|
||
object LocalFollowRepository { | ||
|
||
case class DirectedFollowRelationship(follower: Id[User], followed: Id[User]) | ||
|
||
def apply[F[_] : Applicative](state : mutable.Set[DirectedFollowRelationship] = mutable.Set.empty) = new FollowRepository[F] { | ||
override def addFollower(followerId: Id[User], followeeId: Id[User]): F[Unit] = (state += DirectedFollowRelationship(followerId, followeeId)).pure[F].void | ||
|
||
override def removeFollower(followerId: Id[User], followeeId: Id[User]): F[Unit] = ((state += DirectedFollowRelationship(followerId, followeeId)).pure[F].void) | ||
|
||
override def getFollowers(userId: Id[User]): F[Set[Id[User]]] = (state.filter(_.followed == userId).map(_.follower).toSet.pure[F]) | ||
|
||
override def follows(followerId: Id[User], followeeId: Id[User]): F[Boolean] = state.contains(DirectedFollowRelationship(followerId, followeeId)).pure[F] | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
...main/scala/twitterclone/repositories/interpreters/postgres/PostgresFollowRepository.scala
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,5 @@ | ||
package twitterclone.repositories.interpreters.postgres | ||
|
||
object PostgresFollowRepository { | ||
|
||
} |