Week 9

Types of Databases

Databases: Comparison, Choosing & Polyglot

jsonb: Concepts & Setup

jsonb: querying updating

jsonb: Indexes, Tradeoffs & Exercise

Object Storage

Practice

Assignment

Backend Track

Week 9 Assignment - HYF Shop

Overview

In this assignment you will extend a real Spring Boot REST API for an online shop. The shop sells products across several categories - sneakers, clothing, accessories, and more. Each product has a details column of type jsonb that stores flexible, category-specific attributes such as color, size, and material.

Your job is to connect the API to a real PostgreSQL database, expose the flexible product data through the existing endpoints, implement missing query and update functionality using jsonb operators, and add image upload support backed by Backblaze B2 object storage.

Project Setup

Task 1

  1. Create a new Database in your PostgreSQL server
  2. Initialize your database with database.sql - it will create one table with data
  3. Inspect the products table (SELECT * FROM products)
  4. In IntelliJ - set up your ENV variables (Check application.yaml)
  5. Run the Spring Boot application and verify it’s working
  6. Request GET http://localhost:8080/products - you should get a list of products from the DB.

Task 2

  1. Add to the GET /products request the details field from the DB
    1. Hint: mimic the behavior form the learning platform chapter “jsonb: Concepts & Setup”
  2. Write an SQL query to fetch all products that are red.
  3. Fix GET /products?color=<color> Endpoint by implementing the findByColor method in ProductRepository.
  4. Write an SQL query that sets the size of an item to “M”
    1. Hint: jsonb_set
  5. Fix PUT /products/{id}/size Endpoint by implementing the findByColor method in ProductRepository.

Task 3

Add support of uploading image. There are already two endpoints:

  1. Add the Amazon SDK dependency to the project
  2. Create a new FileService with two operations:
    1. Upload new file to a bucket
    2. Delete an existing file from a bucket
  3. Complete the implementation in ProductService:
    1. ProductService.setProductImage()
    2. ProductService.deleteProductImage()

After succesfully uploading a file to a bucket, save the file URL in the database in the image_url column. Set it to null when deleting an image.

If you use BackBlaze, the public url should look like this:

<https://s3.eu-central-003.backblazeb2.com/file/{bucket-name}/{path-name}>

<aside> ⚠️

If you use BackBlaze, you will not be able to create public buckets without adding a credit card details. This is not required for this assignment. Construct and save the URLs in the database and don’t worry about not accessing them at this point.

</aside>

Submission

Follow the Assignment submission guide to submit


The HackYourFuture curriculum is licensed under CC BY-NC-SA 4.0 *https://hackyourfuture.net/*

CC BY-NC-SA 4.0 Icons

Built with ❤️ by the HackYourFuture community · Thank you, contributors

Found a mistake or have a suggestion? Let us know in the feedback form.