fix errors related to foreign key

This commit is contained in:
Gustavo Trott 2024-04-17 09:49:58 -03:00
parent 59b33c24ab
commit 39a6c21682
7 changed files with 30 additions and 21 deletions

View File

@ -148,10 +148,10 @@ class WhiteboardModel extends SystemConfiguration {
annotationsIdsRemoved
}
def modifyWhiteboardAccess(wbId: String, multiUser: Array[String]) {
def modifyWhiteboardAccess(meetingId: String, wbId: String, multiUser: Array[String]) {
val wb = getWhiteboard(wbId)
val newWb = wb.copy(multiUser = multiUser, oldMultiUser = wb.multiUser, changedModeOn = System.currentTimeMillis())
PresPageWritersDAO.updateMultiuser(newWb)
PresPageWritersDAO.updateMultiuser(meetingId, newWb)
saveWhiteboard(newWb)
}

View File

@ -57,7 +57,7 @@ class WhiteboardApp2x(implicit val context: ActorContext)
}
def modifyWhiteboardAccess(whiteboardId: String, multiUser: Array[String], liveMeeting: LiveMeeting) {
liveMeeting.wbModel.modifyWhiteboardAccess(whiteboardId, multiUser)
liveMeeting.wbModel.modifyWhiteboardAccess(liveMeeting.props.meetingProp.intId, whiteboardId, multiUser)
}
def filterWhiteboardMessage(whiteboardId: String, userId: String, liveMeeting: LiveMeeting): Boolean = {

View File

@ -15,6 +15,7 @@ case class NotificationDbModel(
messageDescription: String,
messageValues: JsValue,
role: Option[String],
userMeetingId: Option[String],
userId: Option[String],
createdAt: java.sql.Timestamp,
)
@ -27,9 +28,10 @@ class NotificationDbTableDef(tag: Tag) extends Table[NotificationDbModel](tag, N
val messageDescription = column[String]("messageDescription")
val messageValues = column[JsValue]("messageValues")
val role = column[Option[String]]("role")
val userMeetingId = column[Option[String]]("userMeetingId")
val userId = column[Option[String]]("userId")
val createdAt = column[java.sql.Timestamp]("createdAt")
override def * = (meetingId, notificationType, icon, messageId, messageDescription, messageValues, role, userId, createdAt) <> (NotificationDbModel.tupled, NotificationDbModel.unapply)
override def * = (meetingId, notificationType, icon, messageId, messageDescription, messageValues, role, userMeetingId, userId, createdAt) <> (NotificationDbModel.tupled, NotificationDbModel.unapply)
}
object NotificationDAO {
@ -57,6 +59,10 @@ object NotificationDAO {
messageDescription,
JsonUtils.vectorToJson(messageValues),
role,
userMeetingId = userId match {
case Some(u) => Some(meetingId)
case _ => None
},
userId,
createdAt = new java.sql.Timestamp(System.currentTimeMillis())
)

View File

@ -19,10 +19,9 @@ class PresPageCursorDbTableDef(tag: Tag) extends Table[PresPageCursorDbModel](ta
override def * = (
pageId, meetingId, userId, xPercent, yPercent, lastUpdatedAt
) <> (PresPageCursorDbModel.tupled, PresPageCursorDbModel.unapply)
def pk = primaryKey("pres_page_cursor_pkey", (pageId, userId))
val pageId = column[String]("pageId")
val meetingId = column[String]("meetingId")
val userId = column[String]("userId")
val pageId = column[String]("pageId", O.PrimaryKey)
val meetingId = column[String]("meetingId", O.PrimaryKey)
val userId = column[String]("userId", O.PrimaryKey)
val xPercent = column[Double]("xPercent")
val yPercent = column[Double]("yPercent")
val lastUpdatedAt = column[java.sql.Timestamp]("lastUpdatedAt")

View File

@ -7,34 +7,36 @@ import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.{Failure, Success}
case class PresPageWritersDbModel(
pageId: String,
userId: String,
changedModeOn: Long,
pageId: String,
meetingId: String,
userId: String,
changedModeOn: Long,
)
class PresPageWritersDbTableDef(tag: Tag) extends Table[PresPageWritersDbModel](tag, None, "pres_page_writers") {
override def * = (
pageId, userId, changedModeOn) <> (PresPageWritersDbModel.tupled, PresPageWritersDbModel.unapply)
def pk = primaryKey("pres_page_writers_pkey", (pageId, userId))
val pageId = column[String]("pageId")
val userId = column[String]("userId")
pageId, meetingId, userId, changedModeOn) <> (PresPageWritersDbModel.tupled, PresPageWritersDbModel.unapply)
val pageId = column[String]("pageId", O.PrimaryKey)
val meetingId = column[String]("meetingId", O.PrimaryKey)
val userId = column[String]("userId", O.PrimaryKey)
val changedModeOn = column[Long]("changedModeOn")
}
object PresPageWritersDAO {
def updateMultiuser(whiteboard: Whiteboard) = {
def updateMultiuser(meetingId: String, whiteboard: Whiteboard) = {
val deleteQuery = TableQuery[PresPageWritersDbTableDef]
.filter(_.pageId === whiteboard.id)
if(whiteboard.multiUser.length > 0) {
deleteQuery.filter(_.meetingId === meetingId)
deleteQuery.filterNot(_.userId inSet whiteboard.multiUser)
}
DatabaseConnection.db.run(deleteQuery.delete).onComplete {
case Success(rowsAffected) => DatabaseConnection.logger.debug(s"Users deleted from Whiteboard ${whiteboard.id}")
case Failure(e) => DatabaseConnection.logger.error(s"Error deleting users from whiteboard: $e")
case Success(rowsAffected) => DatabaseConnection.logger.debug(s"Users deleted from pres_page_writers ${whiteboard.id}")
case Failure(e) => DatabaseConnection.logger.error(s"Error deleting users from pres_page_writers: $e")
}
for {
@ -44,6 +46,7 @@ object PresPageWritersDAO {
TableQuery[PresPageWritersDbTableDef].insertOrUpdate(
PresPageWritersDbModel(
pageId = whiteboard.id,
meetingId = meetingId,
userId = userId,
changedModeOn = whiteboard.changedModeOn
)

View File

@ -7,8 +7,8 @@ import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.{ Failure, Success }
case class UserCustomParameterDbModel(
userId: String,
meetingId: String,
userId: String,
parameter: String,
value: String
)

View File

@ -519,7 +519,7 @@ create table "user_customParameter"(
"userId" varchar(50),
"parameter" varchar(255),
"value" varchar(255),
CONSTRAINT "user_customParameter_pkey" PRIMARY KEY ("userId","parameter"),
CONSTRAINT "user_customParameter_pkey" PRIMARY KEY ("meetingId", "userId","parameter"),
FOREIGN KEY ("meetingId", "userId") REFERENCES "user"("meetingId","userId") ON DELETE CASCADE
);
@ -1789,9 +1789,10 @@ CREATE TABLE "notification" (
"messageDescription" varchar(100),
"messageValues" jsonb,
"role" varchar(100), --MODERATOR, PRESENTER, VIEWER
"userMeetingId" varchar(50),
"userId" varchar(50),
"createdAt" timestamp with time zone DEFAULT current_timestamp,
FOREIGN KEY ("meetingId", "userId") REFERENCES "user"("meetingId","userId") ON DELETE CASCADE
FOREIGN KEY ("meetingId", "userId") REFERENCES "user"("userMeetingId","userId") ON DELETE CASCADE
);
create or replace VIEW "v_notification" AS