I have a simple class (Model) with 3 variables id (p.k and auto increment) url (String) count (int)
Client can add url and can fetch url by id. The problem is I need to count how many times each url is been called.
My Pojo ->
@Entity
@Data
@NoArgsConstructor
public class Sortner {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
private String url;
private Integer counter;
}
Controller ->
@GetMapping("/findById")
public ResponseEntity<?> findById(Integer id) {
return new ResponseEntity<>(sortnerService.findById(id), HttpStatus.OK);
}
Repo is just extending JpaRepository ..
Service ->
public String findById(Integer id) {
Sortner sortner = new Sortner();
return "no. of times api called =>"+sortner.getCounter()+1 ;
}
That's what I have tried to do but this is not returning response as I wanted its just returning 1 no matter how many times I call api using Swagger (YES the logic is really shit) I don't know how to resolve this and make it work please help