esoe
7 months ago
4 changed files with 161 additions and 18 deletions
@ -0,0 +1,77 @@
@@ -0,0 +1,77 @@
|
||||
package ru.molokoin.resourceserviceapi.controllers; |
||||
|
||||
import java.util.List; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.http.HttpStatus; |
||||
import org.springframework.http.MediaType; |
||||
import org.springframework.http.ResponseEntity; |
||||
import org.springframework.web.bind.annotation.DeleteMapping; |
||||
import org.springframework.web.bind.annotation.GetMapping; |
||||
import org.springframework.web.bind.annotation.PathVariable; |
||||
import org.springframework.web.bind.annotation.PostMapping; |
||||
import org.springframework.web.bind.annotation.RequestBody; |
||||
import org.springframework.web.bind.annotation.RequestMapping; |
||||
import org.springframework.web.bind.annotation.RestController; |
||||
|
||||
import ru.molokoin.resourceserviceapi.entities.Building; |
||||
import ru.molokoin.resourceserviceapi.repositories.BuildingFace; |
||||
|
||||
@RestController |
||||
@RequestMapping(path = "/", consumes = {"*/*"}) |
||||
public class BuildingController { |
||||
@Autowired |
||||
private BuildingFace repo; |
||||
|
||||
/** |
||||
* Получение перечня объектов строительства |
||||
* @return |
||||
*/ |
||||
@GetMapping("/building/list") |
||||
public ResponseEntity<List<Building>> getBuildings(){ |
||||
return new ResponseEntity<>(repo.findAll(), HttpStatus.OK); |
||||
} |
||||
|
||||
/** |
||||
* Получение сведений по объекту строительства |
||||
* @param id |
||||
* @return |
||||
*/ |
||||
@GetMapping("/building/{id}") |
||||
public ResponseEntity<?> getBuildingByID(@PathVariable Integer id){ |
||||
return new ResponseEntity<>(repo.findBuildingById(id), HttpStatus.OK); |
||||
} |
||||
|
||||
/** |
||||
* Создание запис о новом объекте строительства |
||||
* @param building |
||||
* @return |
||||
*/ |
||||
@PostMapping(path = "/building/create", |
||||
consumes = MediaType.APPLICATION_JSON_VALUE, |
||||
produces = MediaType.APPLICATION_JSON_VALUE) |
||||
public ResponseEntity<?> saveBuilding(@RequestBody Building building) { |
||||
repo.save(building); |
||||
return new ResponseEntity<>(building, HttpStatus.CREATED); |
||||
} |
||||
|
||||
@PostMapping(path = "/building/update/{id}", |
||||
consumes = MediaType.APPLICATION_JSON_VALUE, |
||||
produces = MediaType.APPLICATION_JSON_VALUE) |
||||
public ResponseEntity<?> updateBuilding(@PathVariable Integer id, @RequestBody Building building) { |
||||
Building b = repo.findBuildingById(id); |
||||
b.setName_full(building.getName_full()); |
||||
b.setName_short(building.getName_short()); |
||||
b.setCode_full(building.getCode_full()); |
||||
b.setCode_short(building.getCode_short()); |
||||
repo.save(b); |
||||
return new ResponseEntity<>(repo.findBuildingById(id), HttpStatus.CREATED); |
||||
} |
||||
|
||||
@DeleteMapping("/building/delete/{id}") |
||||
public ResponseEntity<String> deleteBuilding(@PathVariable Long id){ |
||||
Building b = repo.findBuildingById(id); |
||||
repo.delete(b); |
||||
return new ResponseEntity<>("Запись id#" + id + " удалена ... ", HttpStatus.OK); |
||||
} |
||||
} |
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
package ru.molokoin.resourceserviceapi.entities; |
||||
|
||||
import jakarta.persistence.Column; |
||||
import jakarta.persistence.Entity; |
||||
import jakarta.persistence.GeneratedValue; |
||||
import jakarta.persistence.GenerationType; |
||||
import jakarta.persistence.Id; |
||||
import lombok.AllArgsConstructor; |
||||
import lombok.Data; |
||||
import lombok.NoArgsConstructor; |
||||
|
||||
/** |
||||
* Сущность объекта строительства |
||||
*/ |
||||
@NoArgsConstructor |
||||
@AllArgsConstructor |
||||
@Entity |
||||
@Data |
||||
public class Building { |
||||
@Id |
||||
@GeneratedValue(strategy=GenerationType.AUTO) |
||||
private long id; |
||||
@Column(length=50) |
||||
private String name_short;//Сокращенное наименование
|
||||
private String name_full;//Полное наименование
|
||||
private String code_short;//Краткий код
|
||||
private String code_full;//Полный код
|
||||
|
||||
// подготовить конструкторы на все варианты внесения информации о преподавателях
|
||||
public Building(String name_short, String name_full, String code_short, String code_full){ |
||||
this.name_short = name_short; |
||||
this.name_full = name_full; |
||||
this.code_short = code_short; |
||||
this.code_full = code_full; |
||||
} |
||||
} |
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
package ru.molokoin.resourceserviceapi.repositories; |
||||
|
||||
import java.util.List; |
||||
|
||||
import org.springframework.data.repository.ListCrudRepository; |
||||
import org.springframework.stereotype.Repository; |
||||
|
||||
import ru.molokoin.resourceserviceapi.entities.Building; |
||||
|
||||
@Repository |
||||
public interface BuildingFace extends ListCrudRepository<Building, Long>{ |
||||
List<Building> findAll(); |
||||
Building findBuildingById(long id); |
||||
} |
Loading…
Reference in new issue