Skip to content

Commit

Permalink
fix: notification updates
Browse files Browse the repository at this point in the history
  • Loading branch information
cyyynthia committed Dec 13, 2023
1 parent e612c0c commit 4aebb94
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class NotificationsController(
private val userNotificationService: UserNotificationService,
private val userNotificationModelAssembler: UserNotificationModelAssembler,
) {
@GetMapping("/")
@GetMapping("")
@Operation(summary = "Fetch the current user's notifications")
fun getNotifications(
@RequestParam("status", defaultValue = "UNREAD,READ") status: Set<NotificationStatus>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class UserNotificationTranslationTest : AbstractNotificationTest() {

waitUntilUserNotificationDispatch()

println(userNotificationRepository.findAllByRecipient(testData.alice).map { it.type })
userNotificationRepository.findAllByRecipient(testData.alice).assert.hasSize(1)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ class TestDataService(
}

private fun saveAllKeyDependants(keyBuilders: List<KeyBuilder>) {
val metas = keyBuilders.map { it.data.meta?.self }.filterNotNull()
val metas = keyBuilders.mapNotNull { it.data.meta?.self }
tagService.saveAll(metas.flatMap { it.tags })
keyMetaService.saveAll(metas)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,41 +68,53 @@ class UserNotificationService(
status: Set<NotificationStatus>,
pageable: Pageable,
): List<UserNotification> {
return userNotificationRepository.findNotificationsOfUserFilteredPaged(user, status, pageable)
return userNotificationRepository.findNotificationsOfUserFilteredPaged(
user,
status.map { it.toString() },
pageable,
)
}

fun getUnreadNotificationsCount(user: Long): Int {
return userNotificationRepository.countNotificationsByRecipientIdAndUnreadTrue(user)
}

@Transactional
fun markAsRead(user: Long, notifications: Collection<Long>) {
return userNotificationRepository.markAsRead(user, notifications)
}

@Transactional
fun markAllAsRead(user: Long) {
return userNotificationRepository.markAllAsRead(user)
}

@Transactional
fun markAsUnread(user: Long, notifications: Collection<Long>) {
return userNotificationRepository.markAsUnread(user, notifications)
}

@Transactional
fun markAsDone(user: Long, notifications: Collection<Long>) {
return userNotificationRepository.markAsDone(user, notifications)
}

@Transactional
fun markAllAsDone(user: Long) {
return userNotificationRepository.markAllAsDone(user)
}

@Transactional
fun unmarkAsDone(user: Long, notifications: Collection<Long>) {
return userNotificationRepository.unmarkAsDone(user, notifications)
}

@Transactional
fun deleteAllByUserId(userId: Long) {
userNotificationRepository.deleteAllByUserId(userId)
}

@Transactional
fun deleteAllByProjectId(projectId: Long) {
userNotificationRepository.deleteAllByProjectId(projectId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package io.tolgee.repository.notifications
import io.tolgee.model.Project
import io.tolgee.model.UserAccount
import io.tolgee.model.notifications.UserNotification
import io.tolgee.notifications.NotificationStatus
import io.tolgee.notifications.NotificationType
import org.springframework.data.domain.Pageable
import org.springframework.data.jpa.repository.JpaRepository
Expand All @@ -36,17 +35,16 @@ interface UserNotificationRepository : JpaRepository<UserNotification, Long> {
@Query(
"""
FROM UserNotification un WHERE
(io.tolgee.notifications.NotificationStatus.UNREAD IN :status AND
un.unread = true AND un.markedDoneAt IS NULL) OR
(io.tolgee.notifications.NotificationStatus.READ IN :status AND
un.unread = false AND un.markedDoneAt IS NULL) OR
(io.tolgee.notifications.NotificationStatus.DONE IN :status AND
un.markedDoneAt IS NOT NULL)
un.recipient.id = :recipient AND (
('UNREAD' IN :status AND un.unread = true AND un.markedDoneAt IS NULL) OR
('READ' IN :status AND un.unread = false AND un.markedDoneAt IS NULL) OR
('DONE' IN :status AND un.markedDoneAt IS NOT NULL)
)
"""
)
fun findNotificationsOfUserFilteredPaged(
recipient: Long,
status: Set<NotificationStatus>,
status: List<String>,
pageable: Pageable,
): List<UserNotification>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ package io.tolgee.controllers.internal.e2e_data
import io.swagger.v3.oas.annotations.Hidden
import io.tolgee.development.testDataBuilder.builders.TestDataBuilder
import io.tolgee.development.testDataBuilder.data.NotificationsTestData
import io.tolgee.repository.UserAccountRepository
import io.tolgee.service.security.UserAccountService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.transaction.annotation.Transactional
import org.springframework.web.bind.annotation.CrossOrigin
import org.springframework.web.bind.annotation.GetMapping
Expand All @@ -30,9 +33,20 @@ import org.springframework.web.bind.annotation.RestController
@Hidden
@RequestMapping(value = ["internal/e2e-data/notifications"])
class NotificationsE2eDataController : AbstractE2eDataController() {
@Autowired
lateinit var userAccountRepository: UserAccountRepository

@Autowired
lateinit var userAccountService: UserAccountService

@GetMapping(value = ["/generate"])
@Transactional
fun generateBasicTestData() {
userAccountService.findActive("admin")?.let {
userAccountService.delete(it)
userAccountRepository.delete(it)
}

testDataService.saveTestData(testData)
}

Expand Down

0 comments on commit 4aebb94

Please sign in to comment.