esoe
7 months ago
7 changed files with 123 additions and 5 deletions
@ -0,0 +1,65 @@ |
|||||||
|
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.PutMapping; |
||||||
|
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.ProgramCretarea; |
||||||
|
import ru.molokoin.resourceserviceapi.repositories.ProgramCretareaRepositoryFace; |
||||||
|
|
||||||
|
@RestController |
||||||
|
@RequestMapping(path = "/", consumes = {"*/*"}) |
||||||
|
public class ProgramCretareaController { |
||||||
|
@Autowired |
||||||
|
private ProgramCretareaRepositoryFace repo; |
||||||
|
|
||||||
|
@GetMapping("/cretarea/list") |
||||||
|
public ResponseEntity<List<ProgramCretarea>> getTeachers(){ |
||||||
|
return new ResponseEntity<>(repo.findAll(), HttpStatus.OK); |
||||||
|
} |
||||||
|
|
||||||
|
@GetMapping("/cretarea/{id}") |
||||||
|
public ResponseEntity<?> getTeacherByID(@PathVariable Integer id){ |
||||||
|
return new ResponseEntity<>(repo.findCretareaById(id), HttpStatus.OK); |
||||||
|
} |
||||||
|
|
||||||
|
@PostMapping(path = "/cretarea/create", |
||||||
|
consumes = MediaType.APPLICATION_JSON_VALUE, |
||||||
|
produces = MediaType.APPLICATION_JSON_VALUE) |
||||||
|
public ResponseEntity<?> saveTeacher(@RequestBody ProgramCretarea cretarea) { |
||||||
|
repo.save(cretarea); |
||||||
|
return new ResponseEntity<>(cretarea, HttpStatus.CREATED); |
||||||
|
} |
||||||
|
|
||||||
|
@PutMapping(path = "/cretarea/update/{id}", |
||||||
|
consumes = MediaType.APPLICATION_JSON_VALUE, |
||||||
|
produces = MediaType.APPLICATION_JSON_VALUE) |
||||||
|
public ResponseEntity<?> updateCretarea(@PathVariable Integer id, @RequestBody ProgramCretarea cretarea) { |
||||||
|
ProgramCretarea pc = repo.findCretareaById(id); |
||||||
|
pc.setName(cretarea.getName()); |
||||||
|
pc.setName_short(cretarea.getName_short()); |
||||||
|
repo.save(pc); |
||||||
|
return new ResponseEntity<>(repo.findCretareaById(id), HttpStatus.CREATED); |
||||||
|
} |
||||||
|
|
||||||
|
@DeleteMapping("/cretarea/delete/{id}") |
||||||
|
public ResponseEntity<String> deleteCretarea(@PathVariable Long id){ |
||||||
|
ProgramCretarea pc = repo.findCretareaById(id); |
||||||
|
System.out.println(pc.toString()); |
||||||
|
repo.delete(pc); |
||||||
|
return new ResponseEntity<>("Запись id#" + id + " удалена ... ", HttpStatus.NOT_FOUND); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,44 @@ |
|||||||
|
package ru.molokoin.resourceserviceapi.entities; |
||||||
|
|
||||||
|
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 ProgramCretarea { |
||||||
|
@Id |
||||||
|
@GeneratedValue(strategy=GenerationType.AUTO) |
||||||
|
private long id; |
||||||
|
// @Column(length=500)
|
||||||
|
private String name;//Наименование
|
||||||
|
// @Column(length=5)
|
||||||
|
private String name_short;//Наименование : сокращенно
|
||||||
|
|
||||||
|
/** |
||||||
|
* подготовить конструкторы на все варианты внесения информации о преподавателях |
||||||
|
* |
||||||
|
* @param name |
||||||
|
* @param name_short |
||||||
|
*/ |
||||||
|
public ProgramCretarea(String name, String name_short) { |
||||||
|
this.name = name; |
||||||
|
this.name_short = name_short; |
||||||
|
} |
||||||
|
} |
@ -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.ProgramCretarea; |
||||||
|
|
||||||
|
@Repository |
||||||
|
public interface ProgramCretareaRepositoryFace extends ListCrudRepository<ProgramCretarea, Long>{ |
||||||
|
List<ProgramCretarea> findAll(); |
||||||
|
ProgramCretarea findCretareaById(long id); |
||||||
|
} |
Loading…
Reference in new issue