Skip to content

Latest commit

 

History

History
81 lines (58 loc) · 3.27 KB

README.md

File metadata and controls

81 lines (58 loc) · 3.27 KB

Spring Boot Quick Start 🔥

This is a hands-on project from the Spring Boot Tutorial by Java Brains!

Development Process

With the development process of the Course Management System detailed below, I attempt to condense and provide some insight into what I have learnt throughout this course.

Initial Setup

  • Create a Maven project.
  • Add spring-boot-starter-web dependency.
  • Add CourseApiApp class and run the application.

Getting a List of Topics

  • Add Topic class with id, name, and description.
  • Add Topic RestController.
  • Add getAllTopics and its /topics RequestMapping.
  • Return a hardcoded list of Topic objects which Spring MVC converts to JSON.

Using a Business Service

  • Add TopicService class.
  • Inject or Autowire TopicService dependency into TopicController.
  • Refactor and move hardcoded list to TopicService.
  • Add getAllTopics service function.

Getting a Single Topic

  • Add getTopic service function.
  • Add /topics/{id} RequestMapping which calls service function with the PathVariable and returns the output.

Adding a Topic

  • Add POST RequestMethod mapping for /topics.
  • Pass theTopic instance from the RequestBody to the TopicService.
  • Add addTopic service function.

Updating and Deleting

  • Add PUT RequestMethod mapping for /topics/{id}.
  • Pass the RequestBody Topic instance and id PathVariable to TopicService.
  • Add updateTopic service function.
  • Add DELETE RequestMethod mapping for /topics/{id}.
  • Pass the id PathVariable to TopicService.
  • Add deleteTopic service function.

This is a good time to create an application.properties file and make any necessary configurations, such as changing the application port. It is good practice to frequently verify the state of the application and test endpoint changes using Postman.

Connecting to a Database

  • Add spring-boot-starter-data-jpa and derby embedded database dependencies to pom.xml.
  • Add Entity annotation to Topic class.
  • Add Id primary key annotation.
  • Add TopicRepository interface extending CrudRepository.
  • Autowire TopicRepository to TopicService.
  • Refactor TopicService to use built-in TopicRepository CRUD operation methods.

Adding Course API

  • Set up a Course package in the same way as the Topic package.
  • Establish a ManyToOne relationship from Course to Topic.
  • Add findByTopicId function declaration to CourseRepository interface.
  • Refactor CourseService to use functions provided by CourseRepository.
  • Refactor CourseController.
Course API
--------------
GET       /topics/{topicId}/courses          Get all courses
GET       /topics/{topicId}/courses/{id}     Get one course
POST      /topics/{topicId}/courses          Add new course
PUT       /topics/{topicId}/courses/{id}     Update a course
DELETE    /topics/{topicId}/courses/{id}     Delete a course

Add the spring-boot-starter-actuator and package the project as a jar or a traditional war. All good to go!

Thank you very much!

Open to any suggestions on how to make this better! Much appreciated!