Skip to content
Open
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
15 changes: 13 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.3.1'
id 'io.spring.dependency-management' version '1.1.5'
id 'org.springframework.boot' version '3.4.2'
id 'io.spring.dependency-management' version '1.1.7'
}

group = 'com.booleanuk'
Expand All @@ -13,17 +13,28 @@ java {
}
}

configurations {
compileOnly {
extendsFrom annotationProcessor
}
}

repositories {
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

// https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-starter-webmvc-ui
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.3'
}

tasks.named('test') {
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/booleanuk/api/cinema/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.booleanuk.api.cinema;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Main {
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
}
45 changes: 45 additions & 0 deletions src/main/java/com/booleanuk/api/cinema/customers/Customer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.booleanuk.api.cinema.customers;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.time.LocalDateTime;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "customers")
public class Customer {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;

@Column
private String name;

@Column
private String email;

@Column
private String phone;

@Column
private LocalDateTime createdAt;

@Column
private LocalDateTime updatedAt;

public Customer(String name, String email, String phone) {
this.name = name;
this.email = email;
this.phone = phone;
this.createdAt = LocalDateTime.now();
this.updatedAt = LocalDateTime.now();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.booleanuk.api.cinema.customers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;

import java.util.List;

@RestController
@RequestMapping("customers")
public class CustomerController {
@Autowired
private CustomerRepository customerRepository;

@ResponseStatus(HttpStatus.OK)
@GetMapping("{id}")
public Customer getOneCustomer(@PathVariable int id) {
return this.customerRepository.findById(id).orElseThrow(
() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Customer not found.")
);
}

@ResponseStatus(HttpStatus.OK)
@GetMapping
public List<Customer> getAllCustomers() {
return this.customerRepository.findAll();
}

@ResponseStatus(HttpStatus.CREATED)
@PostMapping
public Customer createCustomer(@RequestBody Customer customer) {
Customer newCustomer = new Customer(customer.getName(), customer.getEmail(), customer.getPhone());
return this.customerRepository.save(newCustomer);
}

@ResponseStatus(HttpStatus.CREATED)
@PutMapping("{id}")
public Customer updateCustomer(@RequestBody Customer customer, @PathVariable int id) {
Customer customerToUpdate = this.customerRepository.findById(id).orElseThrow(
() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Customer not found.")
);
customerToUpdate.setName(customer.getName());
customerToUpdate.setEmail(customer.getEmail());
customerToUpdate.setPhone(customer.getPhone());
return this.customerRepository.save(customerToUpdate);
}

@ResponseStatus(HttpStatus.OK)
@DeleteMapping("{id}")
public Customer deleteCustomer(@PathVariable int id) {
Customer customerToDelete = this.customerRepository.findById(id).orElseThrow(
() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Customer not found.")
);
this.customerRepository.delete(customerToDelete);
return customerToDelete;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.booleanuk.api.cinema.customers;

import org.springframework.data.jpa.repository.JpaRepository;

public interface CustomerRepository extends JpaRepository<Customer, Integer> {
}
51 changes: 51 additions & 0 deletions src/main/java/com/booleanuk/api/cinema/movies/Movie.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.booleanuk.api.cinema.movies;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.time.LocalDateTime;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "movies")
public class Movie {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;

@Column
private String title;

@Column
private String rating;

@Column
private String description;

@Column
private int runtimeMins;

@Column(nullable = false)
private LocalDateTime createdAt;

@Column(nullable = false)
private LocalDateTime updatedAt;

public Movie(String title, String rating, String description, int runtimeMins) {
this.title = title;
this.rating = rating;
this.description = description;
this.runtimeMins = runtimeMins;
}

public Movie(int id) {
this.id = id;
}
}
59 changes: 59 additions & 0 deletions src/main/java/com/booleanuk/api/cinema/movies/MovieController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.booleanuk.api.cinema.movies;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;

import java.util.List;

@RestController
@RequestMapping("movies")
public class MovieController {
@Autowired
private MovieRepository movieRepository;

@ResponseStatus(HttpStatus.OK)
@GetMapping("{id}")
public Movie getOneMovie(@PathVariable int id) {
return this.movieRepository.findById(id).orElseThrow(
() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Movie not found.")
);
}

@ResponseStatus(HttpStatus.OK)
@GetMapping
public List<Movie> getAllMovies() {
return this.movieRepository.findAll();
}

@ResponseStatus(HttpStatus.CREATED)
@PostMapping
public Movie createMovie(@RequestBody Movie movie) {
Movie newMovie = new Movie(movie.getTitle(), movie.getRating(), movie.getDescription(), movie.getRuntimeMins());
return this.movieRepository.save(newMovie);
}

@ResponseStatus(HttpStatus.CREATED)
@PutMapping("{id}")
public Movie updateMovie(@RequestBody Movie movie, @PathVariable int id) {
Movie movieToUpdate = this.movieRepository.findById(id).orElseThrow(
() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Movie not found.")
);
movieToUpdate.setTitle(movie.getTitle());
movieToUpdate.setRating(movie.getRating());
movieToUpdate.setDescription(movie.getDescription());
movieToUpdate.setRuntimeMins(movie.getRuntimeMins());
return this.movieRepository.save(movieToUpdate);
}

@ResponseStatus(HttpStatus.OK)
@DeleteMapping("{id}")
public Movie deleteMovie(@PathVariable int id) {
Movie movieToDelete = this.movieRepository.findById(id).orElseThrow(
() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Movie not found.")
);
this.movieRepository.delete(movieToDelete);
return movieToDelete;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.booleanuk.api.cinema.movies;

import org.springframework.data.jpa.repository.JpaRepository;

public interface MovieRepository extends JpaRepository<Movie, Integer> {
}
52 changes: 52 additions & 0 deletions src/main/java/com/booleanuk/api/cinema/screenings/Screening.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.booleanuk.api.cinema.screenings;

import com.booleanuk.api.cinema.movies.Movie;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.time.LocalDateTime;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "screenings")
public class Screening {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;

@Column
private int screenNumber;

@Column
private LocalDateTime startsAt;

@Column
private int capacity;

@Column
private LocalDateTime createdAt;

@Column
private LocalDateTime updatedAt;

@ManyToOne
@JoinColumn(name = "movie_id")
@JsonIgnoreProperties("screenings")
private Movie movie;

public Screening(int screenNumber, LocalDateTime startsAt, int capacity) {
this.screenNumber = screenNumber;
this.startsAt = startsAt;
this.capacity = capacity;
this.createdAt = LocalDateTime.now();
this.updatedAt = LocalDateTime.now();
}
}
Loading