예제 #1
0
 def get(self):
     reqparser = reqparse.RequestParser()
     reqparser.add_argument('uid', type=unicode, location='args', required=True)
     reqparser.add_argument('cursor', type=unicode, location='args', required=False)
     args = reqparser.parse_args()
     uid = decode_id(args.get('uid'))
     cursor = args.get('cursor')
     cursor = int(decode_id(cursor)) if cursor is not None else None
     comments = endorse_service.get_endorse_comments(uid, cursor)
     return compose_response(result=comments)
예제 #2
0
 def get(self):
     """
         Get user list who thinks `uid` is reliability
     """
     reqparser = reqparse.RequestParser()
     reqparser.add_argument('uid', type=unicode, location='args', required=True)
     reqparser.add_argument('cursor', type=unicode, location='args', required=False)
     args = reqparser.parse_args()
     uid = decode_id(args.get('uid'))
     cursor = args.get('cursor')
     cursor = decode_id(cursor) if cursor is not None else None
     endorsements = endorse_service.get_user_endorse(uid, EndorseType.Reliability, cursor)
     return compose_response(result=endorsements)
예제 #3
0
파일: api_work.py 프로젝트: dannliu/st-be
    def put(self):
        reqparser = reqparse.RequestParser()
        reqparser.add_argument('id',
                               type=unicode,
                               location='json',
                               required=True)
        # company_id and company_name must have one
        # if the company is a new one, create a company record first
        reqparser.add_argument('company_id',
                               type=unicode,
                               location='json',
                               required=False)
        reqparser.add_argument('company_name',
                               type=unicode,
                               location='json',
                               required=False)
        reqparser.add_argument('title',
                               type=unicode,
                               location='json',
                               required=True)
        reqparser.add_argument('start_year',
                               type=int,
                               location='json',
                               required=True)
        reqparser.add_argument('start_month',
                               type=int,
                               location='json',
                               required=True)
        # 2999 stands for present
        reqparser.add_argument('end_year',
                               type=int,
                               location='json',
                               required=True)
        reqparser.add_argument('end_month',
                               type=int,
                               location='json',
                               required=False)

        args = reqparser.parse_args()
        id = decode_id(args.get('id'))
        company_id = decode_id(args.get('company_id'))
        work_service.update_work_experience(current_user.user.id, id,
                                            company_id, args['company_name'],
                                            args['title'], args['start_year'],
                                            args['start_month'],
                                            args['end_year'],
                                            args['end_month'])
        return compose_response(
            result=user_service.get_login_user_profile(current_user.user.id))
예제 #4
0
 def post(self):
     reqparser = reqparse.RequestParser()
     reqparser.add_argument('feed_id',
                            type=unicode,
                            location='json',
                            required=False)
     args = reqparser.parse_args()
     feed_id = int(decode_id(args.get('feed_id')))
     feed = Feed.find(feed_id)
     if not feed:
         st_raise_error(ErrorCode.FEED_NOT_FOUND)
     feed_like = FeedLike.find_by_uid(current_user.user.id, feed_id)
     if not feed_like:
         feed_like = FeedLike(uid=current_user.user.id,
                              feed_id=feed_id,
                              status=FeedLikeStatus.Liked)
         FeedLike.add(feed_like)
     else:
         feed_like.status = FeedLikeStatus.reverse(feed_like.status)
     if feed_like.status == FeedLikeStatus.Liked:
         feed.like_count += 1
     else:
         feed.like_count -= 1
     if feed.like_count < 0:
         # Ensure the count is >= 0
         feed.like_count = 0
     feed_like.update()
     new_feed = feed_service.get_feed(current_user.user.id, feed_id)
     return compose_response(result=new_feed)
예제 #5
0
 def get(self):
     # 获取联系人请求列表
     reqparser = reqparse.RequestParser()
     reqparser.add_argument('cursor', type=unicode, location='args', required=False)
     args = reqparser.parse_args()
     last_request_id = decode_id(args['cursor']) if args.get('cursor') else None
     requests = contact_service.get_contact_requests(current_user.user.id, last_request_id, 20)
     return compose_response(result=requests)
예제 #6
0
 def get(self):
     reqparser = reqparse.RequestParser()
     reqparser.add_argument('cursor', type=unicode, location='args', required=False)
     args = reqparser.parse_args()
     last_timestamp = decode_id(args['cursor']) if args.get('cursor') else None
     last_update_date = timestamp_to_datetime(last_timestamp)
     contacts = contact_service.get_contacts(current_user.user.id, last_update_date, ApiContacts.SIZE)
     return compose_response(result=contacts)
