Index: src/main/java/com/wediscussmovies/project/web/controller/DiscussionController.java
===================================================================
--- src/main/java/com/wediscussmovies/project/web/controller/DiscussionController.java	(revision e0ef1b13a29101c3f7a56f68da8dcdc8cce98b76)
+++ src/main/java/com/wediscussmovies/project/web/controller/DiscussionController.java	(revision e0ef1b13a29101c3f7a56f68da8dcdc8cce98b76)
@@ -0,0 +1,175 @@
+package com.wediscussmovies.project.web.controller;
+
+import com.wediscussmovies.project.LoggedUser;
+import com.wediscussmovies.project.model.Discussion;
+import com.wediscussmovies.project.model.Reply;
+import com.wediscussmovies.project.model.User;
+import com.wediscussmovies.project.service.DiscussionService;
+import com.wediscussmovies.project.service.MovieService;
+import com.wediscussmovies.project.service.PersonService;
+import com.wediscussmovies.project.service.ReplyService;
+import org.springframework.security.authentication.AnonymousAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@Controller
+@RequestMapping("/discussions")
+public class DiscussionController {
+
+    private final DiscussionService discussionService;
+    private final ReplyService replyService;
+    private final MovieService movieService;
+    private final PersonService personService;
+
+    public DiscussionController(DiscussionService discussionService, ReplyService replyService, MovieService movieService, PersonService personService) {
+        this.discussionService = discussionService;
+        this.replyService = replyService;
+        this.movieService = movieService;
+        this.personService = personService;
+    }
+
+    @GetMapping()
+    public String getDiscussions(@RequestParam(required = false) String titleSearch,
+                                    Model model){
+        /* 1.Validacija i  na frontend so, da ne se isprakja baranjeto, ako titleSearch e null ili empty
+         da ne se preoptovaruva serverot so baranja za titleSearch koga e null!
+
+         */
+        List<Discussion> discussions = discussionService.listAllByTitle(titleSearch);
+        model.addAttribute("discussions", discussions);
+        model.addAttribute("contentTemplate", "discussionsList");
+        model.addAttribute("user",LoggedUser.getLoggedUser());
+        return "template";
+    }
+
+    @GetMapping("/{id}")
+    public String getDiscussion(
+            @PathVariable Integer id,
+            Model model){
+        /*
+            2. Moze da se vrati indikator deka takva diskusija ne postoi! - postaveno
+         */
+        try {
+            Discussion disc = discussionService.findById(id);
+            model.addAttribute("disc", disc);
+            model.addAttribute("contentTemplate", "discussion");
+            model.addAttribute("user",LoggedUser.getLoggedUser());
+            model.addAttribute("replies",this.replyService.findAllByDiscussion(disc));
+
+            return "template";
+        }
+        catch (RuntimeException exception){
+            return "redirect:/discussions?error="+exception.getMessage();
+
+        }
+    }
+    @GetMapping("/all/{id}")
+    public String getDiscussionForId(@PathVariable Integer id,@RequestParam Character type, Model model){
+
+        model.addAttribute("discussions", this.discussionService.findAllForPersonOrMovie(id,type));
+        model.addAttribute("contentTemplate", "discussionForType");
+        return "template";
+
+    }
+
+    @GetMapping("/{id}/replies")
+    public String getRepliesToDiscussion(
+            @PathVariable Integer id,
+            Model model){
+
+        try {
+            Discussion discussion = discussionService.findById(id);
+            model.addAttribute("discussion", discussion);
+            model.addAttribute("contentTemplate", "discussionReply");
+            return "template";
+        }
+        catch (RuntimeException exception){
+            return "redirect:/discussions?error="+exception.getMessage();
+
+        }
+
+    }
+
+
+    @GetMapping("/add/{id}")
+    public String getFormForEdit(Model model,
+                                           @PathVariable Integer id)
+    {
+        Discussion discussion = this.discussionService.findById(id);
+        setModelPropertiesForForm(model);
+        model.addAttribute("discussion", discussion);
+
+        return "template";
+    }
+    @GetMapping("/add")
+    public String getFormForAdd(Model model)
+    {
+        setModelPropertiesForForm(model);
+
+        return "template";
+    }
+
+
+    @PostMapping("/save")
+    public String saveDiscussion(
+           @RequestParam Integer idDiscussed,
+            @RequestParam String title,
+            @RequestParam String text,
+            @RequestParam Character type    ){
+
+
+
+        try{
+
+            discussionService.save(type,idDiscussed, title, text, LoggedUser.getLoggedUser());
+            return "redirect:/discussions";
+
+        }
+
+        catch (RuntimeException exc){
+            return "redirect:/discussions?error="+exc.getMessage();
+
+        }
+    }
+
+    @PostMapping("/save/{discussionId}/")
+    public String editDiscussion(
+                                               @PathVariable Integer discussionId,
+                                               @RequestParam String title,
+                                               @RequestParam String text,
+                                               @RequestParam Character type,
+                                               @RequestParam Integer idDiscussed
+                                               ){
+
+
+
+
+        try{
+
+
+            discussionService.edit(discussionId,type,idDiscussed, title, text);
+            return "redirect:/discussions";
+
+        }
+
+        catch (RuntimeException exc){
+            return "redirect:/discussions?error="+exc.getMessage();
+
+        }
+    }
+
+    private void setModelPropertiesForForm(Model model){
+        model.addAttribute("movies",this.movieService.listAll());
+        model.addAttribute("persons",this.personService.findAll());
+        model.addAttribute("contentTemplate", "discussionsAdd");
+
+    }
+
+
+}
Index: src/main/java/com/wediscussmovies/project/web/controller/DiscussionsController.java
===================================================================
--- src/main/java/com/wediscussmovies/project/web/controller/DiscussionsController.java	(revision 3ded84dfbf8ff25bf27cc822ac97b84a063fa95a)
+++ 	(revision )
@@ -1,145 +1,0 @@
-package com.wediscussmovies.project.web.controller;
-
-import com.wediscussmovies.project.model.*;
-
-import com.wediscussmovies.project.service.DiscussionService;
-import com.wediscussmovies.project.service.MovieService;
-import com.wediscussmovies.project.service.PersonService;
-import com.wediscussmovies.project.service.ReplyService;
-import org.springframework.stereotype.Controller;
-import org.springframework.ui.Model;
-import org.springframework.web.bind.annotation.*;
-
-import javax.servlet.http.HttpServletRequest;
-import java.sql.Date;
-import java.time.LocalDate;
-import java.util.List;
-import java.util.Optional;
-
-@Controller
-@RequestMapping("/discussions")
-public class DiscussionsController {
-    private final DiscussionService discussionService;
-    private final ReplyService replyService;
-    private final MovieService movieService;
-    private final PersonService personService;
-    public DiscussionsController(DiscussionService discussionService, ReplyService replyService, MovieService movieService, PersonService personService) {
-        this.discussionService = discussionService;
-        this.replyService = replyService;
-        this.movieService = movieService;
-        this.personService = personService;
-    }
-
-    @GetMapping("/")
-    public String getDiscussions(@RequestParam(required = false) String titleSearch,
-                                    Model model){
-        List<Discussion> discussions = discussionService.listAll();
-        if(titleSearch != null && !titleSearch.isEmpty()){
-            discussions = discussionService.listAllByTitle(titleSearch);
-        }
-        model.addAttribute("discussions", discussions);
-        model.addAttribute("contentTemplate", "discussionsList");
-        return "template";
-    }
-
-    @GetMapping("/{id}")
-    public String getDiscussion(
-            @PathVariable Integer id,
-            Model model){
-        Optional<Discussion> discussion = discussionService.findById(id);
-        if(discussion.isEmpty())
-            return "redirect:/discussions";
-        model.addAttribute("discussion", discussion);
-        model.addAttribute("contentTemplate", "discussionsDiscussion");
-        return "template";
-    }
-
-    @GetMapping("/{id}/reply")
-    public String getReplyToDiscussion(
-            @PathVariable Integer id,
-            Model model){
-        Optional<Discussion> discussion = discussionService.findById(id);
-        if(discussion.isEmpty())
-            return "redirect:/discussions";
-        model.addAttribute("discussion", discussion);
-        model.addAttribute("contentTemplate", "discussionsReply");
-        return "template";
-    }
-    @PostMapping("/{id}/reply/confirm")
-    public String getReplyToDiscussionConfirm(
-            @PathVariable Integer id,
-            @RequestParam String text,
-            HttpServletRequest request){
-        Optional<Discussion> discussion = discussionService.findById(id);
-        User user = (User) request.getSession().getAttribute("user");
-        if(user == null){
-            return "redirect:/login";
-        }
-        Date date = Date.valueOf(LocalDate.now());
-        if(discussion.isEmpty())
-            return "redirect:/discussions";
-        //Reply reply = new Reply(discussion.get(), user, date, text);
-       // replyService.save(reply);
-        return "redirect:/discussions/"+id;
-    }
-
-    @GetMapping("/movies/add/{id}")
-    public String getAddDiscussionForMovie(Model model,
-                                           @PathVariable Integer id,
-                                           HttpServletRequest request){
-        model.addAttribute("contentTemplate", "discussionsAdd");
-        request.setAttribute("movieId", id);
-        return "template";
-    }
-
-    @PostMapping("/movies/add/confirm")
-    public String getAddDiscussionMovieConfirm(Model model,
-                                               HttpServletRequest request,
-                                               @RequestParam String title,
-                                               @RequestParam String text){
-        User user = (User) request.getSession().getAttribute("user");
-        if(user == null){
-            return "redirect:/login";
-        }
-        Integer movie_id = (Integer) request.getSession().getAttribute("movieId");
-        request.getSession().setAttribute("movieId", null);
-        Optional<Movie> movieOp = movieService.findById(movie_id);
-        if(movieOp.isEmpty())
-            return "redirect:/movies";
-      //  Discussion discussion = new Discussion('M',text, title, Date.valueOf(LocalDate.now()),user,movieOp.get(),null);
-       // discussionService.save(discussion);
-        return "redirect:/discussions";
-    }
-
-
-    @GetMapping("/persons/add/{id}")
-    public String getAddDiscussionForPerson(Model model,
-                                           @PathVariable Integer id,
-                                           HttpServletRequest request){
-        model.addAttribute("contentTemplate", "discussionsAdd");
-        request.setAttribute("personId", id);
-        return "template";
-    }
-
-    @PostMapping("/persons/add/confirm")
-    public String getAddDiscussionForPersonConfirm(Model model,
-                                               HttpServletRequest request,
-                                               @RequestParam String title,
-                                               @RequestParam String text){
-        User user = (User) request.getSession().getAttribute("user");
-        if(user == null){
-            return "redirect:/login";
-        }
-        Integer person_id = (Integer) request.getSession().getAttribute("personId");
-        Optional<Person> personOp = personService.findById(person_id);
-        request.getSession().setAttribute("personId", null);
-        if(personOp.isEmpty())
-            return "redirect:/discussions";
-
-      //  Discussion discussion = new Discussion('P',title, text,Date.valueOf(LocalDate.now()),user,null,personOp.get());
-      //  discussionService.save(discussion);
-        return "redirect:/discussions";
-    }
-
-
-}
Index: src/main/java/com/wediscussmovies/project/web/controller/MovieController.java
===================================================================
--- src/main/java/com/wediscussmovies/project/web/controller/MovieController.java	(revision 3ded84dfbf8ff25bf27cc822ac97b84a063fa95a)
+++ src/main/java/com/wediscussmovies/project/web/controller/MovieController.java	(revision e0ef1b13a29101c3f7a56f68da8dcdc8cce98b76)
@@ -1,10 +1,16 @@
 package com.wediscussmovies.project.web.controller;
 
