Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/code-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: AI Code Review

on:
pull_request:
types: [opened, edited, synchronize]

jobs:
code_review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run Copilot Code Review
uses: github/copilot-review-action@v1
1 change: 1 addition & 0 deletions src/main/java/org/example/webapplab1/movies/Movie.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class Movie {
private Long id;

private String title;
@Column(columnDefinition = "TEXT")
private String description;

@Column (name = "release_date")
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/org/example/webapplab1/movies/MovieController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.List;

Expand All @@ -23,4 +26,22 @@ public String getMovies(Model model) {
model.addAttribute("movies", movies);
return "movies";
}

@GetMapping("/movies/new")
public String showCreateForm(Model model) {
model.addAttribute("movie", new Movie());
return "create-movie";
}

@PostMapping("/movies")
public String createMovie(@ModelAttribute("movie") Movie movie) {
movieService.save(movie);
return "redirect:/movies";
}

@GetMapping("/movies/delete/{id}")
public String deleteMovie(@PathVariable("id") Long id) {
movieService.deleteById(id);
return "redirect:/movies";
}
}
1 change: 1 addition & 0 deletions src/main/java/org/example/webapplab1/movies/MovieRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
import org.springframework.data.repository.ListCrudRepository;

public interface MovieRepo extends ListCrudRepository<Movie,Long> {
Long id(Long id);
}
8 changes: 8 additions & 0 deletions src/main/java/org/example/webapplab1/movies/MovieService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ public MovieService(MovieRepo movieRepo) {
public List<Movie> getAllMovies() {
return movieRepo.findAll();
}

public Movie save(Movie movie) {
return movieRepo.save(movie);
}

public void deleteById(Long id) {
movieRepo.deleteById(id);
}
}
3 changes: 1 addition & 2 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
spring.application.name=WebApp-lab1
server.port=8080
spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/movie
spring.datasource.username=myuser
spring.datasource.password=secret
spring.datasource.password=pw
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true

30 changes: 30 additions & 0 deletions src/main/resources/templates/create-movie.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
<meta charset="UTF-8">
<title>Create Movie</title>
</head>
<body>

<h1>Add Movie</h1>

<form th:action="@{/movies}" th:object="${movie}" method="post">
<label for="title">Title</label>
<input type="text" id="title" th:field="*{title}">

<label for="description">Description</label>
<input type="text" id="description" th:field="*{description}">

<label for="releaseDate">Release Date</label>
<input type="text" id="releaseDate" th:field="*{releaseDate}">

<label for="director">Director</label>
<input type="text" id="director" th:field="*{director}">

<label for="durationMinutes">Duration</label>
<input type="number" id="durationMinutes" th:field="*{durationMinutes}">

<button type="submit">Save</button>
</form>
</body>
</html>
3 changes: 2 additions & 1 deletion src/main/resources/templates/movies.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</head>
<body>
<h1>Movie List</h1>
<a th:href="@{/movies/new}">Add new Movie</a>
<table border="1">
<tr>
<th>Movie Title</th>
Expand All @@ -17,7 +18,7 @@ <h1>Movie List</h1>
<td th:text="${movie.title}">Title</td>
<td th:text="${movie.director}">Director</td>
<td th:text="${movie.releaseDate}">Date</td>
<td th:text="${movie.durationMinutes}">Duration</td>
<td th:text="${movie.durationMinutes}">Duration (minutes)</td>
</tr>
</table>
</body>
Expand Down
Loading