Skip to content

Commit

Permalink
controller, dto, mapper is added for pet type and services are updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
ituitis20-karadagd20 committed Dec 20, 2023
1 parent 92ea5e3 commit 345c657
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public ResponseEntity<AppointmentDTO> getAppointmentById(@PathVariable Integer i
}
}

@PostMapping
public ResponseEntity<AppointmentDTO> createAppointment(@RequestBody AppointmentDTO appointmentDTO) {
AppointmentDTO createdAppointment = appointmentService.createAppointment(appointmentDTO);
return new ResponseEntity<>(createdAppointment, HttpStatus.CREATED);
}
// @PostMapping
// public ResponseEntity<AppointmentDTO> createAppointment(@RequestBody AppointmentDTO appointmentDTO) {
// AppointmentDTO createdAppointment = appointmentService.createAppointment(appointmentDTO);
// return new ResponseEntity<>(createdAppointment, HttpStatus.CREATED);
// }

// Other controller methods for creating, updating, and deleting appointments
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public ResponseEntity<CustomerDTO> getCustomerById(@PathVariable Integer id) {
}
}

@PostMapping
public ResponseEntity<CustomerDTO> createCustomer(@RequestBody CustomerDTO customerDTO) {
CustomerDTO createdCustomer = customerService.createCustomer(customerDTO);
return new ResponseEntity<>(createdCustomer, HttpStatus.CREATED);
}
// @PostMapping
// public ResponseEntity<CustomerDTO> createCustomer(@RequestBody CustomerDTO customerDTO) {
// CustomerDTO createdCustomer = customerService.createCustomer(customerDTO);
// return new ResponseEntity<>(createdCustomer, HttpStatus.CREATED);
// }

// Other controller methods for creating, updating, and deleting customers
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public ResponseEntity<MedicationDTO> getMedicationById(@PathVariable Integer id)
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
@PostMapping
public ResponseEntity<MedicationDTO> saveMedication(@RequestBody MedicationDTO medicationDTO) {
MedicationDTO savedMedication = medicationService.saveMedication(medicationDTO);
return new ResponseEntity<>(savedMedication, HttpStatus.CREATED);
}
// @PostMapping
// public ResponseEntity<MedicationDTO> saveMedication(@RequestBody MedicationDTO medicationDTO) {
// MedicationDTO savedMedication = medicationService.saveMedication(medicationDTO);
// return new ResponseEntity<>(savedMedication, HttpStatus.CREATED);
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.production.ehayvanbackendapi.Controllers;

import com.production.ehayvanbackendapi.DTO.PetTypeDTO;
import com.production.ehayvanbackendapi.Services.PetTypeService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/pettypes")
public class PetTypeController {
private final PetTypeService petTypeService;

public PetTypeController(PetTypeService petTypeService) {
this.petTypeService = petTypeService;
}

@GetMapping("/{id}")
public ResponseEntity<PetTypeDTO> getPetTypeById(@PathVariable Integer id) {
PetTypeDTO petTypeDTO = petTypeService.getPetTypeById(id);

if (petTypeDTO != null) {
return new ResponseEntity<>(petTypeDTO, HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}

// @PostMapping
// public ResponseEntity<PetTypeDTO> savePetType(@RequestBody PetTypeDTO petTypeDTO) {
// PetTypeDTO savedPetType = petTypeService.savePetType(petTypeDTO);
// return new ResponseEntity<>(savedPetType, HttpStatus.CREATED);
// }


}

36 changes: 36 additions & 0 deletions src/main/java/com/production/ehayvanbackendapi/DTO/PetTypeDTO.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,40 @@
package com.production.ehayvanbackendapi.DTO;

import java.util.List;

public class PetTypeDTO {
private Integer petTypeID;
private String type;
private List<PetDTO> pets;

public PetTypeDTO(Integer petTypeID, String type, List<PetDTO> pets) {
this.petTypeID = petTypeID;
this.type = type;
this.pets = pets;
}

public Integer getPetTypeID() {
return petTypeID;
}

public void setPetTypeID(Integer petTypeID) {
this.petTypeID = petTypeID;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public List<PetDTO> getPets() {
return pets;
}

public void setPets(List<PetDTO> pets) {
this.pets = pets;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.production.ehayvanbackendapi.Mappers;

import com.production.ehayvanbackendapi.DTO.PetTypeDTO;
import com.production.ehayvanbackendapi.Entities.PetType;
import org.modelmapper.ModelMapper;
import org.springframework.stereotype.Component;

@Component
public class PetTypeMapper {
private final ModelMapper modelMapper;

public PetTypeMapper(ModelMapper modelMapper) {
this.modelMapper = modelMapper;
}

public PetTypeDTO convertToDto(PetType petType) {
return modelMapper.map(petType, PetTypeDTO.class);
}

public PetType convertToEntity(PetTypeDTO petTypeDTO) {
return modelMapper.map(petTypeDTO, PetType.class);
}
}

Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
package com.production.ehayvanbackendapi.Services;

import com.production.ehayvanbackendapi.DTO.PetTypeDTO;
import com.production.ehayvanbackendapi.Entities.PetType;
import com.production.ehayvanbackendapi.Mappers.PetTypeMapper;
import com.production.ehayvanbackendapi.Repositories.PetTypeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PetTypeService {
private final PetTypeRepository petTypeRepository;
private final PetTypeMapper petTypeMapper;

public PetTypeService(PetTypeRepository petTypeRepository) {
@Autowired
public PetTypeService(PetTypeRepository petTypeRepository, PetTypeMapper petTypeMapper) {
this.petTypeRepository = petTypeRepository;
this.petTypeMapper = petTypeMapper;
}
public List<PetType> getAllPetTypes(){
return petTypeRepository.findAll();
public PetTypeDTO getPetTypeById(Integer id) {
PetType petType = petTypeRepository.findById(id).orElse(null);
return petType != null ? petTypeMapper.convertToDto(petType) : null;
}
}

0 comments on commit 345c657

Please sign in to comment.