예제 #1
0
 def select_comment_byKeyword(self, keyword: str) -> list:
     responds = list()
     sql = "SELECT *  FROM `comment` WHERE"
     agrs = list()
     for idx, k in enumerate(keyword.split(" ")):
         if idx != 0:
             sql += " OR "
         sql += " `classN` LIKE %s OR `teacherN` LIKE %s OR `major` LIKE %s OR `say` LIKE %s "
         agrs.extend(["%" + k + "%"] * 4)
     sql += "ORDER BY `comment_id`  DESC"
     results = self.exe(sql=sql, agrs=tuple(agrs))
     for result in results:
         Commentobj = Comment(comment_id=result[0],
                              object_type=result[13],
                              class_name=result[1],
                              teacher_name=result[2],
                              user_memo=result[6],
                              major=result[3],
                              midexam=result[4],
                              endexam=result[5],
                              value=result[7],
                              cost=result[8],
                              classcall=result[9],
                              homework=result[10],
                              classexam=result[11])
         responds.append(Commentobj.to_dict())
     return responds
예제 #2
0
def new_reply_with_array_obj_input(body):  # noqa: E501
    # 拒絕非認證的來源 refuse user or origin
    Origin = connexion.request.headers["Sec-Fetch-Site"] if "Sec-Fetch-Site" in connexion.request.headers else \
    connexion.request.headers["Origin"] if "Origin" in connexion.request.headers else None
    if Origin != "same-site" and Origin != "same-origin" and Origin != "https://goodclass.cf":
        return {"ERROR": "Unauthorized USER"}, 401, header

    if connexion.request.is_json:
        body_json = connexion.request.get_json()
        body = Comment.from_dict(body_json)  # noqa: E501
        try:
            c = operation()
            comment_id = body_json['comment_id']
            user_memo = body_json['user_memo']

            _ = c.new_reply_byid(comment_id=comment_id, user_memo=user_memo)

            return Message(msg="ok").to_dict(), 200, header
        except Exception as e:
            return Message(
                request_status="error",
                msg="UNKNOWERROR: {}".format(e)).to_dict(), 200, header
    else:
        error_msg = Message(request_status="error",
                            msg="connexion.request.is_json")
        return error_msg.to_dict(), 500, header
