Rating system in web application

465 Views Asked by At

I'm trying to create a rating system (as a reputation system in reddit and Stackoverflow) in my web application.

What is the right way to store that rating?

@Entity
Class User {
   Long id
   ...
   @OneToOne
   CustomRating rating
}

@Entity
Class CustomRating {

  @ManyToOne
  Set<User> upvotes;

  @ManyToOne
  Set<User> downvotes;
}

This is the best I can do. Is it possible to make it better?

Thank you!

P.s. every vote should be unique. One person cannot vote twice

1

There are 1 best solutions below

0
HariHaravelan On

Since your User is going to have upvotes and downvotes by other users i suggest to have it all in User entity itself, like below

@Entity
class User {
    Long id;
    set<User> upVotedUsers;
    set<User> downVotedUsers;
}