add get and patch operations
This commit is contained in:
parent
7c7f315e52
commit
a4850683c9
3 changed files with 72 additions and 2 deletions
|
@ -8,7 +8,11 @@ from django.shortcuts import get_object_or_404
|
|||
from hub.services.models import Lead
|
||||
from hub.services.odoo import OdooAPI
|
||||
from .models import ServiceInstance, ServiceBrokerUser
|
||||
from .serializers import ServiceInstanceProvisioningSerializer, CatalogSerializer
|
||||
from .serializers import (
|
||||
ServiceInstanceProvisioningSerializer,
|
||||
CatalogSerializer,
|
||||
ServiceInstanceUpdateSerializer,
|
||||
)
|
||||
from .authentication import ServiceBrokerAuthentication
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -137,3 +141,48 @@ class ServiceBrokerViewSet(viewsets.ViewSet):
|
|||
instance = get_object_or_404(ServiceInstance, instance_id=instance_id)
|
||||
instance.delete()
|
||||
return Response(status=status.HTTP_200_OK)
|
||||
|
||||
@action(
|
||||
detail=False,
|
||||
methods=["get"],
|
||||
url_path="service_instances/(?P<instance_id>[^/.]+)",
|
||||
)
|
||||
def get_instance(self, request, instance_id):
|
||||
instance = get_object_or_404(ServiceInstance, instance_id=instance_id)
|
||||
return Response(
|
||||
{
|
||||
"service_id": str(instance.offering.id),
|
||||
"plan_id": str(instance.plan.id),
|
||||
"dashboard_url": settings.WEBSITE_URL
|
||||
+ reverse(
|
||||
"services:offering_detail", kwargs={"slug": instance.offering.slug}
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
@action(
|
||||
detail=False,
|
||||
methods=["patch"],
|
||||
url_path="service_instances/(?P<instance_id>[^/.]+)",
|
||||
)
|
||||
def update_instance(self, request, instance_id):
|
||||
instance = get_object_or_404(ServiceInstance, instance_id=instance_id)
|
||||
serializer = ServiceInstanceUpdateSerializer(
|
||||
data=request.data, context={"instance": instance}
|
||||
)
|
||||
|
||||
if not serializer.is_valid():
|
||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
instance.plan = serializer.validated_data["plan_id"]
|
||||
instance.save()
|
||||
|
||||
return Response(
|
||||
{
|
||||
"operation": "update",
|
||||
"dashboard_url": settings.WEBSITE_URL
|
||||
+ reverse(
|
||||
"services:offering_detail", kwargs={"slug": instance.offering.slug}
|
||||
),
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue