Beispiel #1
0
    def insert_board_column(self, board_column: BoardColumn) -> ItemResp:
        sql_board_column = board_column_to_db(board_column)

        try:
            self.session.add(sql_board_column)
            self.session.commit()
        except IntegrityError:
            return ItemResp(status=HttpStatus.CONFLICT, errors=[])

        board_column = db_to_board_column(sql_board_column)
        return ItemResp(item=board_column)
Beispiel #2
0
    def insert_ticket(self, ticket: Ticket) -> ItemResp:
        sql_ticket = ticket_to_db(ticket)

        try:
            self.session.add(sql_ticket)
            self.session.commit()
        except IntegrityError:
            return ItemResp(status=HttpStatus.CONFLICT, errors=[])

        ticket = db_to_ticket(sql_ticket)
        return ItemResp(item=ticket)
Beispiel #3
0
    def delete_board_column(self, id: int) -> ItemResp:
        db_board_column = self.session.query(SQLBoardColumn).get(id)
        if not db_board_column:
            return ItemResp(status=HttpStatus.NOT_FOUND)

        try:
            self.session.delete(db_board_column)
            self.session.commit()
        except IntegrityError:
            return ItemResp(status=HttpStatus.CONFLICT)

        return ItemResp()
Beispiel #4
0
    def delete_ticket(self, id: int) -> ItemResp:
        db_ticket = self.session.query(SQLTicket).get(id)
        if not db_ticket:
            return ItemResp(status=HttpStatus.NOT_FOUND)

        try:
            self.session.delete(db_ticket)
            self.session.commit()
        except IntegrityError:
            return ItemResp(status=HttpStatus.CONFLICT)

        return ItemResp()
Beispiel #5
0
def handle_validations(
    fields_validations: List[FieldError] = [],
    bussiness_validations: List[FieldError] = [],
) -> ItemResp:
    errors = []

    if fields_validations:
        errors.extend(make_errors_from_validations_resp(fields_validations))

    if not errors and bussiness_validations:
        errors.extend(make_errors_from_validations_resp(bussiness_validations))

    return (ItemResp(status=HttpStatus.OK) if not errors else ItemResp(
        status=HttpStatus.BAD_REQUEST, errors=errors))
Beispiel #6
0
    def update_board(self, board: Board) -> ItemResp:
        db_board = board_to_db(board)

        try:
            self.session.query(SQLBoard).filter_by(id=board.id).update({
                "title":
                db_board.title,
                "updated_at":
                db_board.updated_at
            })
            self.session.commit()
        except IntegrityError:
            return ItemResp(status=HttpStatus.CONFLICT, errors=[])

        return ItemResp(item=board)
Beispiel #7
0
    def update_board_column(self, board_column: BoardColumn) -> ItemResp:
        db_board_column = board_column_to_db(board_column)

        try:
            self.session.query(SQLBoardColumn).filter_by(
                id=board_column.id).update({
                    "name":
                    db_board_column.name,
                    "updated_at":
                    db_board_column.updated_at,
                })
            self.session.commit()
        except IntegrityError:
            return ItemResp(status=HttpStatus.CONFLICT, errors=[])

        return ItemResp(item=board_column)
Beispiel #8
0
    def update_ticket(self, ticket: Ticket) -> ItemResp:
        db_ticket = ticket_to_db(ticket)

        try:
            self.session.query(SQLTicket).filter_by(id=ticket.id).update({
                "title":
                db_ticket.title,
                "description":
                db_ticket.description,
                "priority":
                db_ticket.priority,
                "labels":
                db_ticket.labels,
                "updated_at":
                db_ticket.updated_at,
            })
            self.session.commit()
        except IntegrityError:
            return ItemResp(status=HttpStatus.CONFLICT, errors=[])

        return ItemResp(item=ticket)
    def update_board_column(self, req: UpdateBoardColumn):
        if bussiness.validate_board_existence(req.board_id, self.boards_uc):
            return ItemResp(status=HttpStatus.NOT_FOUND)

        resp = self.repo.get_board_column_by_id(id=req.id)
        if not resp.item:
            return resp
        board_column = resp.item

        resp = handle_validations(
            fields_validations=[validations.validate_name(req.name)], )
        if not resp.is_ok:
            return resp

        updated_at = datetime.now()

        board_column = BoardColumn(
            id=req.id,
            board_id=board_column.board_id,
            name=req.name,
            created_at=board_column.created_at,
            updated_at=updated_at,
        )
        return self.repo.update_board_column(board_column)
Beispiel #10
0
    def get_board_column_by_id(self, id: int) -> ItemResp:
        db_board_column = self.session.query(SQLBoardColumn).get(id)
        if not db_board_column:
            return ItemResp(status=HttpStatus.NOT_FOUND)

        return ItemResp(item=db_to_board_column(db_board_column))
Beispiel #11
0
    def get_ticket_by_id(self, id: int) -> ItemResp:
        db_ticket = self.session.query(SQLTicket).get(id)
        if not db_ticket:
            return ItemResp(status=HttpStatus.NOT_FOUND)

        return ItemResp(item=db_to_ticket(db_ticket))