Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a3d0eb8
first commit
matusdrobuliak66 Jan 22, 2025
393cd5c
Merge branch 'master' into fix/debt-msg
matusdrobuliak66 Jan 22, 2025
c1e21d3
openapi specs
matusdrobuliak66 Jan 22, 2025
99242cc
add migration db add user email col
matusdrobuliak66 Jan 22, 2025
250f41a
openapi specs
matusdrobuliak66 Jan 22, 2025
0165cde
add unit test
matusdrobuliak66 Jan 22, 2025
03306d5
Merge branch 'master' into fix/debt-msg
matusdrobuliak66 Jan 22, 2025
662a796
fix
matusdrobuliak66 Jan 22, 2025
e26e28d
fix
matusdrobuliak66 Jan 22, 2025
afbe8ec
Merge branch 'master' into fix/debt-msg
matusdrobuliak66 Jan 27, 2025
938d267
review @sanderegg
matusdrobuliak66 Jan 27, 2025
4963ec8
review @pcrespov
matusdrobuliak66 Jan 27, 2025
86f75c0
add comment
matusdrobuliak66 Jan 27, 2025
4a685d1
openapi specs
matusdrobuliak66 Jan 27, 2025
92ca3a0
fix tests
matusdrobuliak66 Jan 27, 2025
6e402f9
Merge branch 'master' into fix/debt-msg
matusdrobuliak66 Jan 28, 2025
21caad7
update regex
odeimaiz Jan 28, 2025
3588ae6
getAllPages
odeimaiz Jan 28, 2025
2ff9021
adminPricingPlans & pricingPlans
odeimaiz Jan 28, 2025
8e35c0d
minor
odeimaiz Jan 28, 2025
b2c0daa
Merge pull request #5 from odeimaiz/matusdrobuliak66-fix/debt-msg
matusdrobuliak66 Jan 28, 2025
45be582
Merge branch 'master' into fix/debt-msg
matusdrobuliak66 Jan 28, 2025
cddb7cc
fix
matusdrobuliak66 Jan 28, 2025
dca94a8
Merge branch 'master' into fix/debt-msg
matusdrobuliak66 Jan 28, 2025
ee53789
Merge branch 'master' into fix/debt-msg
matusdrobuliak66 Jan 28, 2025
493e24f
fix issue with publishing
matusdrobuliak66 Jan 28, 2025
2c97c52
Merge branch 'fix/debt-msg' of github.com:matusdrobuliak66/osparc-sim…
matusdrobuliak66 Jan 28, 2025
d911b4c
Merge branch 'master' into fix/debt-msg
matusdrobuliak66 Jan 28, 2025
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
53 changes: 35 additions & 18 deletions api/specs/web-server/_resource_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
CreatePricingPlanBodyParams,
CreatePricingUnitBodyParams,
PricingPlanAdminGet,
PricingPlanGet,
PricingPlanToServiceAdminGet,
PricingUnitAdminGet,
PricingUnitGet,
Expand All @@ -29,15 +30,16 @@
UpdatePricingUnitBodyParams,
)
from models_library.generics import Envelope
from models_library.rest_pagination import Page, PageQueryParameters
from simcore_service_webserver._meta import API_VTAG
from simcore_service_webserver.resource_usage._pricing_plans_admin_handlers import (
from simcore_service_webserver.resource_usage._pricing_plans_admin_rest import (
PricingPlanGetPathParams,
PricingUnitGetPathParams,
)
from simcore_service_webserver.resource_usage._pricing_plans_handlers import (
from simcore_service_webserver.resource_usage._pricing_plans_rest import (
PricingPlanUnitGetPathParams,
)
from simcore_service_webserver.resource_usage._service_runs_handlers import (
from simcore_service_webserver.resource_usage._service_runs_rest import (
ServicesAggregatedUsagesListQueryParams,
ServicesResourceUsagesListQueryParams,
ServicesResourceUsagesReportQueryParams,
Expand All @@ -48,7 +50,7 @@

@router.get(
"/services/-/resource-usages",
response_model=Envelope[list[ServiceRunGet]],
response_model=Page[ServiceRunGet],
summary="Retrieve finished and currently running user services"
" (user and product are taken from context, optionally wallet_id parameter might be provided).",
tags=["usage"],
Expand All @@ -61,7 +63,7 @@ async def list_resource_usage_services(

@router.get(
"/services/-/aggregated-usages",
response_model=Envelope[list[OsparcCreditsAggregatedByServiceGet]],
response_model=Page[OsparcCreditsAggregatedByServiceGet],
summary="Used credits based on aggregate by type, currently supported `services`"
". (user and product are taken from context, optionally wallet_id parameter might be provided).",
tags=["usage"],
Expand Down Expand Up @@ -93,7 +95,6 @@ async def export_resource_usage_services(
@router.get(
"/pricing-plans/{pricing_plan_id}/pricing-units/{pricing_unit_id}",
response_model=Envelope[PricingUnitGet],
summary="Retrieve detail information about pricing unit",
tags=["pricing-plans"],
)
async def get_pricing_plan_unit(
Expand All @@ -102,27 +103,50 @@ async def get_pricing_plan_unit(
...


@router.get(
"/pricing-plans",
response_model=Page[PricingPlanGet],
tags=["pricing-plans"],
description="To keep the listing lightweight, the pricingUnits field is None.",
)
async def list_pricing_plans(
_query: Annotated[as_query(PageQueryParameters), Depends()]
):
...


@router.get(
"/pricing-plans/{pricing_plan_id}",
response_model=Envelope[PricingPlanGet],
tags=["pricing-plans"],
)
async def get_pricing_plan(
_path: Annotated[PricingPlanGetPathParams, Depends()],
):
...


## Pricing plans for Admin panel


@router.get(
"/admin/pricing-plans",
response_model=Envelope[list[PricingPlanAdminGet]],
summary="List pricing plans",
response_model=Page[PricingPlanAdminGet],
tags=["admin"],
description="To keep the listing lightweight, the pricingUnits field is None.",
)
async def list_pricing_plans():
async def list_pricing_plans_for_admin_user(
_query: Annotated[as_query(PageQueryParameters), Depends()]
):
...


@router.get(
"/admin/pricing-plans/{pricing_plan_id}",
response_model=Envelope[PricingPlanAdminGet],
summary="Retrieve detail information about pricing plan",
tags=["admin"],
)
async def get_pricing_plan(
async def get_pricing_plan_for_admin_user(
_path: Annotated[PricingPlanGetPathParams, Depends()],
):
...
Expand All @@ -131,7 +155,6 @@ async def get_pricing_plan(
@router.post(
"/admin/pricing-plans",
response_model=Envelope[PricingPlanAdminGet],
summary="Create pricing plan",
tags=["admin"],
)
async def create_pricing_plan(
Expand All @@ -143,7 +166,6 @@ async def create_pricing_plan(
@router.put(
"/admin/pricing-plans/{pricing_plan_id}",
response_model=Envelope[PricingPlanAdminGet],
summary="Update detail information about pricing plan",
tags=["admin"],
)
async def update_pricing_plan(
Expand All @@ -159,7 +181,6 @@ async def update_pricing_plan(
@router.get(
"/admin/pricing-plans/{pricing_plan_id}/pricing-units/{pricing_unit_id}",
response_model=Envelope[PricingUnitAdminGet],
summary="Retrieve detail information about pricing unit",
tags=["admin"],
)
async def get_pricing_unit(
Expand All @@ -171,7 +192,6 @@ async def get_pricing_unit(
@router.post(
"/admin/pricing-plans/{pricing_plan_id}/pricing-units",
response_model=Envelope[PricingUnitAdminGet],
summary="Create pricing unit",
tags=["admin"],
)
async def create_pricing_unit(
Expand All @@ -184,7 +204,6 @@ async def create_pricing_unit(
@router.put(
"/admin/pricing-plans/{pricing_plan_id}/pricing-units/{pricing_unit_id}",
response_model=Envelope[PricingUnitAdminGet],
summary="Update detail information about pricing plan",
tags=["admin"],
)
async def update_pricing_unit(
Expand All @@ -200,7 +219,6 @@ async def update_pricing_unit(
@router.get(
"/admin/pricing-plans/{pricing_plan_id}/billable-services",
response_model=Envelope[list[PricingPlanToServiceAdminGet]],
summary="List services that are connected to the provided pricing plan",
tags=["admin"],
)
async def list_connected_services_to_pricing_plan(
Expand All @@ -212,7 +230,6 @@ async def list_connected_services_to_pricing_plan(
@router.post(
"/admin/pricing-plans/{pricing_plan_id}/billable-services",
response_model=Envelope[PricingPlanToServiceAdminGet],
summary="Connect service with pricing plan",
tags=["admin"],
)
async def connect_service_to_pricing_plan(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class LicensedItemCheckoutGet(BaseModel):
licensed_item_id: LicensedItemID
wallet_id: WalletID
user_id: UserID
user_email: str
product_name: ProductName
service_run_id: ServiceRunID
started_at: datetime
Expand All @@ -31,6 +32,7 @@ class LicensedItemCheckoutGet(BaseModel):
"licensed_item_id": "303942ef-6d31-4ba8-afbe-dbb1fce2a953",
"wallet_id": 1,
"user_id": 1,
"user_email": "[email protected]",
"product_name": "osparc",
"service_run_id": "run_1",
"started_at": "2023-01-11 13:11:47.293595",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class LicensedItemPurchaseGet(BaseModel):
expire_at: datetime
num_of_seats: int
purchased_by_user: UserID
user_email: str
purchased_at: datetime
modified: datetime

Expand All @@ -43,6 +44,7 @@ class LicensedItemPurchaseGet(BaseModel):
"expire_at": "2023-01-11 13:11:47.293595",
"num_of_seats": 1,
"purchased_by_user": 1,
"user_email": "[email protected]",
"purchased_at": "2023-01-11 13:11:47.293595",
"modified": "2023-01-11 13:11:47.293595",
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from datetime import datetime
from decimal import Decimal
from typing import NamedTuple

from pydantic import BaseModel, ConfigDict
from pydantic import BaseModel, ConfigDict, PositiveInt

from ..resource_tracker import (
HardwareInfo,
Expand Down Expand Up @@ -76,6 +77,11 @@ class PricingPlanGet(BaseModel):
)


class PricingPlanPage(NamedTuple):
items: list[PricingPlanGet]
total: PositiveInt


class PricingPlanToServiceGet(BaseModel):
pricing_plan_id: PricingPlanId
service_key: ServiceKey
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime
from typing import NamedTuple

from models_library.emails import LowerCaseEmailStr
from pydantic import BaseModel, ConfigDict, PositiveInt

from ..licensed_items import LicensedItemID
Expand Down Expand Up @@ -53,6 +54,7 @@ class LicensedItemCheckoutRestGet(OutputSchema):
licensed_item_id: LicensedItemID
wallet_id: WalletID
user_id: UserID
user_email: LowerCaseEmailStr
product_name: ProductName
started_at: datetime
stopped_at: datetime | None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from decimal import Decimal
from typing import NamedTuple

from models_library.emails import LowerCaseEmailStr
from pydantic import PositiveInt

from ..licensed_items import LicensedItemID
Expand All @@ -24,6 +25,7 @@ class LicensedItemPurchaseGet(OutputSchema):
expire_at: datetime
num_of_seats: int
purchased_by_user: UserID
user_email: LowerCaseEmailStr
purchased_at: datetime
modified_at: datetime

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class PricingPlanGet(OutputSchema):
classification: PricingPlanClassification
created_at: datetime
pricing_plan_key: str
pricing_units: list[PricingUnitGet]
pricing_units: list[PricingUnitGet] | None
is_active: bool


Expand All @@ -78,7 +78,7 @@ class PricingPlanAdminGet(OutputSchema):
classification: PricingPlanClassification
created_at: datetime
pricing_plan_key: str
pricing_units: list[PricingUnitGet] | None
pricing_units: list[PricingUnitAdminGet] | None
is_active: bool


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""add user email col to purchases

Revision ID: 5f88b513cd4c
Revises: ecd4eadaa781
Create Date: 2025-01-22 15:08:17.729337+00:00

"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "5f88b513cd4c"
down_revision = "ecd4eadaa781"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"resource_tracker_licensed_items_purchases",
sa.Column("user_email", sa.String(), nullable=True),
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("resource_tracker_licensed_items_purchases", "user_email")
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
sa.BigInteger,
nullable=False,
),
sa.Column(
"user_email",
sa.String,
nullable=True,
),
sa.Column(
"purchased_at",
sa.DateTime(timezone=True),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
)
from models_library.api_schemas_resource_usage_tracker.pricing_plans import (
PricingPlanGet,
PricingPlanPage,
PricingPlanToServiceGet,
)
from models_library.products import ProductName
Expand Down Expand Up @@ -52,14 +53,21 @@ async def list_pricing_plans(
rabbitmq_rpc_client: RabbitMQRPCClient,
*,
product_name: ProductName,
) -> list[PricingPlanGet]:
result: PricingPlanGet = await rabbitmq_rpc_client.request(
exclude_inactive: bool = True,
# pagination
offset: int = 0,
limit: int = 20,
) -> PricingPlanPage:
result = await rabbitmq_rpc_client.request(
RESOURCE_USAGE_TRACKER_RPC_NAMESPACE,
_RPC_METHOD_NAME_ADAPTER.validate_python("list_pricing_plans"),
product_name=product_name,
exclude_inactive=exclude_inactive,
offset=offset,
limit=limit,
timeout_s=_DEFAULT_TIMEOUT_S,
)
assert isinstance(result, list) # nosec
assert isinstance(result, PricingPlanPage) # nosec
return result


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from fastapi import FastAPI
from models_library.api_schemas_resource_usage_tracker.pricing_plans import (
PricingPlanGet,
PricingPlanPage,
PricingPlanToServiceGet,
PricingUnitGet,
)
Expand Down Expand Up @@ -43,10 +44,17 @@ async def list_pricing_plans(
app: FastAPI,
*,
product_name: ProductName,
) -> list[PricingPlanGet]:
exclude_inactive: bool,
# pagination
offset: int,
limit: int,
) -> PricingPlanPage:
return await pricing_plans.list_pricing_plans_by_product(
product_name=product_name,
db_engine=app.state.engine,
product_name=product_name,
exclude_inactive=exclude_inactive,
offset=offset,
limit=limit,
)


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime
from decimal import Decimal

from models_library.emails import LowerCaseEmailStr
from models_library.licensed_items import LicensedItemID
from models_library.products import ProductName
from models_library.resource_tracker import PricingUnitCostId
Expand All @@ -24,6 +25,7 @@ class LicensedItemsPurchasesDB(BaseModel):
expire_at: datetime
num_of_seats: int
purchased_by_user: UserID
user_email: LowerCaseEmailStr
purchased_at: datetime
modified: datetime

Expand All @@ -41,6 +43,7 @@ class CreateLicensedItemsPurchasesDB(BaseModel):
expire_at: datetime
num_of_seats: int
purchased_by_user: UserID
user_email: LowerCaseEmailStr
purchased_at: datetime

model_config = ConfigDict(from_attributes=True)
Loading
Loading