Skip to content

Commit

Permalink
Create operation is added for customer and appointment
Browse files Browse the repository at this point in the history
  • Loading branch information
ituitis20-karadagd20 authored and CihatAltiparmak committed Dec 19, 2023
1 parent 769176e commit ccb07dd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -36,6 +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);
}

// Other controller methods for creating, updating, and deleting appointments
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import com.production.ehayvanbackendapi.Services.CustomerService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -36,6 +33,12 @@ 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);
}

// Other controller methods for creating, updating, and deleting customers
}

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public AppointmentDTO getAppointmentById(Integer id) {
Appointment appointment = appointmentRepository.findById(id).orElse(null);
return appointment != null ? appointmentMapper.convertToDto(appointment) : null;
}

public AppointmentDTO createAppointment(AppointmentDTO appointmentDTO) {
Appointment appointment = appointmentMapper.convertToEntity(appointmentDTO);
Appointment savedAppointment = appointmentRepository.save(appointment);
return appointmentMapper.convertToDto(savedAppointment);
}
// Other service methods for creating, updating, and deleting appointments
}

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public CustomerDTO getCustomerById(Integer id) {
return customer != null ? customerMapper.convertToDto(customer) : null;
}

public CustomerDTO createCustomer(CustomerDTO customerDTO) {
Customer customer = customerMapper.convertToEntity(customerDTO);
Customer savedCustomer = customerRepository.save(customer);
return customerMapper.convertToDto(savedCustomer);
}

// Other service methods for creating, updating, and deleting customers
}

0 comments on commit ccb07dd

Please sign in to comment.