Created
May 26, 2010 14:33
-
-
Save xetorthio/414557 to your computer and use it in GitHub Desktop.
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
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