-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
guoshijiang
committed
Mar 17, 2024
1 parent
e6534b9
commit dc5ff00
Showing
6 changed files
with
249 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# encoding=utf-8 | ||
|
||
import json | ||
from common.helpers import ok_json | ||
from website.models import ( | ||
Event, | ||
Forum, | ||
BlogCat, | ||
Blog | ||
) | ||
|
||
|
||
# @check_api_token | ||
def get_event_list(request): | ||
params = json.loads(request.body.decode()) | ||
page = params.get('page', 1) | ||
page_size = params.get('page_size', 20) | ||
start = (page - 1) * page_size | ||
end = start + page_size | ||
events = Event.objects.all().order_by("-id")[start:end] | ||
total = Event.objects.all().order_by("-id").count() | ||
event_list = [] | ||
for event in events: | ||
event_list.append(event.as_dict()) | ||
data = { | ||
"total": total, | ||
"event_list": event_list, | ||
} | ||
return ok_json(data) | ||
|
||
|
||
# @check_api_token | ||
def get_forum_list(request): | ||
params = json.loads(request.body.decode()) | ||
page = params.get('page', 1) | ||
page_size = params.get('page_size', 20) | ||
start = (page - 1) * page_size | ||
end = start + page_size | ||
forums = Forum.objects.all().order_by("-id")[start:end] | ||
total = Forum.objects.all().order_by("-id").count() | ||
forum_list = [] | ||
for forum in forums: | ||
forum_list.append(forum.as_dict()) | ||
data = { | ||
"total": total, | ||
"forum_list": forum_list, | ||
} | ||
return ok_json(data) | ||
|
||
|
||
# @check_api_token | ||
def get_blog_cat_list(request): | ||
blog_cats = BlogCat.objects.all() | ||
blog_cat_list = [] | ||
for blog_cat in blog_cats: | ||
blog_cat_list.append(blog_cat.as_dict()) | ||
return ok_json(blog_cat_list) | ||
|
||
|
||
# @check_api_token | ||
def get_blog_list(request): | ||
params = json.loads(request.body.decode()) | ||
cat_id = params.get('cat_id', 0) | ||
page = params.get('page', 1) | ||
page_size = params.get('page_size', 20) | ||
start = (page - 1) * page_size | ||
end = start + page_size | ||
bcat = BlogCat.objects.filter(id=cat_id).first() | ||
if bcat is None: | ||
blogs = Blog.objects.all().order_by("-id")[start:end] | ||
total = Blog.objects.all().order_by("-id").count() | ||
else: | ||
blogs = Blog.objects.filter(cat=bcat).order_by("-id")[start:end] | ||
total = Blog.objects.filter(cat=bcat).order_by("-id").count() | ||
blog_list = [] | ||
for blog in blogs: | ||
blog_list.append(blog.as_dict()) | ||
data = { | ||
"total": total, | ||
"blog_list": blog_list, | ||
} | ||
return ok_json(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 4.1.1 on 2024-03-17 10:40 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('website', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='blog', | ||
name='cat', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='blog_cat', to='website.blogcat', verbose_name='博客分类'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
# 网站接口 | ||
|
||
## 1. 获取博客类别 | ||
|
||
请求示范 | ||
``` | ||
curl --location --request POST 'http://127.0.0.1:8000/api/get_blog_cat_list' \ | ||
--data '' | ||
``` | ||
返回值 | ||
``` | ||
{ | ||
"ok": true, | ||
"code": 200, | ||
"result": [ | ||
{ | ||
"id": 1, | ||
"name": "web3" | ||
}, | ||
{ | ||
"id": 2, | ||
"name": "ecosystem" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
## 2. 获取博客列表 | ||
|
||
请求示范 | ||
``` | ||
curl --location 'http://127.0.0.1:8000/api/get_blog_list' \ | ||
--header 'Content-Type: application/json' \ | ||
--data '{ | ||
"cat_id": 2, | ||
"page": 1, | ||
"page_size": 10 | ||
}' | ||
``` | ||
返回值 | ||
``` | ||
{ | ||
"ok": true, | ||
"code": 200, | ||
"result": { | ||
"total": 1, | ||
"blog_list": [ | ||
{ | ||
"id": 1, | ||
"title": "unknown", | ||
"cat_name": "unknown", | ||
"image": "blog/2024/03/17/1280X1280.JPEG", | ||
"describe": "10DP once, max 10000DP", | ||
"link_url": "dapplink protobuf protobufprotobufprotobuf", | ||
"tags": "hhhh", | ||
"created_at": "2024-03-17 18:44:53" | ||
} | ||
] | ||
} | ||
} | ||
``` | ||
|
||
|
||
## 3. 获取事件列表 | ||
|
||
请求示范 | ||
``` | ||
curl --location 'http://127.0.0.1:8000/api/get_forum_list' \ | ||
--header 'Content-Type: application/json' \ | ||
--data '{ | ||
"page": 1, | ||
"page_size": 10 | ||
}' | ||
``` | ||
返回值 | ||
``` | ||
{ | ||
"ok": true, | ||
"code": 200, | ||
"result": { | ||
"total": 1, | ||
"forum_list": [ | ||
{ | ||
"id": 1, | ||
"name": "Execute transactions on the testnet cross-chain bridge", | ||
"link": "dapplink protobuf protobufprotobufprotobuf", | ||
"describe": "10DP once, max 10000DP", | ||
"created_at": "2024-03-17 18:44:04" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
``` | ||
|
||
|
||
## 4. 获取 forum 列表 | ||
|
||
请求示范 | ||
``` | ||
curl --location 'http://127.0.0.1:8000/api/get_forum_list' \ | ||
--header 'Content-Type: application/json' \ | ||
--data '{ | ||
"page": 1, | ||
"page_size": 10 | ||
}' | ||
``` | ||
返回值 | ||
``` | ||
{ | ||
"ok": true, | ||
"code": 200, | ||
"result": { | ||
"total": 1, | ||
"forum_list": [ | ||
{ | ||
"id": 1, | ||
"title": "dapplink protobuf protobufprotobufprotobuf", | ||
"link": "dapplink protobuf protobufprotobufprotobuf", | ||
"describe": "dapplink protobuf protobufprotobufprotobuf", | ||
"created_at": "2024-03-17 18:43:51" | ||
} | ||
] | ||
} | ||
} | ||
``` | ||
|