-import com.wediscussmovies.project.exception.MovieIdNotFoundException;
-import com.wediscussmovies.project.model.*;
-
+import com.wediscussmovies.project.model.Movie;
+import com.wediscussmovies.project.model.Person;
+import com.wediscussmovies.project.model.User;
 import com.wediscussmovies.project.service.GenreService;
 import com.wediscussmovies.project.service.MovieService;
 import com.wediscussmovies.project.service.PersonService;
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+import org.springframework.security.authentication.AnonymousAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.security.core.userdetails.UserDetails;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
@@ -12,7 +18,6 @@
 
 import java.sql.Date;
-import java.util.LinkedList;
+import java.time.LocalDate;
 import java.util.List;
-import java.util.Optional;
 
 @Controller
@@ -30,5 +35,6 @@
 
     @GetMapping
-    public String getMovies(@RequestParam(required = false) String titleQuery, Model model){
+    public String getMovies(@RequestParam(required = false) String titleQuery, Model model,
+                            @RequestParam(required = false) String error){
         List<Movie> movies;
         if(titleQuery == null ) {
@@ -39,8 +45,18 @@
         }
 
+        Authentication auth = SecurityContextHolder.getContext().getAuthentication();
+
+        if (!(auth instanceof AnonymousAuthenticationToken)){
+            UserDetails userDetails = (UserDetails) auth.getPrincipal();
+            User user = (User) userDetails;
+          model.addAttribute("likedMovies",this.movieService.findLikedMoviesByUser(user));
+          model.addAttribute("user",user);
+        }
 
         model.addAttribute("movies", movies);
         model.addAttribute("contentTemplate", "moviesList");
-        return "list";
+        if (error != null && !error.equals(" "))
+            model.addAttribute("error",error);
+        return "template";
     }
 
@@ -48,7 +64,6 @@
     @GetMapping("/add")
     public String addMovie(Model model){
-        model.addAttribute("directors", personService.findAllDirectors());
-        model.addAttribute("actors", personService.findAllActors());
-        model.addAttribute("genres", genreService.findAll());
+
+        addModelProperties(model);
         model.addAttribute("contentTemplate", "moviesAdd");
         return "template";
@@ -56,167 +71,91 @@
 
 
-    @PostMapping("/{id}/delete")
-    public String addMovie(@PathVariable Integer id){
-        Optional<Movie> movie = movieService.findById(id);
-        if(movie.isPresent()){
-            movieService.deleteById(movie.get().getMovieId());
-        }
-        return "redirect:/movies";
+    @GetMapping("/{id}/delete")
+    public String deleteMovie(@PathVariable Integer id){
+
+       try {
+           this.movieService.deleteById(id);
+           return "redirect:/movies";
+
+       }
+       catch (RuntimeException exc){
+           return "redirect:/movies?error="+exc.getMessage();
+       }
     }
 
-    @PostMapping("/add/confirm")
-    public String addMoviePost(@RequestParam String title,
+    @PostMapping("/save")
+    public String saveMovie(
+
+
+
+            @RequestParam String title,
                                @RequestParam String description,
-                               @RequestParam String image_url,
-                               @RequestParam Date airing_date,
-                               @RequestParam Double rating,
-                               @RequestParam Integer director_id,
+                               @RequestParam String imageUrl,
+                               @RequestParam(required = false) Double rating,
+                               @RequestParam(required = false) Integer directorId,
+                               @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate airingDate,
                                @RequestParam List<Integer> actors,
-                               @RequestParam List<Integer> genres,
-                               Model model){
-        if(title == null || title.isEmpty() ||
-        description == null || description.isEmpty() ||
-        image_url == null || image_url.isEmpty() ||
-        airing_date == null ||
-        rating == null ||
-        director_id == null ||
-        actors == null || actors.size() == 0 ||
-        genres == null || genres.size() == 0)
-        {
-            model.addAttribute("error", "Not enough attributes, make sure all values are inputted, all of them are required");
-            model.addAttribute("hasError", true);
-            return "redirect:/add";
+                               @RequestParam List<Integer> genres
+                            ){
+
+        try {
+            Movie movie = this.movieService.save(title,description,imageUrl,Date.valueOf(airingDate),rating,directorId,actors,genres);
+
+            return "redirect:/movies";
         }
-        List<Person> actorsList = new LinkedList<>();
-        for(Integer id: actors){
-            Optional<Person> person = personService.findActorById(id);
-            if(person.isEmpty()){
-                model.addAttribute("error", "The actor with ID {" + id + "} was not found.");
-                model.addAttribute("hasError", true);
-                return "redirect:/add";
-            }
-            actorsList.add(person.get());
+        catch (RuntimeException exc){
+            return "redirect:/movies?error="+exc.getMessage();
         }
+    }
+    @PostMapping("/save/{movieId}")
+    public String updateMovie(
 
-        List<Genre> genreList = new LinkedList<>();
-        for(Integer id: genres){
-            Optional<Genre> genre = genreService.findById(id);
-            if(genre.isEmpty()){
-                model.addAttribute("error", "The genre with ID {" + id + "} was not found.");
-                model.addAttribute("hasError", true);
-                return "redirect:/add";
-            }
-            genreList.add(genre.get());
+
+            @PathVariable Integer movieId,
+            @RequestParam String title,
+            @RequestParam String description,
+            @RequestParam String imageUrl,
+            @RequestParam(required = false) Double rating,
+            @RequestParam(required = false) Integer directorId,
+            @RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate airingDate,
+            @RequestParam List<Integer> actors,
+            @RequestParam List<Integer> genres
+    ){
+
+        try {
+            Movie movie = this.movieService.edit(movieId,title,description,imageUrl,Date.valueOf(airingDate),rating,directorId,actors,genres);
+
+            return "redirect:/movies";
         }
-
-        Optional<Person> directorOp = personService.findDirectorById(director_id);
-        if(directorOp.isEmpty()){
-            model.addAttribute("error", "The director with ID {" + director_id + "} was not found.");
-            model.addAttribute("hasError", true);
-            return "redirect:/add";
+        catch (RuntimeException exc){
+            return "redirect:/movies?error="+exc.getMessage();
         }
-
-        Person director = directorOp.get();
-
-        Movie movie = new Movie(title, description, image_url, airing_date,
-                    rating, director.getPersonId());
-
-        movieService.save(movie);
-
-        return "redirect:/movies";
     }
 
-    @PostMapping("/edit/confirm")
-    public String editMoviePost(
-                                @RequestParam Integer movie_id,
-                                @RequestParam String title,
-                               @RequestParam String description,
-                               @RequestParam String image_url,
-                               @RequestParam Date airing_date,
-                               @RequestParam Double rating,
-                               @RequestParam Integer director_id,
-                               @RequestParam List<Integer> actors,
-                               @RequestParam List<Integer> genres,
-                               Model model){
-        if(
-                movie_id == null ||
-                title == null || title.isEmpty() ||
-                description == null || description.isEmpty() ||
-                image_url == null || image_url.isEmpty() ||
-                airing_date == null ||
-                rating == null ||
-                director_id == null ||
-                actors == null || actors.size() == 0 ||
-                genres == null || genres.size() == 0)
-        {
-            model.addAttribute("error", "Not enough attributes, make sure all values are inputted, all of them are required");
-            model.addAttribute("hasError", true);
-            return "redirect:/edit";
-        }
 
-        Optional<Movie> movieOptional = movieService.findById(movie_id);
-        if(movieOptional.isEmpty()){
-            model.addAttribute("error", "The movie with ID {" + movie_id + "} was not found.");
-            model.addAttribute("hasError", true);
-            return "redirect:/edit";
-        }
-        Movie movie = movieOptional.get();
-
-        List<Person> actorsList = new LinkedList<>();
-        for(Integer id: actors){
-            Optional<Person> person = personService.findActorById(id);
-            if(person.isEmpty()){
-                model.addAttribute("error", "The actor with ID {" + id + "} was not found.");
-                model.addAttribute("hasError", true);
-                return "redirect:/edit";
-            }
-            actorsList.add(person.get());
-        }
-
-        List<Genre> genreList = new LinkedList<>();
-        for(Integer id: genres){
-            Optional<Genre> genre = genreService.findById(id);
-            if(genre.isEmpty()){
-                model.addAttribute("error", "The genre with ID {" + id + "} was not found.");
-                model.addAttribute("hasError", true);
-                return "redirect:/edit";
-            }
-            genreList.add(genre.get());
-        }
-
-        Optional<Person> directorOp = personService.findDirectorById(director_id);
-        if(directorOp.isEmpty()){
-            model.addAttribute("error", "The director with ID {" + director_id + "} was not found.");
-            model.addAttribute("hasError", true);
-            return "redirect:/edit";
-        }
-
-        Person director = directorOp.get();
-
-        movieService.deleteById(movie_id);
-
-//      //  movie.setActors(actorsList);
-//        movie.setDirector(director);
-//        movie.setGenres(genreList);
-//        movie.setTitle(title);
-//        movie.setDescription(description);
-//        movie.setAringDate(airing_date);
-//        movie.setImageUrl(image_url);
-//        movie.setImbdRating(rating);
-
-        movieService.save(movie);
-
-        return "redirect:/movies";
-    }
 
     @GetMapping("/{id}/edit")
     public String editMovie(@PathVariable Integer id, Model model){
-        Movie movie = movieService.findById(id).orElseThrow(() -> new MovieIdNotFoundException(id));
-        model.addAttribute("directors", personService.findAllDirectors());
+        try {
+            Movie movie = movieService.findById(id);
+            addModelProperties(model);
+            model.addAttribute("movie", movie);
+            model.addAttribute("director",movie.getDirector());
+            model.addAttribute("movieActors",movieService.findAllActorsForMovie(movie));
+            model.addAttribute("movieGenres",movieService.findAllGenresForMovie(movie));
+            model.addAttribute("contentTemplate", "moviesAdd");
+            return "template";
+
+        }
+        catch (RuntimeException exc){
+            return "redirect:/movies?error="+exc.getMessage();
+        }
+
+    }
+    private void addModelProperties(Model model){
+
+        model.addAttribute("directors",  personService.findAllDirectors());
         model.addAttribute("actors", personService.findAllActors());
         model.addAttribute("genres", genreService.findAll());
-        model.addAttribute("movie", movie);
-        model.addAttribute("contentTemplate", "moviesEdit");
-        return "template";
     }
 }
Index: src/main/java/com/wediscussmovies/project/web/controller/PersonController.java
===================================================================
--- src/main/java/com/wediscussmovies/project/web/controller/PersonController.java	(revision e0ef1b13a29101c3f7a56f68da8dcdc8cce98b76)
+++ src/main/java/com/wediscussmovies/project/web/controller/PersonController.java	(revision e0ef1b13a29101c3f7a56f68da8dcdc8cce98b76)
@@ -0,0 +1,128 @@
+package com.wediscussmovies.project.web.controller;
+
+import com.wediscussmovies.project.model.Person;
+import com.wediscussmovies.project.service.MovieService;
+import com.wediscussmovies.project.service.PersonService;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import java.sql.Date;
+import java.util.List;
+
+@Controller
+public class PersonController {
+    private final PersonService personService;
+    private final MovieService movieService;
+
+    public PersonController(PersonService personService, MovieService movieService) {
+        this.personService = personService;
+        this.movieService = movieService;
+    }
+
+    /*
+    1. Prebaruvanjeto po ime i prezime posoodvetno e da bide na frontend
+        Da ne se preoptovaruva server i klient da ceka koga moze vo browser vekje dobieni da se filtrirat
+     */
+    @GetMapping("/actors")
+    public String getActors(Model model, @RequestParam(required = false) String nameAndSurname){
+        List<Person> persons = personService.findPersonsByNameOrSurname('A',nameAndSurname);
+        model.addAttribute("persons", persons);
+        model.addAttribute("contentTemplate", "personsList");
+
+        return "template";
+    }
+    /*
+      2. Prebaruvanjeto po ime i prezime posoodvetno e da bide na frontend
+          Da ne se preoptovaruva server i klient da ceka koga moze vo browser vekje dobieni da se filtrirat
+       */
+    @GetMapping("/directors")
+    public String getDirectors(Model model, @RequestParam(required = false) String nameAndSurname){
+        List<Person> persons = personService.findPersonsByNameOrSurname('D',nameAndSurname);
+        model.addAttribute("persons", persons);
+        model.addAttribute("contentTemplate", "personsList");
+        return "template";
+    }
+
+    @GetMapping("/persons/add")
+    public String addingFormForPerson( Model model){
+
+        addModelPropertiesForForm(model);
+        return "template";
+    }
+    @GetMapping("persons/edit/{personId}")
+    public String editPerson(@PathVariable Integer personId, Model model){
+
+        try {
+            Person person = this.personService.findById(personId);
+            addModelPropertiesForForm(model);
+            model.addAttribute("person",person);
+            model.addAttribute("movieActors",this.personService.findAllMoviesByPerson(person));
+            return "template";
+        }
+        catch (RuntimeException exc){
+            return "redirect:/actors?erorr="+exc.getMessage();
+        }
+    }
+
+    @PostMapping("/persons/save")
+    public String savePerson(
+            @RequestParam String name,
+            @RequestParam String surname,
+            @RequestParam Character type,
+            @RequestParam Date birthDate,
+            @RequestParam String imageUrl,
+            @RequestParam String description,
+            @RequestParam(required = false) List<Integer> movieIds){
+
+        String returnedUrl = getReturnedUrl(type);
+
+        try {
+
+            Person person = this.personService.save(name, surname, type, birthDate, imageUrl, description, movieIds);
+           return returnedUrl;
+        }
+        catch (RuntimeException exc){
+            return returnedUrl + "?error" + exc.getMessage();
+        }
+
+    }
+    @PostMapping("/persons/save/{personId}")
+    public String editPerson(
+            @PathVariable Integer personId,
+            @RequestParam String name,
+            @RequestParam String surname,
+            @RequestParam Character type,
+            @RequestParam Date birthDate,
+            @RequestParam String imageUrl,
+            @RequestParam String description,
+            @RequestParam(required = false) List<Integer> movieIds){
+
+        String returnedUrl = getReturnedUrl(type);
+        try {
+
+            Person person = this.personService.edit(personId,name, surname, type, birthDate, imageUrl, description, movieIds);
+            return returnedUrl;
+        }
+        catch (RuntimeException exc){
+            return returnedUrl + "?error" + exc.getMessage();
+        }
+
+    }
+    private String getReturnedUrl(Character type){
+        if (type.equals('A'))
+           return   "redirect:/actors";
+        return "redirect:/directors";
+    }
+    private void addModelPropertiesForForm(Model model){
+        model.addAttribute("contentTemplate", "personsAdd");
+        model.addAttribute("moviesActors",this.movieService.listAllByType('A'));
+        model.addAttribute("moviesDirectors",this.movieService.listAllByType('D'));
+
+    }
+
+
+}
Index: src/main/java/com/wediscussmovies/project/web/controller/PersonsController.java
===================================================================
--- src/main/java/com/wediscussmovies/project/web/controller/PersonsController.java	(revision 3ded84dfbf8ff25bf27cc822ac97b84a063fa95a)
+++ 	(revision )
@@ -1,118 +1,0 @@
-package com.wediscussmovies.project.web.controller;
-
-import com.wediscussmovies.project.model.*;
-import com.wediscussmovies.project.model.enumerations.PersonType;
-import com.wediscussmovies.project.service.PersonService;
-import org.springframework.stereotype.Controller;
-import org.springframework.ui.Model;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-
-import java.sql.Date;
-import java.util.List;
-
-@Controller
-public class PersonsController {
-    private final PersonService personSerivce;
-
-    public PersonsController(PersonService personSerivce) {
-        this.personSerivce = personSerivce;
-    }
-
-    @GetMapping("/actors")
-    public String getActorsPage(Model model, @RequestParam(required = false) String nameAndSurname){
-        List<Person> actors = personSerivce.findAllActors();
-        if(nameAndSurname != null && !nameAndSurname.isEmpty()){
-            String [] parts = nameAndSurname.split(" ");
-            String name = parts[0];
-            String surname = "";
-            if(parts.length > 1)
-                surname = parts[1];
-            List<Person> actorsByName = personSerivce.findActorsByNameLike("%"+name+"%");
-            if(!surname.isEmpty()){
-                List<Person> actorsBySurname = personSerivce.findActorsBySurnameLike("%"+surname+"%");
-                for(Person p: actorsBySurname){
-                    boolean add = true;
-                    for(Person a: actorsByName){
-                        if(a.getPersonId() == p.getPersonId()){
-                            add=false;
-                            break;
-                        }
-                    }
-                    if(!add)
-                        continue;
-                    actorsByName.add(p);
-                }
-            }
-            actors = actorsByName;
-        }
-       // actors.sort(Person.personComparatorByNameSurname);
-        model.addAttribute("actors", actors);
-        model.addAttribute("contentTemplate", "actorsList");
-        return "template";
-    }
-
-    @GetMapping("/directors")
-    public String getDirectorsPage(Model model, @RequestParam(required = false) String nameAndSurname){
-        List<Person> directors = personSerivce.findAllDirectors();
-        if(nameAndSurname != null && !nameAndSurname.isEmpty()){
-            String [] parts = nameAndSurname.split(" ");
-            String name = parts[0];
-            String surname = "";
-            if(parts.length > 1)
-                surname = parts[1];
-            List<Person> directorsByName = personSerivce.findDirectorsByNameLike("%"+name+"%");
-            if(!surname.isEmpty()){
-                List<Person> directorsBySurname = personSerivce.findDirectorsBySurnameLike("%"+surname+"%");
-                for(Person p: directorsBySurname){
-                    boolean add = true;
-                    for(Person a: directorsByName){
-                        if(a.getPersonId() == p.getPersonId()){
-                            add=false;
-                            break;
-                        }
-                    }
-                    if(!add)
-                        continue;
-                    directorsByName.add(p);
-                }
-            }
-            directors = directorsByName;
-        }
-     //   directors.sort(Person.personComparatorByNameSurname);
-        model.addAttribute("directors", directors);
-        model.addAttribute("contentTemplate", "directorsList");
-        return "template";
-    }
-
-    @GetMapping("/persons/add")
-    public String getPersonsAddPage(Model model){
-        PersonType [] types = PersonType.values();
-        model.addAttribute("types", types);
-        model.addAttribute("contentTemplate", "personsAdd");
-        return "template";
-    }
-
-    @PostMapping("/persons/add/confirm")
-    public String confirmPersonsAdd(
-            @RequestParam String name,
-            @RequestParam String surname,
-            @RequestParam Character type,
-            @RequestParam Date date_of_birth,
-            @RequestParam String image_url,
-            @RequestParam String description){
-        Person person = new Person(name, surname, type, date_of_birth, image_url, description);
-        if(personSerivce.save(person)){
-            String toWhere = "actors";
-            //if(type == PersonType.D)
-                toWhere = "directors";
-            return "redirect:/"+toWhere;
-        }
-        else{
-            return "redirect:/persons/add";
-        }
-    }
-
-}
Index: src/main/java/com/wediscussmovies/project/web/controller/ReplyController.java
===================================================================
--- src/main/java/com/wediscussmovies/project/web/controller/ReplyController.java	(revision 3ded84dfbf8ff25bf27cc822ac97b84a063fa95a)
+++ src/main/java/com/wediscussmovies/project/web/controller/ReplyController.java	(revision e0ef1b13a29101c3f7a56f68da8dcdc8cce98b76)
@@ -1,16 +1,20 @@
 package com.wediscussmovies.project.web.controller;
 
-import com.wediscussmovies.project.model.*;
+import com.wediscussmovies.project.LoggedUser;
+import com.wediscussmovies.project.model.Reply;
+import com.wediscussmovies.project.model.User;
+import com.wediscussmovies.project.model.primarykeys.ReplyPK;
 import com.wediscussmovies.project.service.ReplyService;
+import org.springframework.security.authentication.AnonymousAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.security.core.userdetails.UserDetails;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.*;
 
-import java.util.Optional;
 
 @Controller
+@RequestMapping("/replies")
 public class ReplyController {
     private final ReplyService replyService;
@@ -20,24 +24,62 @@
     }
 
-    @GetMapping("/edit/{id}")
-    public String getReplyEdit(@PathVariable Long id, Model model){
-        Optional<Reply> reply = replyService.findById(id);
-        if(reply.isEmpty())
-            return "redirect:/movies";
-        model.addAttribute("reply", reply.get());
-        model.addAttribute("templateContext", "replyEdit");
+    @GetMapping("/add/{discussionId}")
+    public String addForm(@PathVariable Integer discussionId, Model model){
+        model.addAttribute("discussionId",discussionId);
+        model.addAttribute("contentTemplate","repliesAdd");
         return "template";
     }
 
-    @PostMapping("/edit/confirm/{id}")
-    public String getReplyEdit(@PathVariable Long id, @RequestParam String text){
-        Optional<Reply> replyOp = replyService.findById(id);
-        if(replyOp.isEmpty())
-            return "redirect:/discussions";
-        Reply reply = replyOp.get();
-        replyService.delete(reply);
-        reply.setText(text);
-        replyService.save(reply);
-        return "redirect:/discussions/"+reply.getDiscussionId();
+    @GetMapping("/edit/{discussionId}/{replyId}")
+    public String editForm(@PathVariable Integer discussionId,@PathVariable Integer replyId, Model model){
+
+        try {
+            Reply reply = replyService.findById(discussionId,replyId);
+            model.addAttribute("reply", reply);
+            model.addAttribute("contentTemplate", "repliesAdd");
+            return "template";
+
+
+        }catch (RuntimeException exc){
+            return "redirect:/discussions?error="+exc.getMessage();
+
+        }
     }
+    @PostMapping("/save")
+    public String saveReply(
+            @RequestParam Integer discussionId,
+            @RequestParam String text){
+
+        try {
+
+            this.replyService.save(discussionId,text, LoggedUser.getLoggedUser());
+            return "redirect:/discussions/"+discussionId;
+
+        }
+        catch (RuntimeException exc){
+            return "redirect:/discussions?error="+exc.getMessage();
+
+        }
+    }
+
+    @PostMapping("/save/{replyId}")
+    public String editReply(
+                            @PathVariable Integer replyId,
+                            @RequestParam Integer discussionId,
+                            @RequestParam String text){
+
+        /*
+            1. Da se realizira so ajax baranje na restController
+         */
+        try {
+            Reply reply = replyService.edit(replyId,discussionId, text);
+
+            return "redirect:/discussions/" + reply.getDiscussion().getDiscussionId();
+        }
+        catch (RuntimeException exc){
+            return "redirect:/discussions?error="+exc.getMessage();
+        }
+
+    }
+
 }
Index: src/main/java/com/wediscussmovies/project/web/controller/UsersController.java
===================================================================
--- src/main/java/com/wediscussmovies/project/web/controller/UsersController.java	(revision 3ded84dfbf8ff25bf27cc822ac97b84a063fa95a)
+++ src/main/java/com/wediscussmovies/project/web/controller/UsersController.java	(revision e0ef1b13a29101c3f7a56f68da8dcdc8cce98b76)
@@ -1,98 +1,68 @@
-//package com.wediscussmovies.project.web.controller;
-//
-//import com.wediscussmovies.project.model.PasswordEncoder;
-//import com.wediscussmovies.project.model.*;
-//import com.wediscussmovies.project.model.exception.InvalidUserCredentialsException;
-//import com.wediscussmovies.project.service.UserService;
-//import org.springframework.stereotype.Controller;
-//import org.springframework.ui.Model;
-//import org.springframework.web.bind.annotation.GetMapping;
-//import org.springframework.web.bind.annotation.PostMapping;
-//import org.springframework.web.bind.annotation.RequestParam;
-//
-//import javax.servlet.http.HttpServletRequest;
-//import java.security.NoSuchAlgorithmException;
-//import java.util.Optional;
-//
-//@Controller
-//public class UsersController{
-//    private final UserService userService;
-//
-//    public UsersController(UserService userService) {
-//        this.userService = userService;
-//    }
-//
-//    @GetMapping("/login")
-//    public String getLoginPage(Model model){
-//        return "login";
-//    }
-//
-//    @PostMapping("/login/confirm")
-//    public String confirmLogin(HttpServletRequest request, Model model,
-//                               @RequestParam String username,
-//                               @RequestParam String password){
-//        Optional<User> user;
-//        try{
-//            password = PasswordEncoder.getEncodedPasswordString(password);
-//        }
-//        catch (NoSuchAlgorithmException ex){
-//            model.addAttribute("hasError", true);
-//            model.addAttribute("error", ex.getMessage());
-//            return "login";
-//        }
-//
-//        try{
-//            user = this.userService.login(username, password);
-//            request.getSession().setAttribute("user", user);
-//            request.getSession().setAttribute("loggedIn",true);
-//            return "redirect:/movies";
-//        }
-//        catch (InvalidUserCredentialsException ex){
-//            model.addAttribute("hasError", true);
-//            model.addAttribute("error", ex.getMessage());
-//            return "login";
-//        }
-//    }
-//
-//    @GetMapping("/register")
-//    public String getRegisterPage(){
-//        return "register";
-//    }
-//
-//    @PostMapping("/login/confirm")
-//    public String confirmRegister(HttpServletRequest request,
-//                                  @RequestParam String username,
-//                                  @RequestParam String email,
-//                                  @RequestParam String password,
-//                                  @RequestParam String confirmPassword,
-//                                  @RequestParam String name,
-//                                  @RequestParam String surname){
-//        Optional<User> user;
-//
-//        try{
-//            password = PasswordEncoder.getEncodedPasswordString(password);
-//            confirmPassword = PasswordEncoder.getEncodedPasswordString(confirmPassword);
-//        }
-//        catch (NoSuchAlgorithmException ex){
-//            request.getSession().setAttribute("error", "Contact the administrators!");
-//            request.getSession().setAttribute("hasError", "true");
-//            return "redirect:/movies";
-//        }
-//
-//        user = this.userService.register(request, email, password, confirmPassword, username, name, surname);
-//        if(user.isEmpty()){
-//            request.setAttribute("hasError", "true");
-//        }else{
-//            request.getSession().setAttribute("hasError", "false");
-//            request.getSession().setAttribute("user", user.get());
-//            request.getSession().setAttribute("loggedIn",true);
-//        }
-//        return "redirect:/movies";
-//    }
-//
-//    @GetMapping
-//    public String logout(HttpServletRequest request){
-//        request.getSession().invalidate();
-//        return "redirect:/login";
-//    }
-//}
+package com.wediscussmovies.project.web.controller;
+
+
+import com.wediscussmovies.project.LoggedUser;
+import com.wediscussmovies.project.model.exception.InvalidArgumentsException;
+import com.wediscussmovies.project.model.exception.PasswordsDoNotMatchException;
+import com.wediscussmovies.project.service.MovieService;
+import com.wediscussmovies.project.service.UserService;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+@Controller
+@RequestMapping
+public class UsersController{
+    private  final UserService userService;
+    private final MovieService movieService;
+
+    public UsersController(UserService userService, MovieService movieService) {
+        this.userService = userService;
+        this.movieService = movieService;
+    }
+    @PostMapping("/register")
+    public String register(@RequestParam String username,
+                           @RequestParam String password,
+                           @RequestParam String repeatedPassword,
+                           @RequestParam String email,
+                           @RequestParam String name,
+                           @RequestParam String surname) {
+        try{
+            this.userService.register(email,username,password,repeatedPassword,name,surname);
+            return "redirect:/login";
+        } catch (InvalidArgumentsException | PasswordsDoNotMatchException exception) {
+            return "redirect:/register?error=" + exception.getMessage();
+        }
+    }
+    @GetMapping("/register")
+    public String getRegisterPage(@RequestParam(required = false) String error, Model model) {
+        addModelError(model,error);
+        model.addAttribute("contentTemplate","register");
+        return "template";
+    }
+    @GetMapping("/login")
+    public String getLoginPage(@RequestParam(required = false) String error,Model model){
+        addModelError(model,error);
+        model.addAttribute("contentTemplate","login");
+        return "template";
+    }
+
+    private void addModelError(Model model,String error){
+        if(error != null && !error.isEmpty()) {
+            model.addAttribute("hasError", true);
+            model.addAttribute("error", error);
+        }
+    }
+    @GetMapping("/favoriteList")
+    public String getFavoriteList(Model model){
+        model.addAttribute("movies",this.movieService.findLikedMoviesByUser(LoggedUser.getLoggedUser()));
+        model.addAttribute("contentTemplate","favoriteList");
+        return "template";
+
+    }
+
+
+}
