Report a paste

Please put a quick comment for the admin.

If it looks like spam, the admin will mark it as spam so that the spam filter picks it up in the future.

If the paste contains something private or offensive, it'll probably just be deleted.

No title

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE UndecidableInstances #-}
module Handler.Company where

import Data.Monoid
import Data.ByteString (ByteString)
import qualified Database.Redis as R
import Control.Monad.Except

type Radius = Int

type Category = Char

instance R.RedisCtx m f => R.RedisCtx (ExceptT e m) f where
  returnDecode = lift . R.returnDecode

instance R.MonadRedis m => R.MonadRedis (ExceptT e m) where
  liftRedis = lift . R.liftRedis

getCompanies :: R.Connection -> (Maybe Radius, Maybe Category) -> IO (Either R.Reply [Maybe ByteString])
getCompanies p (Just r, Just c) = undefined
getCompanies p (Just r, _) = undefined
getCompanies p (_, Just c) = undefined
getCompanies p _ = do
  R.runRedis p $
    runExceptT $ do
      lastDates <- ExceptT $ R.zrevrangebyscoreLimit "dates" 9999999 0 0 1
      case lastDates of
        [] -> error "oops2"
        (d:_) -> do
          ids <- ExceptT $ R.zrangebyscore ("companies:date:" <> d) 0 99999999
          ExceptT $ R.mget $ map ((<>) "companies:id:") ids