diff --git a/codebrag-dao/src/main/scala/com/softwaremill/codebrag/dao/finders/followup/FollowupFinder.scala b/codebrag-dao/src/main/scala/com/softwaremill/codebrag/dao/finders/followup/FollowupFinder.scala index 616c4916..fc0f40d4 100644 --- a/codebrag-dao/src/main/scala/com/softwaremill/codebrag/dao/finders/followup/FollowupFinder.scala +++ b/codebrag-dao/src/main/scala/com/softwaremill/codebrag/dao/finders/followup/FollowupFinder.scala @@ -9,9 +9,13 @@ trait FollowupFinder { def findAllFollowupsByCommitForUser(userId: ObjectId): FollowupsByCommitListView def findFollowupForUser(userId: ObjectId, followupId: ObjectId): Either[String, SingleFollowupView] + + def findFollowupforDashboard(followupId: ObjectId): Either[String, SingleFollowupView] def countFollowupsForUser(userId: ObjectId): Long def countFollowupsForUserSince(date: DateTime, userId: ObjectId): Long + + def findAllFollowupsByCommitForDashboard(): FollowupsByCommitListView } diff --git a/codebrag-dao/src/main/scala/com/softwaremill/codebrag/dao/finders/followup/SQLFollowupFinder.scala b/codebrag-dao/src/main/scala/com/softwaremill/codebrag/dao/finders/followup/SQLFollowupFinder.scala index 81bd26a2..e1973a6c 100644 --- a/codebrag-dao/src/main/scala/com/softwaremill/codebrag/dao/finders/followup/SQLFollowupFinder.scala +++ b/codebrag-dao/src/main/scala/com/softwaremill/codebrag/dao/finders/followup/SQLFollowupFinder.scala @@ -129,4 +129,39 @@ class SQLFollowupFinder(val database: SQLDatabase, userDAO: UserDAO) extends Fol case like: Like => FollowupLastLikeView(like.id.toString, author.name, like.postingTime, author.avatarUrl) } } + def findAllFollowupsByCommitForDashboard(): FollowupsByCommitListView = db.withTransaction { implicit session => + val followups = findAllFollowups() + val followupReactions = findFollowupReactions(followups) + val lastReactions = findLastReactionsForFollowups(followups) + val reactionAuthors = findReactionAuthors(lastReactions) + val commits = findCommitsForFollowups(followups) + + val followupsGroupedByCommit = followups.groupBy(_.threadCommitId) + + val sortFollowupsForCommitByDate = (f1: FollowupReactionsView, f2: FollowupReactionsView) => f1.lastReaction.date.isAfter(f2.lastReaction.date) + + val followupsForCommits = followupsGroupedByCommit.map { + case (commitId, commitFollowups) => + val followupsForCommitViews = commitFollowups + .map(f => followupToReactionsView(f, followupReactions.getOrElse(f.id, Nil), lastReactions, reactionAuthors)) + .sortWith(sortFollowupsForCommitByDate) + val commit = commits(commitId) + val commitView = FollowupCommitView(commit.id.toString, commit.sha, commit.repoName, commit.authorName, commit.message, commit.authorDate) + FollowupsByCommitView(commitView, followupsForCommitViews) + } + FollowupsByCommitListView(sortFollowupGroupsByNewest(followupsForCommits)) + } + private def findAllFollowups()(implicit session: Session): List[SQLFollowup] = { + followups.list() + } + def findFollowupforDashboard(followupId: ObjectId) = db.withTransaction { implicit session => + val r = for { + followup <- followups.filter(f => f.id === followupId).firstOption + reaction <- findLastReaction(followup.lastReactionId) + author <- userDAO.findPartialUserDetails(List(reaction.authorId)).headOption + commit <- commitInfos.filter(_.id === followup.threadCommitId).firstOption() + } yield recordsToFollowupView(commit, reaction, author, followup) + + r.fold[Either[String, SingleFollowupView]](Left("No such followup"))(Right(_)) + } } diff --git a/codebrag-rest/src/main/scala/ScalatraBootstrap.scala b/codebrag-rest/src/main/scala/ScalatraBootstrap.scala index 61e21022..57a35d64 100644 --- a/codebrag-rest/src/main/scala/ScalatraBootstrap.scala +++ b/codebrag-rest/src/main/scala/ScalatraBootstrap.scala @@ -75,6 +75,7 @@ class ScalatraBootstrap extends LifeCycle with Logging { context.mount(new CommitsServlet(authenticator, toReviewCommitsFinder, allCommitsFinder, reactionFinder, addCommentUseCase, reviewCommitUseCase, userReactionService, userDao, diffWithCommentsService, unlikeUseCaseFactory, likeUseCase), Prefix + CommitsServlet.MAPPING_PATH) context.mount(new FollowupsServlet(authenticator, followupFinder, followupDoneUseCase), Prefix + FollowupsServlet.MappingPath) +context.mount(new AllFollowupsServlet(authenticator, followupFinder, followupDoneUseCase), Prefix + AllFollowupsServlet.MappingPath) context.mount(new VersionServlet, Prefix + "version") context.mount(new ConfigServlet(config, authenticator), Prefix + "config") context.mount(new InvitationServlet(authenticator, generateInvitationCodeUseCase, sendInvitationEmailUseCase), Prefix + "invitation") diff --git a/codebrag-rest/src/main/scala/com/softwaremill/codebrag/rest/AllFollowupsServlet.scala b/codebrag-rest/src/main/scala/com/softwaremill/codebrag/rest/AllFollowupsServlet.scala new file mode 100644 index 00000000..73f5c477 --- /dev/null +++ b/codebrag-rest/src/main/scala/com/softwaremill/codebrag/rest/AllFollowupsServlet.scala @@ -0,0 +1,38 @@ +package com.softwaremill.codebrag.rest + +import com.softwaremill.codebrag.service.user.Authenticator +import org.scalatra.json.JacksonJsonSupport +import org.bson.types.ObjectId +import org.scalatra.NotFound +import com.softwaremill.codebrag.dao.finders.followup.FollowupFinder +import com.softwaremill.codebrag.dao.finders.views.SingleFollowupView +import com.softwaremill.codebrag.usecases.reactions.FollowupDoneUseCase + +class AllFollowupsServlet(val authenticator: Authenticator, + followupFinder: FollowupFinder, + followupDoneUseCase: FollowupDoneUseCase) + extends JsonServletWithAuthentication with JacksonJsonSupport { + + get("/") { + haltIfNotAuthenticated() + followupFinder.findAllFollowupsByCommitForDashboard() + } + + get("/:id") { + haltIfNotAuthenticated() + val followupId = params("id") + followupFinder.findFollowupforDashboard(new ObjectId(followupId)) match { + case Right(followup) => followup + case Left(msg) => NotFound(msg) + } + } + + delete("/:id") { + haltIfNotAuthenticated() + followupDoneUseCase.execute(user.id, new ObjectId(params("id"))) + } +} + +object AllFollowupsServlet { + val MappingPath = "allfollowups" +} diff --git a/codebrag-ui/app/index.html b/codebrag-ui/app/index.html index c95dc6b9..683e66e9 100644 --- a/codebrag-ui/app/index.html +++ b/codebrag-ui/app/index.html @@ -127,6 +127,10 @@ + + + + @@ -225,6 +229,14 @@ +