Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
830d2ec
Formatting
sras Nov 4, 2016
a43ee57
Insert records directily with out having to convert to PGW types
sras Nov 4, 2016
45c7a2d
Use the records directly without converting to thier PG counterparts …
sras Nov 4, 2016
19b697b
Fix issue when dealing with enum field with default value
sras Nov 5, 2016
f6a52f0
Add housekeeping fields to Tenant
sras Nov 7, 2016
46ba90a
Add housekeeping fields to remaining models
sras Nov 7, 2016
e7fef1e
Update housekeeping columns without lens
sras Nov 7, 2016
bc4b2df
Fix postgresql/haskell conversion issue and start using Lens
sras Nov 7, 2016
4e25c7c
Made role api to use create_item function that uses lenses to deal wi…
sras Nov 7, 2016
f11a655
Convert more api function to use lenses
sras Nov 8, 2016
bb234be
Fix json generation
sras Nov 8, 2016
785c7d7
Implementing generic update function
sras Nov 8, 2016
f286b54
Generic update function type checks now
sras Nov 8, 2016
4781ca8
Refactor
sras Nov 8, 2016
e16f7a0
Convert everything to use lens
sras Nov 8, 2016
df887ed
Split the generic insert/update function in a separate module
sras Nov 9, 2016
8308879
Fixed issue
sras Nov 9, 2016
74e8743
Refactor
sras Nov 9, 2016
a8c94fd
Make created fields optional and updated field required for writing
sras Nov 9, 2016
74eff26
Removed unused AllowAmbiguousTypes extension
sras Nov 9, 2016
290cc61
Reenable create functions
sras Nov 9, 2016
945ef75
Merge OpaleyeTypes with OpaleyeDef
sras Nov 10, 2016
e770e4c
Conver names to camel case and drop id from update functions
sras Nov 10, 2016
04fc93d
Make id fields read only and remove unused Default instances
sras Nov 10, 2016
93b6037
Fix warnings
sras Nov 10, 2016
3734c41
Stylize
sras Nov 10, 2016
07304e8
Refactor to use listToMaybe functions
sras Nov 10, 2016
1a298cb
Start of Audtable api implementation
sras Nov 12, 2016
dd2d971
Convert all api function to use AuditM
sras Nov 12, 2016
bd209c5
Add wrapper to opaleye functions that runs in AuditM
sras Nov 12, 2016
1004ca1
Add functions that does raw db updates in AuditM
sras Nov 14, 2016
4b32bdd
Rename AuditM to AppM
sras Nov 15, 2016
ea708d7
Added TH functions to create auditable lenses
sras Nov 15, 2016
6f80c26
Generate typeclasses for the auditable wrapper using TH
sras Nov 16, 2016
f940de5
Clean up warnings and start conversion of audit log to json Value type
sras Nov 16, 2016
18e2dfe
Change the audit log to use the json Value object
sras Nov 16, 2016
c6f7d14
Added type syns for AuditM wrapper
sras Nov 16, 2016
03a33cc
Convert all the api function to run in AppM
sras Nov 17, 2016
7b4ba29
Use Auditable models in api functions
sras Nov 17, 2016
6ebf760
Insert log to db on update calls
sras Nov 17, 2016
79d5114
Test case for audit logs
sras Nov 17, 2016
f02c93a
Fix build issues
sras Nov 18, 2016
a995b2d
Fix typo in TH function name
sras Nov 20, 2016
4a38268
Adding comments
sras Nov 21, 2016
14e2d8a
Ammende TH functions to take types that are not sysnonyms into account
sras Nov 25, 2016
4ce8966
Added schema files
sras Nov 29, 2016
4b3fca4
Added list tenants endpoints for load testing
sras Nov 30, 2016
82d2d78
Send mail via sendgrid
sras Dec 5, 2016
69f172f
Added email templates and linked mail sending from create tenant json…
sras Dec 7, 2016
aa38a20
Add inline attachment embedding using cid method
sras Dec 7, 2016
95f65e2
Fix double quoting of links and add hardcoded key
sras Dec 7, 2016
27cf3b3
Fix double quote issue with quasiquoter and add a hardcoded key to th…
sras Dec 7, 2016
480119f
Send mail from another thread and code refactor
sras Dec 7, 2016
741ff7d
Add user services
sras Dec 8, 2016
87b9674
Review modifications
sras Dec 9, 2016
81f6fab
Cleaned up stack.yaml
sras Dec 9, 2016
0a8c997
Use the updated mime-email library
sras Dec 12, 2016
29a8a80
Wrapped the app monad around ExceptT to enable handling of uncaught e…
sras Dec 12, 2016
65c5ccc
Trying to add request body to the error logs
sras Dec 13, 2016
52c102b
Use a helper function to fetch env info and log it in case of an exce…
sras Dec 13, 2016
0ce8cbf
Add request info to the log
sras Dec 13, 2016
cd991a1
Added airbrake source
sras Dec 14, 2016
e788e65
cabale file update
sras Dec 14, 2016
6ec820b
Wrap the auditable types
sras Dec 15, 2016
f56c9c5
Got the refactor to compile
sras Dec 15, 2016
caa39c0
Rename files
sras Dec 16, 2016
117f8db
Moved code to a separate package AppCore
sras Dec 16, 2016
54dcd2e
Added removeAuditableRow function to api base
sras Dec 16, 2016
39dbab3
Hide stuff in AppCore module
sras Dec 16, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ cabal.sandbox.config
*.eventlog
.stack-work/
cabal.project.local
Conf.hs
2 changes: 1 addition & 1 deletion ServantOpaleye/stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ extra-package-dbs: []
# extra-lib-dirs: [/path/to/dir]
#
# Allow a newer minor version of GHC than the snapshot specifies
# compiler-check: newer-minor
# compiler-check: newer-minor
40 changes: 35 additions & 5 deletions SpockOpaleye/SpockOpaleye.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,42 @@ cabal-version: >=1.10

