0

I have this function addBug(String title, String description, LocalDateTime created, LocalDateTime updated, ObjectId projectId) in my Service class:

public Bug addBug(String title, String description, LocalDateTime created, LocalDateTime updated,
            ObjectId projectId) {
        Bug newBug = bugRepository.insert(new Bug(title, description, created, updated));

        mongoTemplate.update(Project.class)
                .matching(Criteria.where("_id").is(projectId))
                .apply(new Update().push("bugs").value(newBug))
                .first();

        return newBug;
        // return bugRepository.save(bug); // old way
    }

I want to use this in my Controller class, using a '@PostMapping' using the function 'createBug()', this is how i coded the function but I am getting an error,

@PostMapping
    public ResponseEntity<Bug> createBug(@RequestBody Bug bug) {
        return new ResponseEntity<Bug>(bugService.addBug(bug), HttpStatus.CREATED);
    }

How do I correctly make use of the 'addBug()' function the 'createBug()' function? I am new to spring and java.

I tried passing the same variables as in addBug() when using it in the createBug() but I still get error lines.

  • "I am getting an error" ... what error do you get? you must pass all the parameters the signature of your method takes, otherwise it won't find the method – Stultuske Apr 28 '23 at 07:11

0 Answers0