修复.to_dict()功能
Change-Id: I6e42cb9ecc915bc713e547b05f8bd3c2b53034c8
diff --git a/API/API-TRM/TRM/Back/app/__pycache__/routes.cpython-310.pyc b/API/API-TRM/TRM/Back/app/__pycache__/routes.cpython-310.pyc
index 79cd662..af72069 100644
--- a/API/API-TRM/TRM/Back/app/__pycache__/routes.cpython-310.pyc
+++ b/API/API-TRM/TRM/Back/app/__pycache__/routes.cpython-310.pyc
Binary files differ
diff --git a/API/API-TRM/TRM/Back/app/functions/Fpost.py b/API/API-TRM/TRM/Back/app/functions/Fpost.py
index 529404c..e51cf5c 100644
--- a/API/API-TRM/TRM/Back/app/functions/Fpost.py
+++ b/API/API-TRM/TRM/Back/app/functions/Fpost.py
@@ -9,7 +9,7 @@
def getlist(self):
- results = self.session.query(post.id, post.title,post.status).all()
+ results = self.session.query(post.id, post.title,post.status)
return results
def getpost(self,postid):
res=self.session.query(post).filter(post.id==postid).first()
diff --git a/API/API-TRM/TRM/Back/app/functions/__pycache__/Fpost.cpython-310.pyc b/API/API-TRM/TRM/Back/app/functions/__pycache__/Fpost.cpython-310.pyc
index 5cb09fc..2b6cd6d 100644
--- a/API/API-TRM/TRM/Back/app/functions/__pycache__/Fpost.cpython-310.pyc
+++ b/API/API-TRM/TRM/Back/app/functions/__pycache__/Fpost.cpython-310.pyc
Binary files differ
diff --git a/API/API-TRM/TRM/Back/app/models/__pycache__/post.cpython-310.pyc b/API/API-TRM/TRM/Back/app/models/__pycache__/post.cpython-310.pyc
index 130e2ac..263b592 100644
--- a/API/API-TRM/TRM/Back/app/models/__pycache__/post.cpython-310.pyc
+++ b/API/API-TRM/TRM/Back/app/models/__pycache__/post.cpython-310.pyc
Binary files differ
diff --git a/API/API-TRM/TRM/Back/app/models/__pycache__/users.cpython-310.pyc b/API/API-TRM/TRM/Back/app/models/__pycache__/users.cpython-310.pyc
index 903735a..e6286c3 100644
--- a/API/API-TRM/TRM/Back/app/models/__pycache__/users.cpython-310.pyc
+++ b/API/API-TRM/TRM/Back/app/models/__pycache__/users.cpython-310.pyc
Binary files differ
diff --git a/API/API-TRM/TRM/Back/app/models/post.py b/API/API-TRM/TRM/Back/app/models/post.py
index a865712..041e263 100644
--- a/API/API-TRM/TRM/Back/app/models/post.py
+++ b/API/API-TRM/TRM/Back/app/models/post.py
@@ -23,7 +23,20 @@
}
)
-
+ def to_dict(self):
+ return {
+ 'id': self.id if self.id else None,
+ 'user_id': self.user_id if self.user_id else None,
+ 'topic_id': self.topic_id if self.topic_id else None,
+ 'type': self.type if self.type else None,
+ 'title': self.title if self.title else None,
+ 'content': self.content if self.content else None,
+ 'media_urls': self.media_urls if self.media_urls else None,
+ 'status': self.status if self.status else None,
+ 'heat': self.heat if self.heat else None,
+ 'created_at': self.created_at.isoformat() if self.created_at else None,
+ 'updated_at': self.updated_at.isoformat() if self.updated_at else None
+ }
id = Column(
diff --git a/API/API-TRM/TRM/Back/app/models/users.py b/API/API-TRM/TRM/Back/app/models/users.py
index 2cd9871..0505e86 100644
--- a/API/API-TRM/TRM/Back/app/models/users.py
+++ b/API/API-TRM/TRM/Back/app/models/users.py
@@ -8,7 +8,18 @@
class User(Base):
__tablename__ = 'users'
-
+ def to_dict(self):
+ return {
+ 'id': self.id,
+ 'username': self.username if self.username else None,
+ 'email': self.email if self.email else None,
+ 'avatar': self.avatar if self.avatar else None,
+ 'role': self.role if self.role else None,
+ 'bio': self.bio if self.bio else None,
+ 'status': self.status if self.status else None,
+ 'created_at': self.created_at.isoformat() if self.created_at else None,
+ 'updated_at': self.updated_at.isoformat() if self.updated_at else None
+ }
diff --git a/API/API-TRM/TRM/Back/app/routes.py b/API/API-TRM/TRM/Back/app/routes.py
index f56f447..1238364 100644
--- a/API/API-TRM/TRM/Back/app/routes.py
+++ b/API/API-TRM/TRM/Back/app/routes.py
@@ -39,5 +39,6 @@
if(not checres):
return jsonify()
res=f.getpost(data['postid'])
- return jsonify(res)
+
+ return jsonify(res.to_dict() if res else {})
diff --git a/API/API-TRM/TRM/Back/tests/__pycache__/test_app.cpython-312-pytest-7.4.4.pyc b/API/API-TRM/TRM/Back/tests/__pycache__/test_app.cpython-312-pytest-7.4.4.pyc
index a32ecb0..b21ba04 100644
--- a/API/API-TRM/TRM/Back/tests/__pycache__/test_app.cpython-312-pytest-7.4.4.pyc
+++ b/API/API-TRM/TRM/Back/tests/__pycache__/test_app.cpython-312-pytest-7.4.4.pyc
Binary files differ
diff --git a/API/API-TRM/TRM/Back/tests/test_app.py b/API/API-TRM/TRM/Back/tests/test_app.py
index 71bf99a..5643282 100644
--- a/API/API-TRM/TRM/Back/tests/test_app.py
+++ b/API/API-TRM/TRM/Back/tests/test_app.py
@@ -2,24 +2,26 @@
url = 'http://127.0.0.1:5713/'
def test_get_postlist():
+ print()
urlx=url+'spostlist'
payload = {
'userid': 3
}
headers = {'Content-Type': 'application/json'}
- resp = requests.post(urlx, json=payload, headers=headers)
+ resp = requests.get(urlx, json=payload, headers=headers)
# print(resp.status_code)
print(resp.json())
def test_get_post():
+ print()
urlx=url+'sgetpost'
payload = {
'userid': 3,
- 'postid': 1
+ 'postid': 21
}
headers = {'Content-Type': 'application/json'}
- resp = requests.post(urlx, json=payload, headers=headers)
+ resp = requests.get(urlx, json=payload, headers=headers)
# print(resp.status_code)
print(resp.json())
\ No newline at end of file