11package services
22
33import dto .request .comment .CreateUpdateCommentRequest
4+ import dto .response .comment .CommentResponse
45import exception .AppException
56import models .entities .TaskComment
67import play .api .db .slick .{DatabaseConfigProvider , HasDatabaseConfigProvider }
@@ -9,6 +10,7 @@ import play.api.libs.json.Json
910import repositories .{CommentRepository , TaskRepository }
1011import slick .jdbc .JdbcProfile
1112
13+ import java .time .Instant
1214import javax .inject .{Inject , Singleton }
1315import scala .concurrent .{ExecutionContext , Future }
1416
@@ -78,35 +80,37 @@ class CommentService @Inject()(
7880 DBIO .successful(())
7981 }
8082 updatedComment = existingComment.copy(
81- content = Json .toJson(request.content)
83+ content = Json .toJson(request.content),
84+ updatedAt = Instant .now()
8285 )
8386 updateCount <- commentRepository.update(updatedComment)
8487 } yield updateCount
8588
8689 db.run(action.transactionally)
8790 }
8891
89- // def getCommentsByTaskId(taskId: Int, userId: Int) = {
90- // val action = for {
91- // taskOpt <- taskRepository.findTaskAndProjectIdIfUserInProject(
92- // taskId,
93- // userId
94- // )
95- // _ <- taskOpt match {
96- // case Some((_, _)) =>
97- // DBIO.successful(())
98- // case _ =>
99- // DBIO.failed(
100- // AppException(
101- // message = s"Task with ID $taskId does not exist or you do not have access.",
102- // statusCode = Status.NOT_FOUND
103- // )
104- // )
105- // }
106- //
107- //
108- // } yield
109- // }
92+ def getCommentsByTaskId (taskId : Int , userId : Int ): Future [Seq [CommentResponse ]] = {
93+ val action = for {
94+ taskOpt <- taskRepository.findTaskAndProjectIdIfUserInProject(
95+ taskId,
96+ userId
97+ )
98+ _ <- taskOpt match {
99+ case Some ((_, _)) =>
100+ DBIO .successful(())
101+ case _ =>
102+ DBIO .failed(
103+ AppException (
104+ message = s " Task with ID $taskId does not exist or you do not have access. " ,
105+ statusCode = Status .NOT_FOUND
106+ )
107+ )
108+ }
109+ comments <- commentRepository.findByTaskId(taskId)
110+ } yield comments
111+
112+ db.run(action.transactionally)
113+ }
110114
111115 def deleteComment (commentId : Int , userId : Int ): Future [Int ] = {
112116 val action = for {
0 commit comments