Skip to content

Commit

Permalink
followers initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiecollard committed Jul 13, 2023
1 parent ad4adee commit 640915d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
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)
);
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]
}
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]
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package twitterclone.repositories.interpreters.postgres

object PostgresFollowRepository {

}

0 comments on commit 640915d

Please sign in to comment.