Skip to content

Instantly share code, notes, and snippets.

@xetorthio
Created May 26, 2010 14:33
Show Gist options
  • Save xetorthio/414557 to your computer and use it in GitHub Desktop.
Save xetorthio/414557 to your computer and use it in GitHub Desktop.
package questions
class QuestionsController {
// GET /customers/$id/questions/pending/items
def customerItemsWithPendingQuestions = {
def items = Item.findAllByPendingQuestionsGreaterThan(0)
render items as JSON
}
// GET /items/$id/questions/pending
def itemPendingQuestions = {
def questions = Question.findAllByItemAndStatus(params.id, Question.PENDING)
render questions as JSON
}
// POST /items/$id/questions
def askAQuestion = {
def item = Item.load(param.id)
// creates a new question for the item. save the question and increse the amount of pendingQuestions in the item and save the item.
def question = item.ask(params)
}
// POST /questions/$id/answers
def answerAQuestion = {
def question = Question.load(params.id)
//creates a new Answer and save it. reduce the amount of pendingQuestions in the item and increase the amount of answered questions and save the item.
def answer = question.answer(params)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment