Untitled

mail@pastecode.io avatar
unknown
plain_text
5 days ago
1.0 kB
3
Indexable
Never
@PostMapping("/insertdata")
    public ResponseEntity<String> insertClientFilterIPs(
            @RequestHeader("key") String secretHeader,
            @RequestBody MultipartFile file) throws Exception {
        if(!key.equals(secretHeader)) return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("Unauthorized");
        ipFilterService.processIPFilterFile(file);
        return ResponseEntity.ok("File processed successfully.");
    }

    @GetMapping("/{aid}")
    public ResponseEntity<Object> getClientFilterIpsByAid(
            @RequestHeader("key") String secretHeader,
            @PathVariable String aid) throws Exception {
        if(!key.equals(secretHeader)) return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("Unauthorized");
        return ResponseEntity.ok(ipFilterService.getListIpsFilter(aid));
    }


t muốn tại 1 helper để xử lý if(!key.equals(secretHeader)) return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("Unauthorized");
trách duplicate code 
Leave a Comment