Skip to content
Merged
20 changes: 20 additions & 0 deletions pydis_site/apps/api/migrations/0055_reminder_mentions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 2.2.14 on 2020-07-15 07:37

import django.contrib.postgres.fields
import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0054_user_invalidate_unknown_role'),
]

operations = [
migrations.AddField(
model_name='reminder',
name='mentions',
field=django.contrib.postgres.fields.ArrayField(base_field=models.BigIntegerField(validators=[django.core.validators.MinValueValidator(limit_value=0, message='Mention IDs cannot be negative.')]), blank=True, default=list, help_text='IDs of roles or users to ping with the reminder.', size=None),
),
]
14 changes: 14 additions & 0 deletions pydis_site/apps/api/migrations/0057_merge_20200716_0751.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 2.2.14 on 2020-07-16 07:51

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('api', '0055_reminder_mentions'),
('api', '0056_allow_blank_user_roles'),
]

operations = [
]
14 changes: 14 additions & 0 deletions pydis_site/apps/api/models/bot/reminder.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.contrib.postgres.fields import ArrayField
from django.core.validators import MinValueValidator
from django.db import models

Expand Down Expand Up @@ -45,6 +46,19 @@ class Reminder(ModelReprMixin, models.Model):
expiration = models.DateTimeField(
help_text="When this reminder should be sent."
)
mentions = ArrayField(
models.BigIntegerField(
validators=(
MinValueValidator(
limit_value=0,
message="Mention IDs cannot be negative."
),
)
),
default=list,
blank=True,
help_text="IDs of roles or users to ping with the reminder."
)

def __str__(self):
"""Returns some info on the current reminder, for display purposes."""
Expand Down
4 changes: 3 additions & 1 deletion pydis_site/apps/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ class Meta:
"""Metadata defined for the Django REST Framework."""

model = Reminder
fields = ('active', 'author', 'jump_url', 'channel_id', 'content', 'expiration', 'id')
fields = (
'active', 'author', 'jump_url', 'channel_id', 'content', 'expiration', 'id', 'mentions'
)


class RoleSerializer(ModelSerializer):
Expand Down
1 change: 1 addition & 0 deletions pydis_site/apps/api/tests/test_reminders.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def test_accepts_valid_data(self):
'expiration': datetime.utcnow().isoformat(),
'jump_url': "https://www.google.com",
'channel_id': 123,
'mentions': [8888, 9999],
}
url = reverse('bot:reminder-list', host='api')
response = self.client.post(url, data=data)
Expand Down
30 changes: 28 additions & 2 deletions pydis_site/apps/api/viewsets/bot/reminder.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,16 @@ class ReminderViewSet(
... {
... 'active': True,
... 'author': 1020103901030,
... 'mentions': [
... 336843820513755157,
... 165023948638126080,
... 267628507062992896
... ],
... 'content': "Make dinner",
... 'expiration': '5018-11-20T15:52:00Z',
... 'id': 11
... 'id': 11,
... 'channel_id': 634547009956872193,
... 'jump_url': "https://discord.com/channels/<guild_id>/<channel_id>/<message_id>"
... },
... ...
... ]
Expand All @@ -43,15 +50,34 @@ class ReminderViewSet(
#### Request body
>>> {
... 'author': int,
... 'mentions': List[int],
... 'content': str,
... 'expiration': str # ISO-formatted datetime
... 'expiration': str, # ISO-formatted datetime
... 'channel_id': int,
... 'jump_url': str
... }

#### Status codes
- 201: returned on success
- 400: if the body format is invalid
- 404: if no user with the given ID could be found

### PATCH /bot/reminders/<id:int>
Update the user with the given `id`.
All fields in the request body are optional.

#### Request body
>>> {
... 'mentions': List[int],
... 'content': str,
... 'expiration': str # ISO-formatted datetime
... }

#### Status codes
- 200: returned on success
- 400: if the body format is invalid
- 404: if no user with the given ID could be found

### DELETE /bot/reminders/<id:int>
Delete the reminder with the given `id`.

Expand Down