library
hs-source-dirs: src
exposed-modules: Lib,
TenantApi,
exposed-modules: TenantApi,
UserApi,
RoleApi,
OpaleyeDef,
CryptoDef,
JsonInstances,
Validations,
DataTypes
Conf,
UserServices,
Email
build-depends: base >= 4.7 && < 5
,appcore
,smtp-mail
,lifted-base
,airbrake
,here
,filepath
,mime-mail >= 0.4.12
,product-profunctors
,profunctors
,bytestring
,opaleye
,time
,old-time
,network
,postgresql-simple
,bcrypt
,text
,lens
,mtl
,transformers
,time
,vector
,Spock >=0.11
,aeson
,unordered-containers
,template-haskell
,lifted-base
default-language: Haskell2010

executable SpockOpaleye-exe
Expand All @@ -43,13 +59,27 @@ executable SpockOpaleye-exe
ghc-options: -threaded -rtsopts -with-rtsopts=-N -fwarn-tabs -fwarn-unused-imports -fwarn-missing-signatures -fwarn-incomplete-patterns
build-depends: base
, postgresql-simple
, airbrake
, bytestring
, appcore
, here
, mime-mail
, filepath
, smtp-mail
, network
, old-time
, SpockOpaleye
, Spock >=0.11
, mtl
, transformers
, lens
, text
, time
, bcrypt
, vector
, aeson
, unordered-containers
, lifted-base
default-language: Haskell2010

test-suite SpockOpaleye-test
Expand Down
75 changes: 56 additions & 19 deletions SpockOpaleye/app/Main.hs
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}

module Main where

import AppCore
import Database.PostgreSQL.Simple
import DataTypes
import JsonInstances ()
import TenantApi
import Validations

import Email
import Web.Spock
import Web.Spock.Config

import Control.Monad.Reader
import Control.Monad.Writer
import qualified Control.Monad.Reader as R
import qualified Data.Text as T
import Data.Time
import Prelude hiding (id)
import UserServices
import Control.Monad.Trans.Except
import Control.Exception.Lifted
import Airbrake
import Airbrake.WebRequest
import Data.ByteString (ByteString)

data MySession =
EmptySession
data MySession = EmptySession

data MyAppState = DummyAppState

data AppResult a = AppOk a | AppErr T.Text

