<s> import json <EOL> import logging <EOL> from lib . bottle import get , post , request , response <EOL> import models <EOL> @ get ( '<STR_LIT>' ) <EOL> def get_all_comments ( ) : <EOL> logging . info ( "<STR_LIT>" ) <EOL> comments = models . Comment . query ( ) . order ( models . Comment . created ) . fetch ( <NUM_LIT:100> ) <EOL> to_return = [ models . comment_to_json ( comment ) for comment in comments ] <EOL> response . content_type = '<STR_LIT:application/json>' <EOL> return json . dumps ( to_return ) <EOL> @ post ( '<STR_LIT>' ) <EOL> def create_new_comment ( ) : <EOL> logging . info ( "<STR_LIT>" ) <EOL> logging . info ( request . json ) <EOL> comment = models . Comment ( <EOL> text = request . json . get ( '<STR_LIT:text>' ) , <EOL> author = request . json . get ( '<STR_LIT>' ) <EOL> ) <EOL> comment . put ( ) <EOL> response . content_type = '<STR_LIT:application/json>' <EOL> return models . comment_to_json ( comment ) </s>
