-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(clientError): implement standalone ClientErrorAdminService
- Loading branch information
1 parent
395e8d6
commit 7bda447
Showing
1 changed file
with
40 additions
and
2 deletions.
There are no files selected for viewing
42 changes: 40 additions & 2 deletions
42
grails-app/services/io/xh/hoist/clienterror/ClientErrorAdminService.groovy
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 |
---|---|---|
@@ -1,10 +1,48 @@ | ||
package io.xh.hoist.clienterror | ||
|
||
import grails.gorm.transactions.ReadOnly | ||
import io.xh.hoist.BaseService | ||
import io.xh.hoist.data.filter.Filter | ||
import io.xh.hoist.track.TrackLog | ||
import org.hibernate.Criteria | ||
import org.hibernate.SessionFactory | ||
|
||
import java.time.LocalDate | ||
|
||
import static io.xh.hoist.util.DateTimeUtils.appEndOfDay | ||
import static io.xh.hoist.util.DateTimeUtils.appStartOfDay | ||
import static org.hibernate.criterion.Order.desc | ||
import static org.hibernate.criterion.Restrictions.between | ||
|
||
class ClientErrorAdminService extends BaseService { | ||
SessionFactory sessionFactory | ||
|
||
@ReadOnly | ||
List<ClientError> queryClientError(LocalDate startDay, LocalDate endDay, Filter filter, int maxRows) { | ||
def session = sessionFactory.currentSession | ||
Criteria c = session.createCriteria(ClientError) | ||
c.maxResults = maxRows | ||
c.addOrder(desc('dateCreated')) | ||
c.add(between('dateCreated', appStartOfDay(startDay), appEndOfDay(endDay))) | ||
if (filter) { | ||
c.add(filter.criterion) | ||
} | ||
c.list() as List<ClientError> | ||
} | ||
|
||
@ReadOnly | ||
Map lookups() {[ | ||
browser: distinctVals('browser'), | ||
device: distinctVals('device'), | ||
username: distinctVals('username') | ||
] } | ||
|
||
def queryClientError() { | ||
|
||
//------------------------ | ||
// Implementation | ||
//------------------------ | ||
private List distinctVals(String property) { | ||
TrackLog.createCriteria().list { | ||
projections { distinct(property) } | ||
}.sort() | ||
} | ||
} |