Skip to content

Instantly share code, notes, and snippets.

View mlescaille's full-sized avatar

Marisniulkis Lescaille mlescaille

View GitHub Profile
package com.tutorial.googleeoauth.repository
import com.tutorial.googleeoauth.domain.GoogleCredentialDetails
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.jpa.repository.JpaRepository
/**
* Repository for {@link GoogleCredentialDetails}. Represents credentials of Google's
* OAuth authentication and authorization process.
package com.tutorial.googleeoauth
import com.google.api.client.auth.oauth2.StoredCredential
import com.google.api.client.util.store.AbstractDataStore
import com.google.api.client.util.store.DataStore
import com.tutorial.googleeoauth.domain.GoogleCredentialDetails
import com.tutorial.googleeoauth.exception.ResourceNotFoundException
import com.tutorial.googleeoauth.repository.GoogleCredentialDetailsRepository
import java.util.stream.Collectors
package com.tutorial.googleeoauth
import com.google.api.client.util.store.DataStore
import com.google.api.client.util.store.DataStoreFactory
import com.tutorial.googleeoauth.repository.GoogleCredentialDetailsRepository
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component
/**
* Data store factory class required for implementing a custom data store to store credential
package com.tutorial.googleeoauth.domain
import com.google.api.client.auth.oauth2.StoredCredential
import groovy.transform.CompileStatic
import javax.persistence.Entity
import javax.validation.constraints.NotNull
import java.time.LocalDateTime
/**
implementation 'com.google.auth:google-auth-library-oauth2-http:0.17.1'
implementation ('com.google.oauth-client:google-oauth-client-jetty:1.28.0') {
exclude group: 'org.mortbay.jetty', module: 'servlet-api' // had to exclude this but will depend on the rest of your dependencies
}
import grails.artefact.Enhances
import org.grails.core.artefact.ControllerArtefactHandler
@Enhances(ControllerArtefactHandler.TYPE) //you can do the same with ServiceArtefactHandler.TYPE
trait ExceptionHandler {
def handleControllerError(Exception e) {
response.status = 400
render ApiError.unknownError as JSON
}
class RandomController implements ExceptionHandler {
}
@mlescaille
mlescaille / grailstrait.groovy
Created August 4, 2020 21:38
Grails exception handler trait
import grails.converters.JSON
import com.mari.ApiError
trait ExceptionHandler {
def handleControllerError(Exception e) {
response.status = 400
render ApiError.unknownError as JSON
}
}