I am trying to make a facebook clone app . And from the very begining ,I will need to define a user class . And I got stuck here , every users ,supose to have followers list and following list .How do it able to make this model ? Could you please take a look my code ,thank you so much in advance !!
@Entity(tableName="user_table")
@Parcelize
data class User(
@PrimaryKey(autoGenerate = true)
val userId : Int=0 ,
val username :String,
val email :String,
val password : String,
var followers: Array<User>?,
var followings: Array<User>?,
) : Parcelable
data class UserResponse(val user:User?)
Also ,I attach my node.js model schema :
const mongoose = require('mongoose');
const router = require("express").Router();
const userSchema = new mongoose.Schema({
username:{
type:String,
required : true,
min:3,
max:50,
},
email:{
type:String,
required:true,
unique:true
},
password:{
type:String,
required : true,
},
profilePicture:{
type:String,
default:''
},
coverPicture:{
type : String,
default:''
},
followers:{
type:Array,
default :[]
},
followings:{
type:Array,
default:[]
},
isAdmin:{
type:Boolean,
default : false
}
},
{timestamps:true}
);
const User = mongoose.model('User',userSchema);
exports.userSchema = userSchema;
exports.User = User;
List<User>?rather thanArray<User>?because they are easier to use and I would probably remove the?too because the response defaults to anempty listand notnullwhich is okay in Kotlin soList<User>should just suffice