Skip to content

Commit

Permalink
API re-structure (#414)
Browse files Browse the repository at this point in the history
Co-authored-by: Ashwin <[email protected]>
  • Loading branch information
KingCSharp and ashwin31 committed Nov 9, 2020
1 parent b59bf50 commit 0909cd4
Show file tree
Hide file tree
Showing 10 changed files with 319 additions and 416 deletions.
7 changes: 2 additions & 5 deletions accounts/api_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
app_name = 'api_accounts'

urlpatterns = [
path("accounts-list/", api_views.AccountsListView.as_view()),
path("accounts-create/", api_views.CreateAccountView.as_view()),
path("<int:pk>/view/", api_views.AccountDetailView.as_view()),
path("accounts/<int:pk>/update/", api_views.AccountUpdateView.as_view()),
path("accounts/<int:pk>/delete/", api_views.AccountDeleteView.as_view()),
path("", api_views.AccountsListView.as_view()),
path("<int:pk>/", api_views.AccountDetailView.as_view()),
]
308 changes: 93 additions & 215 deletions accounts/api_views.py

Large diffs are not rendered by default.

60 changes: 60 additions & 0 deletions accounts/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


class TagsSerailizer(serializers.ModelSerializer):

class Meta:
model = Tags
fields = (
Expand Down Expand Up @@ -83,3 +84,62 @@ class Meta:
"contact"
"is_sent"
)


class AccountCreateSerializer(serializers.ModelSerializer):

def __init__(self, *args, **kwargs):
account_view = kwargs.pop("account", False)
request_obj = kwargs.pop("request_obj", None)
super(AccountCreateSerializer, self).__init__(*args, **kwargs)
self.fields["status"].required = False
if account_view:
self.fields["billing_address_line"].required = True
self.fields["billing_street"].required = True
self.fields["billing_city"].required = True
self.fields["billing_state"].required = True
self.fields["billing_postcode"].required = True
self.fields["billing_country"].required = True

if self.instance:
self.fields["lead"].required = False
self.fields["lead"].required = False
self.company = request_obj.company

def validate_name(self, name):
if self.instance:
if self.instance.name != name:
if not Account.objects.filter(
name__iexact=name,
company=self.company
).exists():
return name
raise serializers.ValidationError(
"Account already exists with this name")
return name
if not Account.objects.filter(
name__iexact=name,
company=self.company).exists():
return name
raise serializers.ValidationError(
"Account already exists with this name")

class Meta:
model = Account
fields = (
"name",
"phone",
"email",
"website",
"industry",
"description",
"status",
"billing_address_line",
"billing_street",
"billing_city",
"billing_state",
"billing_postcode",
"billing_country",
"lead",
"contacts",
)
2 changes: 1 addition & 1 deletion accounts/swagger_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@
required=True, type=openapi.TYPE_STRING),
]

account_delete_params = [
company_params = [
company_params_in_header,
]
23 changes: 10 additions & 13 deletions common/api_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@

urlpatterns = [
path("dashboard/", api_views.ApiHomeView.as_view()),
path("registration/", api_views.RegistrationView.as_view()),
path("login/", api_views.LoginView.as_view()),
path("validate-subdomain/", api_views.check_sub_domain),
path("auth/register/", api_views.RegistrationView.as_view()),
path("auth/login/", api_views.LoginView.as_view()),
path("auth/validate-subdomain/", api_views.check_sub_domain),
path("profile/", api_views.ProfileView.as_view()),
path("get_teams_and_users/", api_views.GetTeamsAndUsersView.as_view()),
path("change-password/", api_views.ChangePasswordView.as_view(), name="change_password"),
path("forgot-password/", api_views.ForgotPasswordView.as_view()),
path("reset-password/", api_views.ResetPasswordView.as_view(), name='reset_password'),
path("users/list/", api_views.UsersListView.as_view(), name="users_list"),
path("users/<int:pk>/view/", api_views.UserDetailView.as_view(), name="view_user"),
# path("users/create/", api_views.CreateUserView.as_view(), name="create_user"),
path("documents/create/", api_views.DocumentCreate.as_view(), name="create_doc"),
#To be checked
path("users/<int:pk>/delete/", api_views.UserDeleteView.as_view(), name="remove_user"),
path("users/get_teams_and_users/", api_views.GetTeamsAndUsersView.as_view()),
path("profile/change-password/", api_views.ChangePasswordView.as_view()),
path("auth/forgot-password/", api_views.ForgotPasswordView.as_view()),
path("auth/reset-password/", api_views.ResetPasswordView.as_view()),
path("users/", api_views.UsersListView.as_view()),
path("users/<int:pk>/", api_views.UserDetailView.as_view()),
path("documents/create/", api_views.DocumentCreate.as_view()),
]
Loading

0 comments on commit 0909cd4

Please sign in to comment.