예제 #7
0
 def put(self):
     # 接受或者删除联系人申请
     # TODO: We need check whether two users were once in the same company?
     reqparser = reqparse.RequestParser()
     reqparser.add_argument('id', type=unicode, location='json', required=True)
     reqparser.add_argument('accept', type=bool, location='json', required=True)
     args = reqparser.parse_args()
     id = decode_id(args["id"])
     result = contact_service.accept_contact_request(id, current_user.user.id, args["accept"])
     return compose_response(result=result)
예제 #8
0
파일: api_user.py 프로젝트: dannliu/st-be
 def get(self):
     reqparser = reqparse.RequestParser()
     reqparser.add_argument('uid',
                            type=unicode,
                            location='args',
                            required=True)
     args = reqparser.parse_args()
     uid = int(decode_id(args['uid']))
     user_profile = user_service.get_user_profile(uid, current_user.user.id)
     return compose_response(result=user_profile)
예제 #9
0
 def get(self):
     reqparser = reqparse.RequestParser()
     reqparser.add_argument('cursor',
                            type=unicode,
                            location='args',
                            required=False)
     args = reqparser.parse_args()
     cursor = args.get('cursor')
     last_id = int(decode_id(cursor)) if cursor else None
     feeds = feed_service.get_feeds(current_user.user.id, last_id, 20)
     return compose_response(result=feeds)
예제 #10
0
 def post(self):
     # 请求建立联系人关系
     reqparser = reqparse.RequestParser()
     reqparser.add_argument('uidA', type=unicode, location='json', required=True)
     reqparser.add_argument('uidB', type=unicode, location='json', required=True)
     reqparser.add_argument('comment', type=unicode, location='json', required=False)
     args = reqparser.parse_args()
     uidA = int(decode_id(args['uidA']))
     uidB = int(decode_id(args['uidB']))
     if uidB == current_user.user.id:
         st_raise_error(ErrorCode.NOT_ALLOWED_ADD_SELF)
     result = ContactRequest.add(current_user.user.id, uidA, uidB, args.get('comment'))
     if result:
         if current_user.user.id == uidA:
             message = "{}请求添加你为联系人".format(current_user.user.user_name)
         else:
             userA = User.find(uidA)
             message = "{}给你推荐了{}".format(current_user.user.user_name, userA.user_name)
         rc_service.send_system_notification(rc_service.RCSystemUser.T100001,
                                             args['uidB'], message)
     return compose_response(message="请求发送成功")
예제 #11
0
파일: api_work.py 프로젝트: dannliu/st-be
 def delete(self):
     reqparser = reqparse.RequestParser()
     reqparser.add_argument('id',
                            type=unicode,
                            location='json',
                            required=True)
     args = reqparser.parse_args()
     id = decode_id(args.get('id'))
     wks = work_service.get_work_experiences(current_user.user.id)
     if len(wks) <= 1:
         st_raise_error(ErrorCode.WORK_EXPERIENCE_CAN_NOT_BE_EXTINCT)
     work_service.delete_work_experience(current_user.user.id, id)
     return compose_response(
         result=user_service.get_login_user_profile(current_user.user.id))
예제 #12
0
 def post(self):
     reqparser = reqparse.RequestParser()
     reqparser.add_argument('uid', type=unicode, location='json', required=True)
     reqparser.add_argument('text', type=unicode, location='json', required=True)
     args = reqparser.parse_args()
     to_uid = int(decode_id(args.get('uid')))
     EndorseComment.update(to_uid, current_user.user.id, args.get('text'))
     text = args.get('text')
     if text and len(text.strip()) > 0:
         message = "你的同事{}给你做了评价".format(current_user.user.user_name)
         rc_service.send_system_notification(rc_service.RCSystemUser.T100005,
                                             args.get("uid"), message)
     profile = user_service.get_user_profile(to_uid, current_user.user.id)
     return compose_response(result=profile, message="评论成功")
예제 #13
0
 def post(self):
     """
     Update the reliability status for `uid`
     """
     reqparser = reqparse.RequestParser()
     reqparser.add_argument('uid', type=unicode, location='json', required=True)
     reqparser.add_argument('status', type=bool, location='json', required=True)
     args = reqparser.parse_args()
     to_uid = int(decode_id(args.get('uid')))
     status = args.get('status')
     if status:
         message = "你的同事{}认为你很靠谱".format(current_user.user.user_name)
         rc_service.send_system_notification(rc_service.RCSystemUser.T100004,
                                             args.get("uid"), message)
     UserEndorse.update(to_uid, current_user.user.id, EndorseType.Reliability, status)
     profile = user_service.get_user_profile(to_uid, current_user.user.id)
     return compose_response(result=profile)
예제 #14
0
파일: meida.py 프로젝트: dannliu/st-be
 def decode_id(id):
     return int(decode_id(id)[5:])
예제 #15
0
파일: acl.py 프로젝트: dannliu/st-be
 def __init__(self, **kwargs):
     self.user = User.find(decode_id(kwargs.get('user_id')))
     self.device_id = kwargs.get("device_id")