repo-based-blog-0.0.1: Blogging module using blaze html for markup

Stabilityexperimental
Maintainerwoozletoff@gmail.com
Safe HaskellNone

Web.RBB.Blog.Query

Contents

Description

This module provides some functions and data types that can be used to manage search and query data for a list of Entry values.

Synopsis

Documentation

data EntryQuery Source

The request data provided inside a URL.

Example: ?id=42&sortBy=Identifier

Example backend implementation using the Happstack package:

 import Happstack.Server (look, HasRqData, ServerPartT)

 maybeLookAndRead :: (Monad m, Read a, Alternative m, HasRqData m)
                  => a -> String -> m a
 maybeLookAndRead a qry = do
     l <- optional $ look qry
     return $ fromMaybe a (maybe (Just a) readMaybe l)

 -- | Parse the supported request data and present it in a data type.
 parseQueryRqData :: ServerPartT IO EntryQuery
 parseQueryRqData = EntryQuery
     <$> (sortMethodToComparator
         <$> maybeLookAndRead Update "sortBy"
         <*> maybeLookAndRead Descending "sortOrder")

Constructors

EntryQuery 

Fields

eqSortBy :: Entry -> Entry -> Ordering

The method entries are sorted by.

Instances

Default EntryQuery

The Default instance for an EntryQuery type contains a function that sorts the entries descending by the last update to the entry.

Sorting

data SortMethod Source

Simple enum that provides Show and read instances so that a parser can convert the sting directly to a value of this type.

Constructors

Update 
Identifier 
Author 

sortMethodToComparator :: SortMethod -> SortOrder -> Entry -> Entry -> OrderingSource

Convert a SortMethod value to a sorting function that can be used in confunction with functions sortBy from Data.List.