AdminController.java

  1. package no.nav.data.team.settings;

  2. import io.swagger.v3.oas.annotations.Operation;
  3. import io.swagger.v3.oas.annotations.responses.ApiResponse;
  4. import io.swagger.v3.oas.annotations.responses.ApiResponses;
  5. import io.swagger.v3.oas.annotations.tags.Tag;
  6. import lombok.RequiredArgsConstructor;
  7. import lombok.extern.slf4j.Slf4j;
  8. import no.nav.data.common.mail.EmailService;
  9. import no.nav.data.common.mail.MailTask;
  10. import no.nav.data.common.security.SecurityUtils;
  11. import no.nav.data.common.security.dto.UserInfo;
  12. import no.nav.data.common.storage.StorageService;
  13. import no.nav.data.team.notify.NotificationService;
  14. import no.nav.data.team.team.domain.Team;
  15. import org.springframework.http.ResponseEntity;
  16. import org.springframework.web.bind.annotation.GetMapping;
  17. import org.springframework.web.bind.annotation.PostMapping;
  18. import org.springframework.web.bind.annotation.RequestMapping;
  19. import org.springframework.web.bind.annotation.RequestParam;
  20. import org.springframework.web.bind.annotation.RestController;

  21. import java.util.UUID;

  22. @Slf4j
  23. @RestController
  24. @RequiredArgsConstructor
  25. @Tag(name = "Admin", description = "Admin ops")
  26. @RequestMapping("/admin")
  27. public class AdminController {

  28.     private final NotificationService notificationService;
  29.     private final EmailService emailService;
  30.     private final StorageService storage;

  31.     @Operation(summary = "mail test")
  32.     @ApiResponses(value = {@ApiResponse(description = "mail")})
  33.     @GetMapping(value = "/mail", produces = "text/html")
  34.     public ResponseEntity<String> mail() {
  35.         testMail();
  36.         return ResponseEntity.ok("ok");
  37.     }

  38.     @Operation(summary = "trigger nudge")
  39.     @ApiResponses(value = {@ApiResponse(description = "nudge")})
  40.     @PostMapping(value = "/nudge", produces = "text/html")
  41.     public ResponseEntity<String> nudge(@RequestParam(value = "teamId") UUID teamId) {
  42.         var team = storage.get(teamId, Team.class);
  43.         notificationService.nudge(team);
  44.         return ResponseEntity.ok("ok");
  45.     }

  46.     public void testMail() {
  47.         var email = SecurityUtils.getCurrentUser().map(UserInfo::getEmail).orElseThrow();
  48.         emailService.sendMail(MailTask.builder().to(email).subject("test").body("testbody").build());
  49.     }

  50. }