JPT User object
Introduction
User
is a table that record all user profile information, like user ID, password referee etc., More importantly, upload and download bytes also recorded in this table.
I use bigint in database to store date
for all time
related fields.
For upload and download bytes, I use bigint in postgresql.
Table structure
Column | Type | |
---|---|---|
uid | integer | |
password | character varying(100) | |
username | character varying(100) | |
character varying(100) | ||
upload_byte | bigint | |
download_byte | bigint | |
credit | integer | |
referee | integer | |
register_time | bigint | |
status | integer |
Class
Note that the UserLevel level
field is annotated as @Transient
, since server will calculate the score of user when requested, hence user level is dynamic. Thisconsistantified database representation and relation.
Class below is just a simplified version of this class, for details, please refer to github.
1 |
|
Because password
is a sensitive field, currently this field could be serialized by GSON when creating response. But it is really easy to stop from doing that by removing @Expose
annotation from this field.
JSON
1 |
|
As you can see, JSON that serialized by GSON will have content like above.
Sometimes there is no level
field as it is not mandetory. But from my design, torrent poster could specify the minimum required level of a torrent, which could narrowing the target user to serve.