Commit 16fc3a05 authored by fangzhipeng's avatar fangzhipeng

提交代码

parent 0466a9a7
......@@ -40,5 +40,33 @@ def select_follow_by_user_id(user_id):
session.close()
return [dict(x.items()) for x in items]
def select_by_record_id(record_id):
"""
根据记录Id获取记录
:param record_id:
:return:
"""
session = sqlengin.getSession()
session.execute('update user_record t set t.hot=t.hot+1 WHERE t.id=:record_id', {'record_id': record_id})
record = session.execute('select t.*, tt.nickname from user_record t, user_info tt WHERE t.user_id=tt.id AND t.id=:record_id', {'record_id': record_id}).first()
session.commit()
session.close()
return dict(record.items()) if record else None
def select_hot_record():
"""
获取热门记录
:return:
"""
session = sqlengin.getSession()
items = session.execute('select t.*, tt.nickname from user_record t, user_info tt WHERE t.user_id=tt.id ORDER BY t.hot DESC').fetchall()
session.close()
return [dict(x.items()) for x in items]
if __name__ == '__main__':
print(json_util.to_json(select_follow_by_user_id(2)))
\ No newline at end of file
print(json_util.to_json(select_by_record_id(2)))
\ No newline at end of file
......@@ -32,6 +32,17 @@ def get_my_follow():
items = record_dao.select_follow_by_user_id(user_id)
return http.BaseRes(data=items).to_json()
@record.route('/hot_record')
@login_require
def get_hot_record():
"""
获取热门记录
:return:
"""
items = record_dao.select_hot_record()
return http.BaseRes(data=items).to_json()
@record.route('/publish', methods=['post', 'get'])
@login_require
def publish_record():
......@@ -46,7 +57,15 @@ def publish_record():
return http.BaseRes(message='发布成功!').to_json()
@record.route('/record_detail')
def record_detail():
"""
记录详细信息
:return:
"""
record_id = request.values.get('record_id')
record = record_dao.select_by_record_id(record_id)
return http.BaseRes(data=record).to_json()
if __name__ == '__main__':
print(get_my_record())
\ No newline at end of file
......@@ -24,7 +24,7 @@ def to_json(obj):
:param obj:
:return:
"""
return json.dumps(obj, cls=MyJSONEncoder, ensure_ascii=False)
return json.dumps(obj, cls=MyJSONEncoder, ensure_ascii=False) if obj else ''
def db_to_json(obj):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment