Skip to content
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

Events API #628 #760

Closed
wants to merge 2 commits into from
Closed

Events API #628 #760

wants to merge 2 commits into from

Conversation

josueemartinezz
Copy link

@josueemartinezz josueemartinezz commented Mar 13, 2024

Contributor checklist


Description

  • Added (list, create, retrieve, update, partial_update, destroy) HTTP methods for Events. Ensured event creators are admin associated within their organization.
  • Modified serializers to validate non-trivial input. Trivial validation checks are removed as they're ensured by the model setup.
  • Added missing fields for the Event model (according to Figma designs)

TESTING

  • Extensive testing was done on the backend to ensure the model catches bad user input to eliminate validation checks done in serializers.
  • Verified that upon organization creation, an organization admin member is allowed to create an event whereas if is_admin is false, HTTP responds appropriately.

NOTE:

  • breaks might occur as during the testing stage I would receive independent errors coming from authentication and organization models. However, @andrewtavis confirmed to leave these model definitions as they are after manipulating them.

Related issue

Copy link
Contributor

github-actions bot commented Mar 13, 2024

Thank you for the pull request!

The activist team will do our best to address your contribution as soon as we can. The following is a checklist for maintainers to make sure this process goes as well as possible. Feel free to address the points below yourself in further commits if you realize that actions are needed :)

If you're not already a member of our public Matrix community, please consider joining! We'd suggest using Element as your Matrix client, and definitely join the General and Development rooms once you're in. It'd be great to have you!

Maintainer checklist

  • The commit messages for the remote branch should be checked to make sure the contributor's email is set up correctly so that they receive credit for their contribution

    • The contributor's name and icon in remote commits should be the same as what appears in the PR
    • If there's a mismatch, the contributor needs to make sure that the email they use for GitHub matches what they have for git config user.email in their local activist repo
  • The TypeScript and formatting workflows within the PR checks do not indicate new errors in the files changed

  • The CHANGELOG has been updated with a description of the changes for the upcoming release and the corresponding issue (if necessary)

Copy link

netlify bot commented Mar 13, 2024

Deploy Preview for activist-org ready!

Name Link
🔨 Latest commit b513a1e
🔍 Latest deploy log https://app.netlify.com/sites/activist-org/deploys/65ff067cb99a090007c86753
😎 Deploy Preview https://deploy-preview-760--activist-org.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@andrewtavis
Copy link
Member

Thanks for the hard work here, @josueemartinezz! As an initial check on all of this, would you want to go through the backend check and send along fixes for all of that? @to-sta and I can then take a look afterwards :)

@andrewtavis
Copy link
Member

Two minor things that I just shared with another contributor that would be helpful for you, @josueemartinezz:

Want to stress that there's no issue on our end with the checks failing! All this is very appreciated, and doing the steps above will just take it all to the next level 🚀

@@ -43,6 +43,11 @@ class OrganizationViewSet(viewsets.ModelViewSet[Organization]):
serializer_class = OrganizationSerializer
pagination_class = CustomPagination
throttle_classes = [AnonRateThrottle, UserRateThrottle]

def list(self, request: Request, *args: str, **kwagrs: int) -> Response:
queryset = Organization.objects.all()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josueemartinezz

The variable queryset is unused and redundant 😅.

queryset = Event.objects.all()
serializer = self.get_serializer(self.queryset, many=True)

@@ -70,7 +75,7 @@ def destroy(self, request: Request, *args: str, **kwargs: int) -> Response:
instance = get_object_or_404(Organization, pk=kwargs["pk"])
instance.delete()
data = {"message": f'Organization {kwargs["pk"]} has been deleted successfully'}
return Response(data, status=status.HTTP_204_NO_CONTENT)
return Response(status=status.HTTP_202_ACCEPTED)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor thing here. Accepted is good status for this but we generally use the status.HTTP_201_CREATED in case we create an instance.

@@ -26,11 +26,14 @@
class Event(CreationDeletionMixin):
id = models.UUIDField(primary_key=True, default=uuid4, editable=False)
name = models.CharField(max_length=255)
tagline = models.CharField(max_length=255, blank=True)
tagline = models.CharField(max_length=255, blank=True, null=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In django CharField and TextField are never saved as NULL values, therefore there is no need for null=True.

@@ -41,6 +44,8 @@ class Event(CreationDeletionMixin):
event_icon = models.OneToOneField(
"content.Image", on_delete=models.CASCADE, null=True, blank=True
)
creation_date = models.DateTimeField(auto_now_add=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

creation_date and deletion_date are added by the mixin:

class Event(CreationDeletionMixin):
     ...

@@ -70,7 +75,7 @@ def destroy(self, request: Request, *args: str, **kwargs: int) -> Response:
instance = get_object_or_404(Organization, pk=kwargs["pk"])
instance.delete()
data = {"message": f'Organization {kwargs["pk"]} has been deleted successfully'}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable data is created but it is not used. You have to add it to the response.

@to-sta
Copy link
Collaborator

to-sta commented Mar 17, 2024

@josueemartinezz Thanks for contribution 😃. I added a few comments. How did you test the API?

@josueemartinezz
Copy link
Author

josueemartinezz commented Mar 17, 2024

@josueemartinezz Thanks for contribution 😃. I added a few comments. How did you test the API?

Hi! Thank you so much for your review. I'll get these fixed right away. I tested the API by using Swagger-UI for all the HTTP methods, ensuring bad user input passed the Event model's field validation requirements. If it did, like a user's end_time precedes start_time, I raised exceptions in serializers.py. I tested for foreign key existence, but this again was accounted for by the key checks done by the field type. Please let me know of any testing strategies tips apart from just playing around with inputs on Swagger-UI.

1. Added (list, create, retrieve, update, partial_update, destroy) HTTP methods
2. Modified serializers to validate non-trivial input from user. Trivial validation is ensured by the model setup.
3. Added missing fields for Event model (according to Figma designs)
1. fixed pre-commit and ruff formatting
2. discarded redundant fields from mixin
3. removed null CharField & TextField
4. fixed request status for Destroy instance.
5. removed unused/redundant variables.
@andrewtavis
Copy link
Member

Heyo @josueemartinezz! We have the other priority backend PRs merged and will get to this when we can! Sorry for the wait! Map for events has been taking some major strides, so the feature set is definitely there for when this is brought in 😊

@josueemartinezz josueemartinezz closed this by deleting the head repository May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants