0

so the question may seem very unclear and I'm sorry but I will explain better here. I am currently working on a feature where you can ban users from an app. In the database, each user has an unique userId and I was thinking on banning based on that.

To ban a user from a room, I thought about adding an entry to a new table called bannedUser, which has 3 columns: id (randomly generated, primary key), roomId and userId (both foreign keys). Now each user has an username, which I display in a list of participants to the room. To do that, I have a method that gets all users in a room and returns a List<User>, which I then map to a List<String> with only the usernames. This means that I lose the userId. Now if I want to ban a user, I have to provide the userId and since usernames are not unique, I cannot search for it using just the username.

Therefore, I'm asking for help. I don't know exactly how I should do this. Let's say a moderator clicks a ban user button. This gets all users in the room and creates a pop-up with all usernames. Where and how should I store the userIds for each username without revealing them to the moderator?

wildf1re25
  • 21
  • 2
  • 1
    If usernames are not unique, how will a moderator be able to tell the difference between two users with the same name, if you don't reveal the user id? – Thomas Mar 28 '21 at 11:24
  • 1
    *"`List`, which I then filter to a `List`"* the correct term is "map", not "filter" but there lies your problem: you're mixing model and presentation. First filter out the users that should not be displayed, then map them to a list of strings. – Federico klez Culloca Mar 28 '21 at 11:24
  • 1
    work through a tutorial on how to use ListView, in particular about custom cells – kleopatra Mar 28 '21 at 11:41
  • Does this help? https://stackoverflow.com/questions/34838341/javafx-custom-cell-factory-with-custom-objects – Abra Mar 28 '21 at 12:07

0 Answers0