Institute of Computer Science
  1. Courses
  2. 2024/25 spring
  3. Enterprise Systems Integration (MTAT.03.229)
ET
Log in

Enterprise Systems Integration 2024/25 spring

  • Home
  • Lectures
  • Practicals
  • Assignements
  • Project and exam
  • Message Board

Session 2.4: Spring Boot – REST - CRUD - I

1. Clone the following repository

$ git clone   https://github.com/M-Gharib/ESI-W2-CRUD1.git

Note: if you want to create a new Spring Boot project from scratch, you can refer to last week's materials for that. However, you need to install the following dependency:

  • Spring Web;
  • Spring Data JPA SQL;
  • PostgresSQL Driver SQL.

2. Open the application.properties within the resources folder

src
└── main
     └── java
     └── resources

3. Add your username, password as well as the name of your database

# Database Settings
spring.datasource.url=jdbc:postgresql://localhost:5432/esi2023 # modify if your db is not "esi2023"
spring.datasource.username=postgres # modify if your username is not postgres 
spring.datasource.password=postgres # modify if your password is not postgres 

# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect

# Hibernate ddl auto (create, create-drop, validate, update)
# Allows for auto creation of tables
spring.jpa.hibernate.ddl-auto = update

4. Check the modification in Product.java compared to the code in Session 2.1: Spring Boot - Rest API - [Pre Lab]. Note old code is available within this project but it is commented out.

Your teacher will describe most of the code to you, and based on that you should complete the following tasks:

Task 1. write the required code for the updateProduct function in ProductService.java to update a product in the database

    public void updateProduct(String id, Product product) {
      .....
    }

Task 2. write the required code for the updateProduct function in ProductController.java to invoke the updateProduct function in ProductService.java

@PutMapping("/products/{id}")
    public void updateProduct(@RequestBody Product product, @PathVariable String id){
     .....
    }

Task 3. Test whether your code works as expected by sending the related request in RestClientFile.rest

Task 4. write the required code for the deleteProduct function in ProductService.java to delete a product from the database

     public void deleteProduct(String id) {
       ....
     }

Task 5. write the required code for the deleteProduct function in ProductController.java to invoke the deleteProduct function in ProductService.java

@DeleteMapping("/products/{id}")
    public void deleteProduct(@PathVariable String id){
      .....
    }

Task 6. Test whether your code works as expected by sending the related request in RestClientFile.rest

  • Institute of Computer Science
  • Faculty of Science and Technology
  • University of Tartu
In case of technical problems or questions write to:

Contact the course organizers with the organizational and course content questions.
The proprietary copyrights of educational materials belong to the University of Tartu. The use of educational materials is permitted for the purposes and under the conditions provided for in the copyright law for the free use of a work. When using educational materials, the user is obligated to give credit to the author of the educational materials.
The use of educational materials for other purposes is allowed only with the prior written consent of the University of Tartu.
Terms of use for the Courses environment