1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-25 22:44:19 +00:00

Repository filtering

Now the API can be asked to give only active repos or closed ones (or both).
This commit is contained in:
Lorenzo Balugani 2021-04-26 18:51:32 +02:00
parent 6d512c3abe
commit 5d45d0904c
2 changed files with 16 additions and 3 deletions

View file

@ -22,4 +22,5 @@ class Repository(Base.Model):
uses = Base.relationship("Uses", back_populates="repository") uses = Base.relationship("Uses", back_populates="repository")
def to_json(self): def to_json(self):
return {"id": self.id, "name": self.name, "start": self.start.isoformat(), "owner": self.owner.to_json()} return {"id": self.id, "name": self.name, "start": self.start.isoformat(), "isActive":self.isActive,
"end":self.end.isoformat(),"owner": self.owner.to_json()}

View file

@ -10,9 +10,21 @@ from flask_cors import cross_origin
def page_repository_list(): def page_repository_list():
""" """
API call that returns the list of repositories. API call that returns the list of repositories.
:parameter onlyActive: if present, only active repos are provided
:parameter onlyDead: if present, only dead repos are provided
:returns: a JSON-formatted string that contains under the "content" field the list of repositories that belong to :returns: a JSON-formatted string that contains under the "content" field the list of repositories that belong to
the user ("owner") and a list of repositories that he can spectate ("spectator"). the user ("owner") and a list of repositories that he can spectate ("spectator").
""" """
user = find_user(get_jwt_identity()) user = find_user(get_jwt_identity())
return json_success({"owner": [r.to_json() for r in user.owner_of], owner = Repository.query.filter_by(owner_id=user.email)
"spectator": [r.repository.to_json() for r in user.authorizations]}) spectator = Authorization.query.filter_by(email=user.email).join(Repository)
if request.json.get("onlyActive"):
owner = owner.filter_by(isActive=True)
spectator = spectator.filter(Repository.isActive == True)
elif request.json.get("onlyDead"):
owner = owner.filter_by(isActive=False)
spectator = spectator.filter(Repository.isActive == False)
owner = owner.all()
spectator = spectator.all()
return json_success({"owner": [r.to_json() for r in owner],
"spectator": [r.repository.to_json() for r in spectator]})