diff --git a/app/org/maproulette/framework/model/Comment.scala b/app/org/maproulette/framework/model/Comment.scala index 86049e97..ec757f1f 100644 --- a/app/org/maproulette/framework/model/Comment.scala +++ b/app/org/maproulette/framework/model/Comment.scala @@ -28,7 +28,8 @@ case class Comment( created: DateTime, comment: String, actionId: Option[Long] = None, - fullCount: Int = 0 + fullCount: Int = 0, + edited: Boolean = false ) object Comment extends CommonField { diff --git a/app/org/maproulette/framework/model/TaskLogEntry.scala b/app/org/maproulette/framework/model/TaskLogEntry.scala index 41e49821..b7e874f6 100644 --- a/app/org/maproulette/framework/model/TaskLogEntry.scala +++ b/app/org/maproulette/framework/model/TaskLogEntry.scala @@ -27,7 +27,9 @@ case class TaskLogEntry( reviewRequestedBy: Option[Int], reviewedBy: Option[Int], comment: Option[String], - errorTags: Option[String] + errorTags: Option[String], + entryId: Option[Long] = None, + edited: Boolean = false ) {} object TaskLogEntry { diff --git a/app/org/maproulette/framework/repository/CommentRepository.scala b/app/org/maproulette/framework/repository/CommentRepository.scala index 2fa8b61b..9b11252e 100644 --- a/app/org/maproulette/framework/repository/CommentRepository.scala +++ b/app/org/maproulette/framework/repository/CommentRepository.scala @@ -139,7 +139,7 @@ class CommentRepository @Inject() (override val db: Database) extends Repository implicit c: Option[Connection] = None ): Boolean = { withMRTransaction { implicit c => - SQL("UPDATE task_comments SET comment = {comment} WHERE id = {id} RETURNING *") + SQL("UPDATE task_comments SET comment = {comment}, edited = true WHERE id = {id} RETURNING *") .on(Symbol("comment") -> updatedComment, Symbol("id") -> id) .execute() } @@ -171,8 +171,8 @@ object CommentRepository { long("task_comments.task_id") ~ long("task_comments.challenge_id") ~ long( "task_comments.project_id" ) ~ get[DateTime]("task_comments.created") ~ get[String]("task_comments.comment") ~ - get[Option[Long]]("task_comments.action_id") map { - case id ~ osmId ~ name ~ avatarUrl ~ taskId ~ challengeId ~ projectId ~ created ~ comment ~ actionId => + get[Option[Long]]("task_comments.action_id") ~ get[Boolean]("task_comments.edited") map { + case id ~ osmId ~ name ~ avatarUrl ~ taskId ~ challengeId ~ projectId ~ created ~ comment ~ actionId ~ edited => Comment( id, osm_id = osmId, @@ -183,7 +183,8 @@ object CommentRepository { projectId = projectId, created = created, comment = comment, - actionId = actionId + actionId = actionId, + edited = edited ) } } diff --git a/app/org/maproulette/framework/repository/TaskHistoryRepository.scala b/app/org/maproulette/framework/repository/TaskHistoryRepository.scala index 6823af7c..36e1ac3b 100644 --- a/app/org/maproulette/framework/repository/TaskHistoryRepository.scala +++ b/app/org/maproulette/framework/repository/TaskHistoryRepository.scala @@ -24,8 +24,10 @@ class TaskHistoryRepository @Inject() (override val db: Database) extends Reposi get[Long]("task_comments.task_id") ~ get[DateTime]("task_comments.created") ~ get[Int]("users.id") ~ - get[String]("task_comments.comment") map { - case taskId ~ created ~ userId ~ comment => + get[String]("task_comments.comment") ~ + get[Option[Long]]("task_comments.id") ~ + get[Boolean]("task_comments.edited") map { + case taskId ~ created ~ userId ~ comment ~ id ~ edited => new TaskLogEntry( taskId, created, @@ -39,7 +41,9 @@ class TaskHistoryRepository @Inject() (override val db: Database) extends Reposi None, None, Some(comment), - None + None, + entryId = id, + edited = edited ) } } @@ -193,7 +197,7 @@ class TaskHistoryRepository @Inject() (override val db: Database) extends Reposi */ def getComments(taskId: Long): List[TaskLogEntry] = { this.withMRConnection { implicit c => - SQL(s"""SELECT tc.task_id, tc.created, users.id, tc.comment FROM task_comments tc + SQL(s"""SELECT tc.id, tc.task_id, tc.created, users.id, tc.comment, tc.edited FROM task_comments tc INNER JOIN users on users.osm_id=tc.osm_id WHERE task_id = $taskId""").as(this.commentEntryParser.*) } diff --git a/conf/evolutions/default/100.sql b/conf/evolutions/default/100.sql new file mode 100644 index 00000000..dbf717cd --- /dev/null +++ b/conf/evolutions/default/100.sql @@ -0,0 +1,5 @@ +# --- !Ups +ALTER TABLE task_comments ADD COLUMN edited BOOLEAN DEFAULT false;; + +# --- !Downs +ALTER TABLE IF EXISTS task_comments DROP COLUMN edited;;