'Why clicks value is not updating?

I'm am trying to create a link shortener using Spring Boot. I want everytime the user access the shorten link, the clicks value should increase by 1 but its seems not to be working when I try to access the link from the browser but it works fine when I use postman.

Please view my code below


public class DosuController {

    private final DosuService dosuService;

    public DosuController(DosuService dosuService) {
        this.dosuService = dosuService;
    }

    @GetMapping("/{dosu}")
    public ResponseEntity<Void> redirect(@PathVariable("dosu") String dosu) {
        return dosuService.redirect(dosu);
    }
}


//SERVICE
public class DosuService {

    private final DosuRepo dosuRepo;

    public DosuService(DosuRepo dosuRepo) {
        this.dosuRepo = dosuRepo;
    }

   public ResponseEntity<Void> 
    redirect(String dosu){
     Dosu dosus = 
     dosuRepo.findByDosu(dosu);
     if(dosus == null){
       throw new 
       ResponseStatusException 
       (HttpStatus.NOT_FOUND,"Dosu not found with name: +"dosu);
 }

dosus.setClicks(dosus.getClicks()+1);

dosusRepo.save(dosus)


HttpHeaders headers = new HttpHeaders();
headers.setLocation(URI.create(dosus.getRedirectUrl()));
 return new ResponseEntity<>(headers, HttpStatus.MOVED_PERMANENTLY);
   }
}



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source