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)
email 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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
public class User
{

@Id
@Basic(optional = false)
@Column(nullable = false)
@Expose
private Integer uid;
//user Id, primary key

@Expose
@Column(length = 100)
private String password;

@Expose
@Column(length = 100)
private String username;
//user name, unique

@Expose
@Column(length = 100)
private String email;
//unique, useful when forget password

@Expose
@Column(name = "upload_byte")
private Long uploadByte = 0l;
//field indicate the number of byte uploaded

@Expose
@Column(name = "download_byte")
private Long downloadByte = 0l;
//field indicate the number of byte downloaded

@Expose
@Column
private Integer credit = 0;
//some extra credit awarded by administrator or other mechanism
//could be used to do a lot of gameing thing

@Expose
@Column(name = "register_time")
private Long registerTime;

@Expose
@Transient
private UserLevel level;
//user level corresponding to related download and upload

@Expose
@Column
private Status status;
//User status, like banned from login or something else

@JoinColumn(name = "referee", referencedColumnName = "uid")
@ManyToOne
private User referee;
//...

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
2
3
4
5
{
"uid":1349, "password":"test123", "username":"tenjin",
"status":"VALID", "credit":0, "registerTime":1442471051470,
"email":"testhappy@128.com", "uploadByte":0, "downloadByte":0
}

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.


JPT User object
https://rug.al/2015/2015-09-18-jpt-user-object/
Author
Rugal Bernstein
Posted on
September 18, 2015
Licensed under