Ignore:
Timestamp:
01/18/22 17:18:17 (3 years ago)
Author:
Test <matonikolov77@…>
Branches:
main
Children:
e0ef1b1
Parents:
7fafead
Message:

Model-database resolved bugs for mapping

Location:
src/main/java/com/wediscussmovies/project/web/controller
Files:
1 added
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/com/wediscussmovies/project/web/controller/DiscussionsController.java

    r7fafead r3ded84d  
    22
    33import com.wediscussmovies.project.model.*;
    4 import com.wediscussmovies.project.model.enumerations.DiscussionType;
     4
    55import com.wediscussmovies.project.service.DiscussionService;
    66import com.wediscussmovies.project.service.MovieService;
     
    1414import java.sql.Date;
    1515import java.time.LocalDate;
    16 import java.util.ArrayList;
    1716import java.util.List;
    1817import java.util.Optional;
     
    8079        if(discussion.isEmpty())
    8180            return "redirect:/discussions";
    82         Reply reply = new Reply(discussion.get(), user, date, text);
    83         replyService.save(reply);
     81        //Reply reply = new Reply(discussion.get(), user, date, text);
     82       // replyService.save(reply);
    8483        return "redirect:/discussions/"+id;
    8584    }
     
    103102            return "redirect:/login";
    104103        }
    105         Long movie_id = (Long) request.getSession().getAttribute("movieId");
     104        Integer movie_id = (Integer) request.getSession().getAttribute("movieId");
    106105        request.getSession().setAttribute("movieId", null);
    107106        Optional<Movie> movieOp = movieService.findById(movie_id);
    108107        if(movieOp.isEmpty())
    109108            return "redirect:/movies";
    110         Discussion discussion = new Discussion(DiscussionType.M,text, title, Date.valueOf(LocalDate.now()),user,movieOp.get(),null,new ArrayList<>());
    111         discussionService.save(discussion);
     109      //  Discussion discussion = new Discussion('M',text, title, Date.valueOf(LocalDate.now()),user,movieOp.get(),null);
     110       // discussionService.save(discussion);
    112111        return "redirect:/discussions";
    113112    }
     
    137136        if(personOp.isEmpty())
    138137            return "redirect:/discussions";
    139         Discussion discussion = new Discussion(DiscussionType.P,title, text,Date.valueOf(LocalDate.now()),user,null,personOp.get(),new ArrayList<>());
    140         discussionService.save(discussion);
     138
     139      //  Discussion discussion = new Discussion('P',title, text,Date.valueOf(LocalDate.now()),user,null,personOp.get());
     140      //  discussionService.save(discussion);
    141141        return "redirect:/discussions";
    142142    }
  • src/main/java/com/wediscussmovies/project/web/controller/MovieController.java

    r7fafead r3ded84d  
    22
    33import com.wediscussmovies.project.exception.MovieIdNotFoundException;
    4 import com.wediscussmovies.project.model.Genre;
    5 import com.wediscussmovies.project.model.Movie;
    6 import com.wediscussmovies.project.model.Person;
     4import com.wediscussmovies.project.model.*;
     5
    76import com.wediscussmovies.project.service.GenreService;
    87import com.wediscussmovies.project.service.MovieService;
     
    3332    public String getMovies(@RequestParam(required = false) String titleQuery, Model model){
    3433        List<Movie> movies;
    35         if(titleQuery == null || titleQuery.isEmpty()) {
     34        if(titleQuery == null ) {
    3635            movies = movieService.listAll();
    3736        }
     
    4039        }
    4140
    42         movies.sort(Movie.comparatorTitle);
    4341
    4442        model.addAttribute("movies", movies);
    4543        model.addAttribute("contentTemplate", "moviesList");
    46         return "template";
     44        return "list";
    4745    }
    4846
     
    5957
    6058    @PostMapping("/{id}/delete")
    61     public String addMovie(@PathVariable Long id){
     59    public String addMovie(@PathVariable Integer id){
    6260        Optional<Movie> movie = movieService.findById(id);
    6361        if(movie.isPresent()){
    64             movieService.deleteById(movie.get().getId());
     62            movieService.deleteById(movie.get().getMovieId());
    6563        }
    6664        return "redirect:/movies";
     
    122120
    123121        Movie movie = new Movie(title, description, image_url, airing_date,
    124                     rating, director, actorsList, genreList);
     122                    rating, director.getPersonId());
    125123
    126124        movieService.save(movie);
     
    131129    @PostMapping("/edit/confirm")
    132130    public String editMoviePost(
    133                                 @RequestParam Long movie_id,
     131                                @RequestParam Integer movie_id,
    134132                                @RequestParam String title,
    135133                               @RequestParam String description,
     
    198196        movieService.deleteById(movie_id);
    199197
    200         movie.setActors(actorsList);
    201         movie.setDirector(director);
    202         movie.setGenres(genreList);
    203         movie.setTitle(title);
    204         movie.setDescription(description);
    205         movie.setAringDate(airing_date);
    206         movie.setImageUrl(image_url);
    207         movie.setImbdRating(rating);
     198//      //  movie.setActors(actorsList);
     199//        movie.setDirector(director);
     200//        movie.setGenres(genreList);
     201//        movie.setTitle(title);
     202//        movie.setDescription(description);
     203//        movie.setAringDate(airing_date);
     204//        movie.setImageUrl(image_url);
     205//        movie.setImbdRating(rating);
    208206
    209207        movieService.save(movie);
     
    213211
    214212    @GetMapping("/{id}/edit")
    215     public String editMovie(@PathVariable Long id, Model model){
     213    public String editMovie(@PathVariable Integer id, Model model){
    216214        Movie movie = movieService.findById(id).orElseThrow(() -> new MovieIdNotFoundException(id));
    217215        model.addAttribute("directors", personService.findAllDirectors());
  • src/main/java/com/wediscussmovies/project/web/controller/PersonsController.java

    r7fafead r3ded84d  
    11package com.wediscussmovies.project.web.controller;
    22
    3 import com.wediscussmovies.project.model.Person;
     3import com.wediscussmovies.project.model.*;
    44import com.wediscussmovies.project.model.enumerations.PersonType;
    55import com.wediscussmovies.project.service.PersonService;
     
    1515
    1616@Controller
    17 @RequestMapping(".")
    1817public class PersonsController {
    1918    private final PersonService personSerivce;
     
    101100            @RequestParam String name,
    102101            @RequestParam String surname,
    103             @RequestParam PersonType type,
     102            @RequestParam Character type,
    104103            @RequestParam Date date_of_birth,
    105104            @RequestParam String image_url,
     
    108107        if(personSerivce.save(person)){
    109108            String toWhere = "actors";
    110             if(type == PersonType.D)
     109            //if(type == PersonType.D)
    111110                toWhere = "directors";
    112111            return "redirect:/"+toWhere;
  • src/main/java/com/wediscussmovies/project/web/controller/ReplyController.java

    r7fafead r3ded84d  
    11package com.wediscussmovies.project.web.controller;
    22
    3 import com.wediscussmovies.project.model.Reply;
     3import com.wediscussmovies.project.model.*;
    44import com.wediscussmovies.project.service.ReplyService;
     5import org.springframework.stereotype.Controller;
    56import org.springframework.ui.Model;
    67import org.springframework.web.bind.annotation.GetMapping;
     
    1112import java.util.Optional;
    1213
     14@Controller
    1315public class ReplyController {
    1416    private final ReplyService replyService;
     
    3739        reply.setText(text);
    3840        replyService.save(reply);
    39         return "redirect:/discussions/"+reply.getDiscussion().getId();
     41        return "redirect:/discussions/"+reply.getDiscussionId();
    4042    }
    4143}
Note: See TracChangeset for help on using the changeset viewer.