Code Monkey home page Code Monkey logo

Comments (3)

thomaxxl avatar thomaxxl commented on August 13, 2024

Hi,

Can you be a bit more precies please? I don't understand what exactly you are trying to achieve.

from safrs.

NexPlex avatar NexPlex commented on August 13, 2024

Here is a Pseudocode example

  1. User (client API) supplies client_Id and client_secret and receives a token
  2. The user does a GET (using token) on TceContacts or TceContactsHst. The Get needs to have a filter something like this filter_by(User.client_id = token_user)
db.session.query(TceContacts).join(TceCampaign).join(User).filter_by(client_id = token_user).all()
  1. The user does a POST (using token) to TceContacts. The value in TceContacts.campId must exist in TceCampaign.id (foreign key constraint) filter_by(User.client_id = token_user)
db.session.query(TceContacts).join(TceCampaign).join(User).filter_by(client_id = token_user).all()

class Base(SAFRSBase, db.Model):
    __abstract__ = True
    id = db.Column(Integer, nullable=False, primary_key=True)
    created_at = db.Column(db.DateTime, default=db.func.current_timestamp())
    modified_at = db.Column(db.DateTime,
                            default=db.func.current_timestamp(),
                            onupdate=db.func.current_timestamp())
    active = db.Column(db.Boolean(), default=True)


class User(Base):
    __tablename__ = 'user'

    client_id = Column(String(100))
    client_secret = Column(String(100))
    firstName = Column(String(145))
    lastName = Column(String(145))
    address = Column(String(45))

    tceCampaign = relationship("TceCampaign", back_populates="user")

class TceCampaign(Base):
    __tablename__ = 'tceCampaign'

    userId = Column(Integer, ForeignKey('user.id'))
    name = Column(String(100))
    dailyStartTime = Column(Time)
    dailyEndTime = Column(Time)
    startDays = Column(Integer)

    user = relationship("User", back_populates="tceCampaign")
    tceContacts = relationship("TceContacts", back_populates="tceCampaign", cascade="all,delete")

class TceContacts(Base):

    __tablename__ = 'tceContacts'

    http_methods = ["get", 'POST']
    exclude_rels = ["tceCampRun"]
    custom_decorators = [jwt_required, test_dec]

    campId = Column(ForeignKey(u'tceCamp.id', ondelete=u'CASCADE'), index=True)
    firstName = Column(String(145))
    lastName = Column(String(145))

    tceCampaign = relationship(u'TceCampaign', back_populates="tceContacts")

class TceContactsHst(Base):
    __tablename__ = 'tceContactsHst'

    http_methods = ["get"]
    custom_decorators = [jwt_required, test_dec]

    contactsId = Column(ForeignKey(u'tceContacts.id'), index=True)
    runStatus = Column(String(45))
    processId = Column(Integer)
    process = Column(String(45))
    rate = Column(Numeric(6, 4))

    tceContacts = relationship(u'TceContacts')

from safrs.

thomaxxl avatar thomaxxl commented on August 13, 2024

Hi,

you can create a custom filter, e.g.:

class User(SAFRSBase, db.Model):

    id = db.Column(String, primary_key=True)
    username = db.Column(db.String(32))

    @classmethod
    def filter(cls, *args, **kwargs):
        print(args, kwargs) # args[0] should contain the filter= url query parameter value
        return cls.query.filter_by(username = args[0])

This filter will be called when you provide ?filter=user2
I hope this helps?

from safrs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.