package sanchez.sergio.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import sanchez.sergio.persistence.repositories.NotificationRepository;

/**
 * @author sergio
 */
@Api
@RestController
@RequestMapping("/v1/api/")
public class NotificationController {
    
    @Autowired
    private NotificationRepository notificationRepository;
   
    @GetMapping(path = "/notifications/{userId}")
    @ApiOperation(value = "getNotifications", nickname = "getNotifications", notes="Get Notifications", response = ResponseEntity.class)
    public ResponseEntity getNotifications(@ApiParam(value = "userId", required = true) @PathVariable Long userId) {
        return Optional.ofNullable(notificationRepository.findByUserId(userId))
                .map(e -> new ResponseEntity<>(e, HttpStatus.OK))
                .orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
    }
    
}

@@ -339,16 +339,94 @@
 ntity;%0D%0A
+import org.springframework.security.core.annotation.AuthenticationPrincipal;%0D%0A
 import o
@@ -469,32 +469,32 @@
 on.GetMapping;%0D%0A
-
 import org.sprin
@@ -738,16 +738,72 @@
 sitory;%0D
+%0Aimport sanchez.sergio.security.CommonUserDetailsAware;%0D
 %0A%0D%0A/**%0D%0A
@@ -1307,24 +1307,24 @@
  userId) %7B%0D%0A
-
         retu
@@ -1542,11 +1542,566 @@
 %0D%0A    %0D%0A
+    @GetMapping(path = %22/notifications/self%22)%0D%0A    @ApiOperation(value = %22getSelfNotifications%22, nickname = %22getSelfNotifications%22, notes=%22Get Self Notifications%22, response = ResponseEntity.class)%0D%0A    public ResponseEntity getNotifications(@AuthenticationPrincipal CommonUserDetailsAware%3CLong%3E principal) %7B%0D%0A        return Optional.ofNullable(notificationRepository.findByUserId(principal.getUserId()))%0D%0A                .map(e -%3E new ResponseEntity%3C%3E(e, HttpStatus.OK))%0D%0A                .orElse(new ResponseEntity%3C%3E(HttpStatus.NOT_FOUND));%0D%0A    %7D%0D%0A    %0D%0A
 %7D%0D%0A

Add get self notifications