connectDb :: IO Connection
connectDb = connect defaultConnectInfo { connectDatabase = "haskell-webapps" }

Expand All @@ -30,19 +45,41 @@ main = do
DummyAppState
runSpock 8080 (spock spockCfg app)

runAppM :: AppM a -> Connection -> IO (AppResult a)
runAppM x conn = do
user <- getTestUser
r <- runExceptT $ handle throwE $ runReaderT (runWriterT x) (conn, Just $ getTestTenant, Just $ user)
case r of
Right (item, lg) -> do
return $ AppOk item
Left ex -> do
let message = T.pack $ show ex
return $ AppErr message

runWithLogging :: ActionT (WebStateM Connection MySession MyAppState) (AppResult a)
-> (a -> ActionT (WebStateM Connection MySession MyAppState) ())
-> ActionT (WebStateM Connection MySession MyAppState) ()
runWithLogging act sact = do
r <- act
case r of
AppOk rOk -> sact rOk
AppErr msg -> do
r <- request
liftIO $ notifyReq conf (waiRequestToRequest r) (Error "Uncaught exception" msg) (("Filename", 5):|[])
json $ T.pack "There was an error. Please try again later"
where
conf = airbrakeConf "61a1adfc070a9be9f21e43f586bbf5f7" "Env"

app :: SpockM Connection MySession MyAppState ()
app = do
post ("tenants/new") $
do maybe_tenant_incoming <- jsonBody
maybe_newtenant <-
case maybe_tenant_incoming of
Just incoming_tenant -> do
result <-
runQuery (\conn -> validateIncomingTenant conn incoming_tenant)
case result of
Valid -> runQuery (\conn -> create_tenant conn incoming_tenant)
_ -> return Nothing
Nothing -> return Nothing
case maybe_newtenant of
Just tenant -> json tenant
_ -> json $ T.pack "Tenant not created"
get ("tenants") $ do
runWithLogging (runQuery $ runAppM readTenants) (\tenants ->json tenants)
post ("tenants/new") $ runWithLogging (do
maybeTenantIncoming <- jsonBody
runQuery $ runAppM $ do
case maybeTenantIncoming of
Just incomingTenant -> doCreateTenant incomingTenant
Nothing -> return $ Left $ T.pack "Unrecognized input"
) (\et -> case et of
Right new_tenant -> json new_tenant
Left message -> json message)
30 changes: 30 additions & 0 deletions SpockOpaleye/appcore/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copyright Author name here (c) 2016

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.

* Neither the name of Author name here nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 2 additions & 0 deletions SpockOpaleye/appcore/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
6 changes: 6 additions & 0 deletions SpockOpaleye/appcore/app/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Main where

import Lib

main :: IO ()
main = someFunc
67 changes: 67 additions & 0 deletions SpockOpaleye/appcore/appcore.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: appcore
version: 0.1.0.0
synopsis: Initial project template from stack
description: Please see README.md
homepage: https://github.com/githubuser/appcore#readme
license: BSD3
license-file: LICENSE
author: Author name here
maintainer: example@example.com
copyright: 2016 Author name here
category: Web
build-type: Simple
extra-source-files: README.md
cabal-version: >=1.10

library
hs-source-dirs: src
,src/User
,src/Role
,src/Tenant
exposed-modules: AppCore
other-modules: Auditable
,AuditableTH
,CryptoDef
,OpaleyeDef
,UserDefs
,TenantDefs
,RoleDefs
,Lenses
,UserId
,TenantId
,Utils
,AppM
,ApiBase
,UserApi
,TenantApi
build-depends: base >= 4.7 && < 5
, aeson
, transformers
, text
, lens
, time
, old-time
, product-profunctors
, profunctors
, vector
, bytestring
, opaleye
, postgresql-simple
, template-haskell
, unordered-containers
, bcrypt
, mtl
default-language: Haskell2010

test-suite appcore-test
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: Spec.hs
build-depends: base
, appcore
ghc-options: -threaded -rtsopts -with-rtsopts=-N
default-language: Haskell2010

source-repository head
type: git
location: https://github.com/githubuser/appcore
Loading