Commit a740e8cf authored by Ristylou Dolar's avatar Ristylou Dolar

Added status response in utils, CRUD for services and endpoint models

parent f7da0abd
...@@ -123,3 +123,49 @@ class APIEndpointSerializer(serializers.ModelSerializer): ...@@ -123,3 +123,49 @@ class APIEndpointSerializer(serializers.ModelSerializer):
'http_method', 'endpoint_url', 'is_need_auth', 'is_active', 'created_at', 'updated_at', 'deleted_at' 'http_method', 'endpoint_url', 'is_need_auth', 'is_active', 'created_at', 'updated_at', 'deleted_at'
) )
read_only_fields = ('id', 'api_endpoint_no', 'created_at', 'updated_at', 'deleted_at') read_only_fields = ('id', 'api_endpoint_no', 'created_at', 'updated_at', 'deleted_at')
def is_valid(self, raise_exception=False):
assert not hasattr(self, 'restore_object'), (
'Serializer `%s.%s` has old-style version 2 `.restore_object()` '
'that is no longer compatible with REST framework 3. '
'Use the new-style `.create()` and `.update()` methods instead.' %
(self.__class__.__module__, self.__class__.__name__)
)
assert hasattr(self, 'initial_data'), (
'Cannot call `.is_valid()` as no `data=` keyword argument was '
'passed when instantiating the serializer instance.'
)
if not hasattr(self, '_validated_data'):
try:
self._validated_data = self.run_validation(self.initial_data)
except ValidationError as exc:
self._validated_data = {}
self._errors = exc.detail
else:
self._errors = {}
#if validation failed
if self._errors and raise_exception:
error_message = {}
message = str(self.errors)
for k, v in self.errors.items():
message = str(v)
start = message.find('string=') + 8
end = message.find(', code=') - 1
message = message[start:end]
error_message[str(k)] = message
raise BadRequestException(error_message)
return not bool(self._errors)
def create(self, validated_data):
new_endpoint = APIEndpoint.objects.create(**validated_data)
new_endpoint.api_endpoint_no = number_generator('ENP', new_endpoint.id)
new_endpoint.save()
return new_endpoint
...@@ -148,3 +148,14 @@ def number_generator(prefix, id): ...@@ -148,3 +148,14 @@ def number_generator(prefix, id):
autogenerated_no = prefix + '-' + date + '-' + id_num autogenerated_no = prefix + '-' + date + '-' + id_num
return autogenerated_no return autogenerated_no
# status message
def status_message_response(code, status, message, results):
message = {
'code': code,
'status': status,
'message': message,
'results': results
}
return message
This diff is collapsed.
...@@ -20,5 +20,5 @@ swagger = get_swagger_view(title='API Main End Point') ...@@ -20,5 +20,5 @@ swagger = get_swagger_view(title='API Main End Point')
urlpatterns = [ urlpatterns = [
path('docs/', swagger), path('docs/', swagger),
path('', include('api.urls')), path('api/v1/', include('api.urls')),
] ]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment