git commit -m "Added endpoints, model, schema, and services for pet attributes"

This commit is contained in:
Koushal Jain 2025-05-08 00:30:53 +05:30
parent 0c88f916db
commit 91b9831915
6 changed files with 143 additions and 0 deletions

View file

@ -0,0 +1,31 @@
package org.springframework.samples.petclinic.controller;
import org.springframework.http.ResponseEntity;
import org.springframework.samples.petclinic.model.PetTypes;
import org.springframework.samples.petclinic.service.PetTypeService;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/pettypes")
public class PetTypeController {
private final PetTypeService petTypeService;
public PetTypeController(PetTypeService petTypeService) {
this.petTypeService = petTypeService;
}
@PostMapping
public ResponseEntity<PetTypes> createPetType(@RequestBody PetTypes petType) {
PetTypes savedPetType = petTypeService.save(petType);
return ResponseEntity.ok(savedPetType);
}
@GetMapping
public ResponseEntity<List<PetTypes>> getAllPetTypes() {
List<PetTypes> petTypes = petTypeService.findAll();
return ResponseEntity.ok(petTypes);
}
}

View file

@ -0,0 +1,61 @@
package org.springframework.samples.petclinic.model;
import jakarta.persistence.*;
@Entity
@Table(name = "pet_types")
public class PetTypes {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false)
private String name;
private String temperament;
private Double length;
private Double weight;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTemperament() {
return temperament;
}
public void setTemperament(String temperament) {
this.temperament = temperament;
}
public Double getLength() {
return length;
}
public void setLength(Double length) {
this.length = length;
}
public Double getWeight() {
return weight;
}
public void setWeight(Double weight) {
this.weight = weight;
}
}

View file

@ -0,0 +1,7 @@
package org.springframework.samples.petclinic.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.samples.petclinic.model.PetTypes;
public interface PetTypeRepository extends JpaRepository<PetTypes, Long> {
}

View file

@ -0,0 +1,10 @@
package org.springframework.samples.petclinic.service;
import org.springframework.samples.petclinic.model.PetTypes;
import java.util.List;
public interface PetTypeService {
PetTypes save(PetTypes petType);
List<PetTypes> findAll();
}

View file

@ -0,0 +1,27 @@
package org.springframework.samples.petclinic.service;
import org.springframework.samples.petclinic.model.PetTypes;
import org.springframework.samples.petclinic.repository.PetTypeRepository;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class PetTypeServiceImpl implements PetTypeService {
private final PetTypeRepository petTypeRepository;
public PetTypeServiceImpl(PetTypeRepository petTypeRepository) {
this.petTypeRepository = petTypeRepository;
}
@Override
public PetTypes save(PetTypes petType) {
return petTypeRepository.save(petType);
}
@Override
public List<PetTypes> findAll() {
return petTypeRepository.findAll();
}
}

View file

@ -0,0 +1,7 @@
CREATE TABLE pet_types (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
temperament VARCHAR(255),
length DOUBLE,
weight DOUBLE,
);