예제 #3
0
    def test_add_com(self):
        """Test case for add_com

        Dodaj novi komentar
        """
        body = Comment()
        response = self.client.open('/v2/comment',
                                    method='POST',
                                    data=json.dumps(body),
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
예제 #4
0
 def select_comment_byNewest(self, start_num=0, num=30) -> list:
     responds = list()
     sql = "SELECT * FROM `comment` ORDER BY `comment_id` DESC limit %s,%s"
     agrs = [start_num, start_num + num]
     results = self.exe(sql=sql, agrs=tuple(agrs))
     for result in results:
         Commentobj = Comment(comment_id=result[0],
                              object_type=result[13],
                              class_name=result[1],
                              teacher_name=result[2],
                              user_memo=result[6],
                              major=result[3],
                              midexam=result[4],
                              endexam=result[5],
                              value=result[7],
                              cost=result[8],
                              classcall=result[9],
                              homework=result[10],
                              classexam=result[11])
         responds.append(Commentobj.to_dict())
     return responds
예제 #5
0
def add_com(body):  # noqa: E501
    """Dodaj novi komentar

     # noqa: E501

    :param body: Objekat za komentar koji treba da se doda u bazu
    :type body: dict | bytes

    :rtype: None
    """
    if connexion.request.is_json:
        body = Comment.from_dict(connexion.request.get_json())  # noqa: E501
    return 'do some magic!'
def projects_id_comments_put(id, project):
    """
    You can't put the entire List
    
    :param id: Project id
    :type id: int
    :param project: The comment you want to update
    :type project: dict | bytes

    :rtype: None
    """
    if connexion.request.is_json:
        project = Comment.from_dict(connexion.request.get_json())
    return 'do some magic!'
def projects_id_comments_post(id, project):
    """
    Create a new comment
    
    :param id: Project id
    :type id: int
    :param project: The comment you want to create
    :type project: dict | bytes

    :rtype: Message
    """
    if connexion.request.is_json:
        project = Comment.from_dict(connexion.request.get_json())
    return 'do some magic!'
    def test_projects_id_comments_put(self):
        """
        Test case for projects_id_comments_put

        You can't put the entire List
        """
        project = Comment()
        response = self.client.open(
            '/project-tracker/projects/{id}/comments'.format(id=56),
            method='PUT',
            data=json.dumps(project),
            content_type='application/json')
        self.assert200(response,
                       "Response body is : " + response.data.decode('utf-8'))
def new_class_with_array_obj_input(body):  # noqa: E501
    # 拒絕非認證的來源 refuse user or origin
    Origin = connexion.request.headers["Sec-Fetch-Site"] if "Sec-Fetch-Site" in connexion.request.headers else \
    connexion.request.headers["Origin"] if "Origin" in connexion.request.headers else None
    if Origin != "same-site" and Origin != "same-origin" and Origin != "https://goodclass.cf":
        return {"ERROR": "Unauthorized USER"}, 401, header
    """Info of class

     # noqa: E501

    :param body: Pet object that needs to be added to the store
    :type body: dict | bytes

    :rtype: object
    """
    if connexion.request.is_json:
        body_json = connexion.request.get_json()
        body = Comment.from_dict(body_json)  # noqa: E501
        try:
            c = comment_operation()
            major = body_json[
                'major'] if 'major' in body_json else "這傢伙很懶,什麼都沒有寫"
            midexam = body_json[
                'midexam'] if 'midexam' in body_json else "這傢伙很懶,什麼都沒有寫"
            endexam = body_json[
                'endexam'] if 'endexam' in body_json else "這傢伙很懶,什麼都沒有寫"
            value = body_json[
                'value'] if 'value' in body_json else "這傢伙很懶,什麼都沒有寫"
            cost = body_json['cost'] if 'cost' in body_json else "這傢伙很懶,什麼都沒有寫"
            classcall = body_json[
                'classcall'] if 'classcall' in body_json else 2
            homework = body_json['homework'] if 'homework' in body_json else 2
            classexam = body_json[
                'classexam'] if 'classexam' in body_json else 2
            _ = c.new_comment_byid(body.class_name, body.teacher_name, major,
                                   midexam, endexam, body.user_memo, value,
                                   cost, classcall, homework, classexam)

            return Message(msg="ok").to_dict(), 200, header
        except Exception as e:
            return Message(
                request_status="error",
                msg="UNKNOWERROR: {}".format(e)).to_dict(), 200, header
    else:
        error_msg = Message(request_status="error",
                            msg="connexion.request.is_json")
        return error_msg.to_dict(), 500, header
예제 #10
0
    def select_comment_byid(self, comment_id=1) -> Comment:
        sql = "SELECT * FROM `comment` WHERE `comment_id` = %s"
        agrs = [comment_id]
        result = self.exe(sql=sql, agrs=tuple(agrs))[0]
        Commentobj = Comment(comment_id=result[0],
                             object_type=result[13],
                             class_name=result[1],
                             teacher_name=result[2],
                             user_memo=result[6],
                             major=result[3],
                             midexam=result[4],
                             endexam=result[5],
                             value=result[7],
                             cost=result[8],
                             classcall=result[9],
                             homework=result[10],
                             classexam=result[11])

        return Commentobj
def update_class_with_array_obj_input(body):  # noqa: E501
    # 拒絕非認證的來源 refuse user or origin
    Origin = connexion.request.headers["Sec-Fetch-Site"] if "Sec-Fetch-Site" in connexion.request.headers else \
    connexion.request.headers["Origin"] if "Origin" in connexion.request.headers else None
    if Origin != "same-site" and Origin != "same-origin" and Origin != "https://goodclass.cf":
        return {"ERROR": "Unauthorized USER"}, 401, header
    """Info of class

     # noqa: E501

    :param body: Pet object that needs to be added to the store
    :type body: dict | bytes

    :rtype: object
    """
    if connexion.request.is_json:
        body = Comment.from_dict(connexion.request.get_json())  # noqa: E501
        return body, 200, header
    else:
        error_msg = Message(request_status="error",
                            msg="connexion.request.is_json")
        return error_msg.to_dict(), 500, header
from swagger_server.models.comment import Comment

a = Comment(comment_id=1,
            object_type="normal",
            class_name="中文課",
            teacher_name="鍾老師",
            user_memo="超過100分")
print(a.to_dict())