Skip to content

Commit

Permalink
Merge pull request #59 from bugout-dev/public-journals-update
Browse files Browse the repository at this point in the history
Public journals update
  • Loading branch information
kompotkot committed Feb 9, 2023
2 parents cf02199 + 34c0a54 commit b220713
Show file tree
Hide file tree
Showing 8 changed files with 454 additions and 147 deletions.
3 changes: 3 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[settings]
profile = black
multi_line_output = 3
7 changes: 4 additions & 3 deletions sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export AWS_S3_JOURNAL_SEARCH_RESULTS_BUCKET="<name of S3 bucket to write search
export AWS_S3_JOURNAL_SEARCH_RESULTS_PREFIX="<prefix to prepend to results object>"
export AWS_S3_GITHUB_SUMMARY_BUCKET="<name of S3 bucket to write locust summary object>"
export AWS_S3_GITHUB_SUMMARY_PREFIX="<prefix to prepend to results locust summary object>"
export AWS_S3_DRONES_BUCKET="<name of S3 bucket drones write to>"
export AWS_S3_DRONES_BUCKET_STATISTICS_PREFIX="<prefix to prepend to result of statistics object>"
export BUGOUT_AWS_S3_DRONES_BUCKET="<name of S3 bucket drones write to>"
export BUGOUT_AWS_S3_DRONES_BUCKET_STATISTICS_PREFIX="<prefix to prepend to result of statistics object>"
export BUGOUT_JOURNAL_EMOJI="bugout"
export BUGOUT_BACK_EMOJI="thumbsup"
export SPIRE_API_URL="https://spire.bugout.dev"
Expand All @@ -42,4 +42,5 @@ export BUGOUT_REDIS_URL="http://127.0.0.1:6379"
export BUGOUT_REDIS_PASSWORD="mypassword"
export REDIS_REPORTS_QUEUE="<redis key to humbug reports queue>"
export BUGOUT_HUMBUG_REDIS_TIMEOUT="0.5"
export BUGOUT_HUMBUG_REDIS_CONNECTIONS_PER_PROCESS="10"
export BUGOUT_HUMBUG_REDIS_CONNECTIONS_PER_PROCESS="10"
export BUGOUT_DRONES_URL="http://127.0.0.1:7476"
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,10 @@
],
"distribute": ["setuptools", "twine", "wheel"],
},
entry_points={"console_scripts": ["journals=spire.journal.cli:main"]},
entry_points={
"console_scripts": [
"journals=spire.journal.cli:main",
"public-journals=spire.public.cli:main",
]
},
)
79 changes: 64 additions & 15 deletions spire/public/actions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from typing import Any, Dict, List, Set, Optional
from uuid import UUID, uuid4
from typing import Any, Dict, List
from uuid import UUID

from sqlalchemy.orm import Session

Expand All @@ -21,28 +21,77 @@ class PublicUserNotFound(Exception):
"""


async def get_public_journal(db_session: Session, journal_id: UUID) -> PublicJournal:
entry_fields_length_limit: List[Dict[str, Any]] = [
{"name": "title", "max_length": 100},
{"name": "content", "max_length": 400},
{"name": "tags", "max_length": 5},
{"name": "context_url", "max_length": 100},
{"name": "context_id", "max_length": 40},
{"name": "context_type", "max_length": 40},
]


def create_public_journal(
db_session: Session, journal_id: UUID, user_id: UUID
) -> PublicJournal:
public_journal = PublicJournal(
journal_id=journal_id,
user_id=user_id,
)
db_session.add(public_journal)
db_session.commit()

return public_journal


def get_public_journal(db_session: Session, journal_id: UUID) -> PublicJournal:
"""
Return public journal with provided id.
"""
journal = (
public_journal = (
db_session.query(PublicJournal)
.filter(PublicJournal.journal_id == journal_id)
.one_or_none()
)
if journal is None:
raise PublicJournalNotFound(f"Did not find journals with id: {journal_id}")
if public_journal is None:
raise PublicJournalNotFound(f"Public journal with id: {journal_id} not found")

return public_journal


return journal
def delete_public_journal(
db_session: Session, public_journal: PublicJournal
) -> PublicJournal:
db_session.delete(public_journal)
db_session.commit()

return public_journal

async def get_public_user(
db_session: Session, user_id: Optional[UUID] = None
) -> PublicUser:
query = db_session.query(PublicUser)
if user_id is not None:
public_user = query.filter(PublicUser.user_id == user_id).one()
else:
public_user = query.first()

def get_public_user(db_session: Session, user_id: UUID) -> PublicUser:
"""
Search for public user in database.
"""
public_user = (
db_session.query(PublicUser).filter(PublicUser.user_id == user_id).one_or_none()
)
if public_user is None:
raise PublicUserNotFound("Public user not found")

return public_user


def get_public_journal_user(db_session: Session, journal_id: UUID) -> PublicUser:
"""
Search for public journal with user in database.
"""
public_journal_user = (
db_session.query(PublicUser)
.join(PublicJournal, PublicUser.user_id == PublicJournal.user_id)
.filter(PublicJournal.journal_id == journal_id)
.one_or_none()
)
if public_journal_user is None:
raise PublicJournalNotFound(f"Public journal with id: {journal_id} not found")

return public_journal_user
Loading

0 comments on commit b220713

Please sign in to comment.