Skip to content

Commit

Permalink
Merge branch '1-create-table-for-medtype' of https://github.com/E-Hay…
Browse files Browse the repository at this point in the history
…van/e-hayvan-backend into 1-create-table-for-medtype
  • Loading branch information
FruTooTi committed Jan 1, 2024
2 parents bc52dad + 10ad072 commit c9cfa3c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/pettypes")
public class PetTypeController {
Expand All @@ -26,6 +28,18 @@ public ResponseEntity<PetTypeDTO> getPetTypeById(@PathVariable Integer id) {
}
}

@GetMapping("/all")
public ResponseEntity<List<PetTypeDTO>> getAllPetTypes() {
List<PetTypeDTO> response = petTypeService.getAllPetTypes();

if (!response.isEmpty()) {
return new ResponseEntity<>(response, HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}


// no other CRUD operation is necessary


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/schedules")
public class ScheduleController {
Expand Down Expand Up @@ -35,6 +37,17 @@ public ResponseEntity<ScheduleDTO> deleteSchedule(@PathVariable Integer id) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}

@GetMapping("/all")
public ResponseEntity<List<ScheduleDTO>> getAllSchedules() {
List<ScheduleDTO> response = scheduleService.getAllSchedules();

if (!response.isEmpty()) {
return new ResponseEntity<>(response, HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
// @PostMapping
// public ResponseEntity<ScheduleDTO> saveSchedule(@RequestBody ScheduleDTO scheduleDTO) {
// ScheduleDTO savedSchedule = scheduleService.saveSchedule(scheduleDTO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
Expand All @@ -22,4 +23,15 @@ public PetTypeDTO getPetTypeById(Integer id) {
PetType petType = petTypeRepository.findById(id).orElse(null);
return petType != null ? petTypeMapper.convertToDto(petType) : null;
}

public List<PetTypeDTO> getAllPetTypes() {
List<PetType> petTypeList = petTypeRepository.findAll();
List<PetTypeDTO> petTypeDtoList = new ArrayList<>();

for (PetType petType : petTypeList) {
petTypeDtoList.add(petTypeMapper.convertToDto(petType));
}

return petTypeDtoList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.production.ehayvanbackendapi.Mappers.ScheduleMapper;
import com.production.ehayvanbackendapi.Repositories.ScheduleRepository;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -39,6 +40,17 @@ public ScheduleDTO deleteSchedule(Integer id) {
return null;
}

public List<ScheduleDTO> getAllSchedules() {
List<Schedule> scheduleList = scheduleRepository.findAll();
List<ScheduleDTO> scheduleDtoList = new ArrayList<>();

for (Schedule schedule : scheduleList) {
scheduleDtoList.add(scheduleMapper.convertToDto(schedule));
}

return scheduleDtoList;
}

// public ScheduleDTO saveSchedule(ScheduleDTO scheduleDTO) {
// Schedule schedule = scheduleMapper.convertToEntity(scheduleDTO);
// Schedule savedSchedule = scheduleRepository.save(schedule);
Expand Down

0 comments on commit c9cfa3c

Please sign in to comment.