Skip to content

amazi2/Advanced_Programing

Repository files navigation

Advanced_Programing

My Name: Niyonsaba Alice

Registration Number: M03526/2024

Spring Boot CRUD Assignment

This is a Spring Boot application that implements CRUD operations for Student and Course entities with MySQL database integration.

Features

Task 1: Enhanced Student Creation

  • Student entity with email validation
  • Prevents duplicate students with same email
  • Returns "The student already exists" message for duplicates

Task 2: Course Entity CRUD

  • Complete CRUD operations for Course entity
  • Course fields: id, title, credits
  • Full REST API implementation

Prerequisites

  • Java 17 or higher
  • Maven 3.6+
  • MySQL 8.0+

Setup Instructions

  1. Database Setup

    CREATE DATABASE student_course_db;
  2. Configure Database Update src/main/resources/application.properties with your MySQL credentials:

    spring.datasource.username=your_username
    spring.datasource.password=your_password
  3. Run Application

    mvn spring-boot:run

API Endpoints

Student Endpoints

  • POST /api/students - Create new student (with email validation)
  • GET /api/students - Get all students
  • GET /api/students/{id} - Get student by ID
  • PUT /api/students/{id} - Update student
  • DELETE /api/students/{id} - Delete student

Course Endpoints

  • POST /api/courses - Create new course
  • GET /api/courses - Get all courses
  • GET /api/courses/{id} - Get course by ID
  • PUT /api/courses/{id} - Update course
  • DELETE /api/courses/{id} - Delete course

Sample JSON Payloads

Student

{
    "name": "John Doe",
    "email": "[email protected]",
    "age": 20
}

Course

{
    "title": "Introduction to Computer Science",
    "credits": 3
}

Testing with Postman

  1. Start the application
  2. Import the endpoints into Postman
  3. Test all CRUD operations
  4. Verify email validation for students
  5. Check error handling for invalid requests

Project Structure

src/main/java/com/assignment/crud/
├── CrudApplication.java          # Main application class
├── entity/
│   ├── Student.java             # Student entity
│   └── Course.java              # Course entity
├── repository/
│   ├── StudentRepository.java   # Student data access
│   └── CourseRepository.java    # Course data access
├── service/
│   ├── StudentService.java      # Student business logic
│   └── CourseService.java       # Course business logic
└── controller/
    ├── StudentController.java   # Student REST endpoints
    └── CourseController.java    # Course REST endpoints

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published