Skip to content

Commit

Permalink
add ability to edit comments and show if edited
Browse files Browse the repository at this point in the history
  • Loading branch information
jschwarz2030 committed Jan 28, 2025
1 parent 19d1bfd commit be53d93
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
3 changes: 2 additions & 1 deletion app/org/maproulette/framework/model/Comment.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion app/org/maproulette/framework/model/TaskLogEntry.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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,
Expand All @@ -183,7 +183,8 @@ object CommentRepository {
projectId = projectId,
created = created,
comment = comment,
actionId = actionId
actionId = actionId,
edited = edited
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -39,7 +41,9 @@ class TaskHistoryRepository @Inject() (override val db: Database) extends Reposi
None,
None,
Some(comment),
None
None,
entryId = id,
edited = edited
)
}
}
Expand Down Expand Up @@ -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.*)
}
Expand Down
5 changes: 5 additions & 0 deletions conf/evolutions/default/99.sql
Original file line number Diff line number Diff line change
@@ -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;;

0 comments on commit be53d93

Please sign in to comment.