Skip to content

[Issue 3537] save search get opp #3671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""add searched_opportunity_ids_and_last_notified_at to user_saved_opportunity

Revision ID: 9e7fc937646a
Revises: dc04ce955a9a
Create Date: 2025-01-28 19:06:19.397240

"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = "9e7fc937646a"
down_revision = "dc04ce955a9a"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"user_saved_search",
sa.Column(
"last_notified_at",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
schema="api",
)
op.add_column(
"user_saved_search",
sa.Column("searched_opportunity_ids", postgresql.ARRAY(sa.BigInteger()), nullable=False),
schema="api",
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("user_saved_search", "searched_opportunity_ids", schema="api")
op.drop_column("user_saved_search", "last_notified_at", schema="api")
# ### end Alembic commands ###
11 changes: 10 additions & 1 deletion api/src/db/models/user_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
from datetime import datetime

from sqlalchemy import BigInteger, ForeignKey
from sqlalchemy.dialects.postgresql import JSONB, UUID
from sqlalchemy.dialects.postgresql import ARRAY, JSONB, UUID
from sqlalchemy.orm import Mapped, mapped_column, relationship
from sqlalchemy.sql.functions import now as sqlnow

from src.adapters.db.type_decorators.postgres_type_decorators import LookupColumn
from src.constants.lookup_constants import ExternalUserType
from src.db.models.base import ApiSchemaTable, TimestampMixin
from src.db.models.lookup_models import LkExternalUserType
from src.db.models.opportunity_models import Opportunity
from src.util import datetime_util


class User(ApiSchemaTable, TimestampMixin):
Expand Down Expand Up @@ -102,6 +104,13 @@ class UserSavedSearch(ApiSchemaTable, TimestampMixin):

name: Mapped[str]

last_notified_at: Mapped[datetime] = mapped_column(
nullable=False,
default=datetime_util.utcnow,
server_default=sqlnow(),
)
searched_opportunity_ids: Mapped[list[int]] = mapped_column(ARRAY(BigInteger))


class UserNotificationLog(ApiSchemaTable, TimestampMixin):
__tablename__ = "user_notification_log"
Expand Down
4 changes: 4 additions & 0 deletions api/tests/src/db/models/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2047,3 +2047,7 @@ class Meta:
name = factory.Faker("sentence")

search_query = factory.LazyAttribute(lambda s: s.search_query)

last_notified_at = factory.Faker("date_time_between", start_date="-5y", end_date="-3y")

search_opportunity_ids = factory.LazyAttribute(lambda _: random.sample(range(1, 1000), 5))
Binary file modified documentation/api/database/erds/api-schema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.