package com.hotels.controllers;

import com.hotels.DTO.CreatingHotelDto;
import com.hotels.DTO.HotelDto;
import com.hotels.models.Hotel;
import com.hotels.services.HotelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

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

@RestController
@RequestMapping("/v1/hotels")
public class HotelController {
    @Autowired
    private HotelService service;

    @RequestMapping(method = RequestMethod.GET)
    public ResponseEntity<List<HotelDto>> get() {
        List<Hotel> hotels = this.service.getAll();
        if (hotels.isEmpty()) {
            return new ResponseEntity<>(HttpStatus.NO_CONTENT);
        }

        List<HotelDto> result = new ArrayList<>();

        for (Hotel hotel : hotels) {
            HotelDto dto = toDto(hotel);
            result.add(dto);
        }
        return new ResponseEntity<>(result, HttpStatus.OK);
    }


    @RequestMapping(method = RequestMethod.POST)
    public ResponseEntity<HotelDto> addHotel(@RequestBody CreatingHotelDto hotelDto) {
        Hotel hotel = toCreatingModel(hotelDto);
        Hotel savedHotel = this.service.save(hotel);
        return new ResponseEntity<>(toDto(savedHotel), HttpStatus.CREATED);

    }

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public ResponseEntity<HotelDto> getStudentById(@PathVariable("id") Long id) {
        Hotel hotel = this.service.getById(id);
        if (hotel == null) {
            return new ResponseEntity<>(HttpStatus.NO_CONTENT);
        }

        return new ResponseEntity<>(toDto(hotel), HttpStatus.OK);
    }

    private HotelDto toDto(Hotel hotel) {
        HotelDto dto = new HotelDto();
        dto.name = hotel.getName();
        dto.address = hotel.getAddress();
        dto.id = hotel.getId();
        dto.email = hotel.getEmail();
        dto.phone = hotel.getPhone();
        dto.category = hotel.getCategory();
        dto.description = hotel.getDescription();
        return dto;
    }

    private Hotel toCreatingModel(CreatingHotelDto dto) {
        Hotel hotel = new Hotel();
        hotel.setName(dto.name);
        hotel.setAddress(dto.address);
        hotel.setEmail(dto.email);
        hotel.setPhone(dto.phone);
        hotel.setCategory(dto.category);
        hotel.setDescription(dto.description);
        return hotel;
    }



}

@@ -11,16 +11,24 @@
 m.hotels
+amdrooms
 .control
@@ -49,24 +49,32 @@
 t com.hotels
+amdrooms
 .DTO.Creatin
@@ -102,16 +102,24 @@
 m.hotels
+amdrooms
 .DTO.Hot
@@ -143,16 +143,24 @@
 m.hotels
+amdrooms
 .models.
@@ -184,16 +184,24 @@
 m.hotels
+amdrooms
 .service
@@ -426,18 +426,16 @@
 ion.*;%0D%0A
-%0D%0A
 import j
@@ -520,11 +520,8 @@
 g(%22/
-v1/
 hote
@@ -607,24 +607,89 @@
 service;%0D%0A%0D%0A
+    @com.hotelsamdrooms.filters.JsonFilter(keys = %7B%22category%22%7D)%0D%0A
     @Request
@@ -1626,15 +1626,13 @@
  get
-Student
+Hotel
 ById
@@ -2097,47 +2097,8 @@
 );%0D%0A
-        dto.email = hotel.getEmail();%0D%0A
     
@@ -2224,24 +2224,105 @@
 ription();%0D%0A
+        dto.facilities=hotel.getFacility();%0D%0A        dto.rooms=hotel.getRoom();%0D%0A
         retu
@@ -2512,44 +2512,8 @@
 );%0D%0A
-        hotel.setEmail(dto.email);%0D%0A
     
@@ -2630,24 +2630,103 @@
 cription);%0D%0A
+        hotel.setFacility(dto.facilities);%0D%0A        hotel.setRoom(dto.rooms);%0D%0A
         retu

Update HotelController.java