Skip to content

Commit

Permalink
offical websit api design
Browse files Browse the repository at this point in the history
  • Loading branch information
guoshijiang committed Mar 17, 2024
1 parent 055c1a2 commit e6534b9
Show file tree
Hide file tree
Showing 13 changed files with 379 additions and 25 deletions.
8 changes: 7 additions & 1 deletion airdrop/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
PointsRecord,
ProjectInterAction,
Questions,
Period,
PeriodReward
)

Expand All @@ -30,6 +31,11 @@ class ChainAdmin(admin.ModelAdmin):
list_display = ('id', 'question', 'answer', 'language')


@admin.register(Period)
class ChainAdmin(admin.ModelAdmin):
list_display = ('id', 'title', 'sub_title', 'link_url', 'period')


@admin.register(PeriodReward)
class ChainAdmin(admin.ModelAdmin):
list_display = ('id', 'title', 'address', 'amount', 'is_send')
list_display = ('id', 'address', 'amount', 'is_send')
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generated by Django 4.1.1 on 2024-03-17 10:16

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('airdrop', '0005_remove_periodreward_name_periodreward_period_and_more'),
]

operations = [
migrations.CreateModel(
name='Period',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('uuid', models.CharField(blank=True, max_length=100, null=True, unique=True)),
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
('updated_at', models.DateTimeField(auto_now=True, db_index=True)),
('title', models.CharField(default='', max_length=200, verbose_name='活动主题')),
('sub_title', models.CharField(default='', max_length=200, verbose_name='活动副标题')),
('image', models.ImageField(blank=True, null=True, upload_to='period/%Y/%m/%d/', verbose_name='活动图片')),
('link_url', models.CharField(default='', max_length=100, verbose_name='活动链接')),
('period', models.CharField(blank=True, max_length=300, verbose_name='活动周期')),
],
options={
'verbose_name': 'Period',
'verbose_name_plural': 'Period',
},
),
migrations.RemoveField(
model_name='periodreward',
name='period',
),
migrations.RemoveField(
model_name='periodreward',
name='sub_title',
),
migrations.RemoveField(
model_name='periodreward',
name='title',
),
]
60 changes: 49 additions & 11 deletions airdrop/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def as_dict(self):
}


class PeriodReward(BaseModel):
class Period(BaseModel):
title = models.CharField(
max_length=200,
unique=False,
Expand All @@ -280,22 +280,61 @@ class PeriodReward(BaseModel):
default="",
verbose_name='活动副标题'
)
address = models.CharField(
max_length=200,
unique=False,
verbose_name='地址'
image = models.ImageField(
upload_to='period/%Y/%m/%d/',
blank=True,
null=True,
verbose_name='活动图片'
)
amount = models.CharField(
link_url = models.CharField(
default="",
max_length=100,
unique=False,
verbose_name='中奖金额'
verbose_name='活动链接'
)
period = models.CharField(
max_length=300,
unique=False,
blank=True,
verbose_name='活动周期'
)

class Meta:
verbose_name = 'Period'
verbose_name_plural = verbose_name

def as_dict(self, address):
is_reward = True
reward = {}
p_reward = PeriodReward.objects.filter(address=address).first()
if p_reward is None:
is_reward = False
else:
reward = p_reward.as_dict()
return {
'id': self.id,
'title': self.title,
'sub_title': self.sub_title,
'image': str(self.image),
'link_url': self.link_url,
'period': self.period,
'is_reward': is_reward,
"reward": reward,
}


class PeriodReward(BaseModel):
address = models.CharField(
max_length=200,
unique=False,
verbose_name='地址'
)
amount = models.CharField(
max_length=100,
unique=False,
verbose_name='中奖金额'
)

is_send = models.BooleanField(
default=False
)
Expand All @@ -308,12 +347,11 @@ def __str__(self):
return self.address

def as_dict(self):
tz = pytz.timezone(settings.TIME_ZONE)
return {
'id': self.id,
'title': self.title,
'sub_title': self.sub_title,
'address': self.address,
'period': self.period,
'amount': self.amount,
'is_send': self.is_send,
}
'created_at': self.created_at.astimezone(tz).strftime("%Y-%m-%d %H:%M:%S")
}
17 changes: 4 additions & 13 deletions api/airdrop/api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
PointsRecord,
ProjectInterAction,
Questions,
PeriodReward
Period
)


