You shouldn't pass params
into the service, the HTTP request params should only be used in the web layer. Try this instead
Controller
class PostController {
def postService;
def index() {}
def insert () {
render 'it works'
def post = postService.insertPost(params.post, session.user)
}
def showPost () {
def user = User.get(session.user)
def userPost = Post.withCriteria {
eq('user', user)
order('dateCreated', 'desc')
}
[userPost: userPost]
}
}
Service
class PostService {
def insertPost (String post, userId) {
def user = User.get(userId)
def post = new Post(post: post)
user.addToPosts(post)
return user.save(flush: true)
}
}