<s> from framework . routes import get , put , abort <EOL> from framework . session import get_current_user <EOL> from models . notice import Notice <EOL> @ get ( '<STR_LIT>' ) <EOL> def list_notices_route ( request ) : <EOL> """<STR_LIT>""" <EOL> db_conn = request [ '<STR_LIT>' ] <EOL> current_user = get_current_user ( request ) <EOL> if not current_user : <EOL> return abort ( <NUM_LIT> ) <EOL> notices = Notice . list ( db_conn , <EOL> user_id = current_user [ '<STR_LIT:id>' ] , <EOL> ** request [ '<STR_LIT>' ] ) <EOL> output = { '<STR_LIT>' : [ notice . deliver ( access = '<STR_LIT>' ) <EOL> for notice in notices ] } <EOL> return <NUM_LIT:200> , output <EOL> @ put ( '<STR_LIT>' ) <EOL> def mark_notice_route ( request , notice_id ) : <EOL> """<STR_LIT>""" <EOL> db_conn = request [ '<STR_LIT>' ] <EOL> current_user = get_current_user ( request ) <EOL> if not current_user : <EOL> return abort ( <NUM_LIT> ) <EOL> notice = Notice . get ( db_conn , id = notice_id ) <EOL> if not notice : <EOL> return abort ( <NUM_LIT> ) <EOL> if notice [ '<STR_LIT>' ] != current_user [ '<STR_LIT:id>' ] : <EOL> return abort ( <NUM_LIT> ) <EOL> if '<STR_LIT>' not in request [ '<STR_LIT>' ] : <EOL> errors = [ { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:message>' : '<STR_LIT>' , <EOL> } ] <EOL> elif request [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) is True : <EOL> notice , errors = notice . mark_as_read ( db_conn ) <EOL> elif request [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) is False : <EOL> notice , errors = notice . mark_as_unread ( db_conn ) <EOL> if len ( errors ) : <EOL> return <NUM_LIT> , { <EOL> '<STR_LIT>' : errors , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> return <NUM_LIT:200> , { '<STR_LIT>' : notice . deliver ( access = '<STR_LIT>' ) } </s>
