Skip to content

Commit

Permalink
Merge pull request #982 from bounswe/main
Browse files Browse the repository at this point in the history
deploying latest backend changes
  • Loading branch information
halisbal authored Dec 11, 2023
2 parents 116755e + 67f22cd commit d773153
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
package com.app.gamereview.controller;

import com.app.gamereview.dto.request.post.GetPostListFilterRequestDto;
import com.app.gamereview.dto.response.comment.GetPostCommentsResponseDto;
import com.app.gamereview.dto.response.post.GetPostListResponseDto;
import com.app.gamereview.dto.request.notification.GetNotificationsRequestDto;
import com.app.gamereview.model.Notification;
import com.app.gamereview.model.User;
import com.app.gamereview.service.NotificationService;
import com.app.gamereview.service.PostService;
import com.app.gamereview.util.JwtUtil;
import com.app.gamereview.util.validation.annotation.AuthorizationRequired;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;

Expand All @@ -34,9 +24,9 @@ public NotificationController(NotificationService notificationService) {

@AuthorizationRequired
@GetMapping("/get-notifications")
public ResponseEntity<List<Notification>> getNotificationList( @RequestHeader String Authorization, HttpServletRequest request) {
public ResponseEntity<List<Notification>> getNotificationList(@RequestHeader String Authorization, @RequestBody(required = false) GetNotificationsRequestDto filter, HttpServletRequest request) {
User user = (User) request.getAttribute("authenticatedUser");
List<Notification> notifications = notificationService.getNotificationList(user.getId());
List<Notification> notifications = notificationService.getNotificationList(user.getId(), filter);
return ResponseEntity.ok(notifications);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.app.gamereview.dto.request.notification;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class GetNotificationsRequestDto {
private Boolean isRead;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ public class Notification extends BaseModel {
private NotificationParent parentType;
private String message;
private String user;
private Boolean isRead = false;

public Notification(Notification notification) {
this.parent = notification.getParent();
this.parentType = notification.getParentType();
this.message = notification.getMessage();
this.user = notification.getUser();
this.isRead = notification.getIsRead();
}

public void setIsRead(Boolean isRead) {
this.isRead = isRead;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.app.gamereview.service;

import com.app.gamereview.dto.request.notification.CreateNotificationRequestDto;
import com.app.gamereview.dto.request.notification.GetNotificationsRequestDto;
import com.app.gamereview.model.Notification;
import com.app.gamereview.repository.*;
import org.modelmapper.ModelMapper;
Expand All @@ -13,6 +14,7 @@

import java.time.LocalDateTime;
import java.util.List;
import java.util.ArrayList;
@Service
public class NotificationService {
private final NotificationRepository notificationRepository;
Expand All @@ -28,13 +30,30 @@ public NotificationService(NotificationRepository notificationRepository, MongoT
this.modelMapper = modelMapper;
}

public List<Notification> getNotificationList(String userId) {
public List<Notification> getNotificationList(String userId, GetNotificationsRequestDto filter) {
Query query = new Query();
query.addCriteria(Criteria.where("user").is(userId));
if(filter != null && filter.getIsRead() != null){
query.addCriteria(Criteria.where("isRead").is(filter.getIsRead()));
}
query.with(Sort.by(Sort.Direction.DESC, "createdAt"));
List<Notification> notificationList = mongoTemplate.find(query, Notification.class);
return notificationList;

// create a deep copy to return without isRead being changed
List<Notification> copiedList = new ArrayList<>();
for (Notification notification : notificationList) {
copiedList.add(new Notification(notification));
}

if(filter == null || filter.getIsRead() == null){
for (Notification notification : notificationList) {
if(!notification.getIsRead()) {
notification.setIsRead(true);
notificationRepository.save(notification);
}
}
}
return copiedList;
}

public Notification createNotification(CreateNotificationRequestDto request){
Expand Down

0 comments on commit d773153

Please sign in to comment.