Skip to content

Commit

Permalink
Merge pull request #36 from participating-online/feature/28-unread-count
Browse files Browse the repository at this point in the history
Implemented unread count
  • Loading branch information
jgrim authored Nov 25, 2023
2 parents 0fa3c5c + b1a2003 commit 4003d2e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.sublinks.sublinksapi.api.lemmy.v3.user.models.GetPersonMentions;
import com.sublinks.sublinksapi.api.lemmy.v3.user.models.GetPersonMentionsResponse;
import com.sublinks.sublinksapi.api.lemmy.v3.user.models.GetRepliesResponse;
import com.sublinks.sublinksapi.api.lemmy.v3.user.models.GetUnreadCount;
import com.sublinks.sublinksapi.api.lemmy.v3.user.models.GetUnreadCountResponse;
import com.sublinks.sublinksapi.api.lemmy.v3.user.models.MarkPersonMentionAsRead;
import com.sublinks.sublinksapi.api.lemmy.v3.user.models.PersonMentionResponse;
Expand All @@ -31,6 +32,7 @@
import com.sublinks.sublinksapi.person.repositories.PersonMentionRepository;
import com.sublinks.sublinksapi.person.repositories.PersonRepository;
import com.sublinks.sublinksapi.person.services.PersonService;
import com.sublinks.sublinksapi.privatemessages.repositories.PrivateMessageRepository;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
Expand Down Expand Up @@ -71,6 +73,7 @@ public class UserController {
private final LemmyPersonMentionService lemmyPersonMentionService;
private final CommentReplyRepository commentReplyRepository;
private final LemmyCommentReplyService lemmyCommentReplyService;
private final PrivateMessageRepository privateMessageRepository;

@Operation(summary = "Get the details for a person.")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK", content = {
Expand Down Expand Up @@ -149,8 +152,8 @@ GetRepliesResponse replies(@Valid final GetReplies getReplies, JwtPerson princip

final List<CommentReply> commentReplies = commentReplyRepository.allCommentReplysBySearchCriteria(
com.sublinks.sublinksapi.comment.models.CommentReplySearchCriteria.builder()
.sortType(getReplies.sort()).unreadOnly(getReplies.unread_only() != null
&& getReplies.unread_only())
.sortType(getReplies.sort())
.unreadOnly(getReplies.unread_only() != null && getReplies.unread_only())
.page(getReplies.page()).perPage(getReplies.limit()).build());

final List<CommentReplyView> commentReplyViews = new ArrayList<>();
Expand Down Expand Up @@ -246,8 +249,18 @@ public LoginResponse saveUserSettings(@Valid @RequestBody SaveUserSettings saveU
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK", content = {
@Content(mediaType = MediaType.APPLICATION_JSON_VALUE, schema = @Schema(implementation = GetUnreadCountResponse.class))})})
@GetMapping("unread_count")
GetUnreadCountResponse unreadCount() {
GetUnreadCountResponse unreadCount(@Valid final GetUnreadCount getUnreadCountForm,
JwtPerson principal) {

final Person person = Optional.ofNullable((Person) principal.getPrincipal())
.orElseThrow(() -> new ResponseStatusException(HttpStatus.UNAUTHORIZED));

GetUnreadCountResponse.GetUnreadCountResponseBuilder builder = GetUnreadCountResponse.builder();

builder.mentions((int) personMentionRepository.countByRecipientAndIsReadFalse(person));
builder.replies((int) commentReplyRepository.countByRecipientAndIsReadFalse(person));
builder.private_messages((int) privateMessageRepository.countByRecipientAndIsReadFalse(person));

return GetUnreadCountResponse.builder().build();
return builder.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.sublinks.sublinksapi.comment.repositories;

import com.sublinks.sublinksapi.comment.dto.CommentReply;
import com.sublinks.sublinksapi.person.dto.Person;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface CommentReplyRepository extends JpaRepository<CommentReply, Long>, CommentReplyRepositorySearch {
public interface CommentReplyRepository extends JpaRepository<CommentReply, Long>,
CommentReplyRepositorySearch {

long countByRecipientAndIsReadFalse(Person recipient);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.sublinks.sublinksapi.person.repositories;

import com.sublinks.sublinksapi.person.dto.Person;
import com.sublinks.sublinksapi.person.dto.PersonMention;
import org.springframework.data.jpa.repository.JpaRepository;

public interface PersonMentionRepository extends JpaRepository<PersonMention, Long>,
PersonMentionRepositorySearch {

long countByRecipientAndIsReadFalse(Person recipient);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.sublinks.sublinksapi.privatemessages.repositories;

import com.sublinks.sublinksapi.person.dto.Person;
import com.sublinks.sublinksapi.privatemessages.dto.PrivateMessage;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;

public interface PrivateMessageRepository extends JpaRepository<PrivateMessage, Long>,
PrivateMessageRepositorySearch {

long countByRecipientAndIsReadFalse(Person recipient);
}

0 comments on commit 4003d2e

Please sign in to comment.