Expand All @@ -22,20 +22,11 @@ def get_reward_info(request):
address = params.get("address", None)
if address is None:
return error_json("address params is empty", 4000)
pr_list = PeriodReward.objects.filter(address__icontains=address).all()
if len(pr_list) == 0:
data = {
"is_reward": False
}
return ok_json(data)
pr_list = Period.objects.all()
pr_response = []
for pr in pr_list:
pr_response.append(pr.as_dict())
data = {
"is_reward": True,
"rewards": pr_response
}
return ok_json(data)
pr_response.append(pr.as_dict(address=address))
return ok_json(pr_response)


# @check_api_token
Expand Down
1 change: 1 addition & 0 deletions hailstone/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"services",
"channels",
'airdrop',
'website',
]

MIDDLEWARE = [
Expand Down
Empty file added website/__init__.py
Empty file.
29 changes: 29 additions & 0 deletions website/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# encoding=utf-8

from django.contrib import admin
from website.models import (
Event,
Forum,
BlogCat,
Blog
)


@admin.register(Event)
class AddressAmountStatAdmin(admin.ModelAdmin):
list_display = ('id', 'name', 'link_url', 'describe')


@admin.register(Forum)
class AddressAmountStatAdmin(admin.ModelAdmin):
list_display = ('id', 'title', 'link_url', 'describe')


@admin.register(BlogCat)
class AddressAmountStatAdmin(admin.ModelAdmin):
list_display = ('id', 'name')


@admin.register(Blog)
class AddressAmountStatAdmin(admin.ModelAdmin):
list_display = ('id', 'title', 'link_url', 'tags', 'describe')
6 changes: 6 additions & 0 deletions website/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class WebsiteConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'website'
78 changes: 78 additions & 0 deletions website/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Generated by Django 4.1.1 on 2024-03-17 09:58

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Blog',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('uuid', models.CharField(blank=True, max_length=100, null=True, unique=True)),
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
('updated_at', models.DateTimeField(auto_now=True, db_index=True)),
('title', models.CharField(default='unknown', max_length=200, verbose_name='博客标题')),
('image', models.ImageField(blank=True, null=True, upload_to='blog/%Y/%m/%d/')),
('describe', models.CharField(blank=True, default='', max_length=500, null=True, verbose_name='描述')),
('link_url', models.CharField(default='', max_length=100, verbose_name='博客链接')),
('tags', models.CharField(default='', max_length=200, verbose_name='标签')),
],
options={
'verbose_name': 'Blog',
'verbose_name_plural': 'Blog',
},
),
migrations.CreateModel(
name='BlogCat',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('uuid', models.CharField(blank=True, max_length=100, null=True, unique=True)),
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
('updated_at', models.DateTimeField(auto_now=True, db_index=True)),
('name', models.CharField(default='unknown', max_length=100, verbose_name='分类名称')),
],
options={
'verbose_name': 'BlogCat',
'verbose_name_plural': 'BlogCat',
},
),
migrations.CreateModel(
name='Event',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('uuid', models.CharField(blank=True, max_length=100, null=True, unique=True)),
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
('updated_at', models.DateTimeField(auto_now=True, db_index=True)),
('name', models.CharField(default='', max_length=100, verbose_name='事件名称')),
('link_url', models.CharField(default='', max_length=100, verbose_name='事件链接')),
('describe', models.CharField(blank=True, default='', max_length=500, null=True, verbose_name='事件描述')),
],
options={
'verbose_name': 'Event',
'verbose_name_plural': 'Event',
},
),
migrations.CreateModel(
name='Forum',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('uuid', models.CharField(blank=True, max_length=100, null=True, unique=True)),
('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
('updated_at', models.DateTimeField(auto_now=True, db_index=True)),
('title', models.CharField(default='', max_length=100, verbose_name='标题')),
('link_url', models.CharField(default='', max_length=100, verbose_name='form 链接')),
('describe', models.CharField(blank=True, default='', max_length=500, null=True, verbose_name='描述')),
],
options={
'verbose_name': 'Forum',
'verbose_name_plural': 'Forum',
},
),
]
Empty file added website/migrations/__init__.py
Empty file.
Loading

0 comments on commit e6534b9

Please sign in to comment.