initial commit this project for test architecture
This commit is contained in:
54
src/main/java/com/example/mmad/testapp/controller/PersonController.java
Executable file
54
src/main/java/com/example/mmad/testapp/controller/PersonController.java
Executable file
@ -0,0 +1,54 @@
|
||||
package com.example.mmad.testapp.controller;
|
||||
|
||||
import com.example.mmad.testapp.model.PersonModel;
|
||||
import com.example.mmad.testapp.service.PersonService;
|
||||
import com.example.mmad.testapp.service.StreamProducer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/person")
|
||||
public class PersonController {
|
||||
|
||||
private PersonService personService;
|
||||
private StreamProducer streamProducer;
|
||||
|
||||
@Autowired
|
||||
public void setPersonService(PersonService personService, StreamProducer streamProducer) {
|
||||
this.streamProducer = streamProducer;
|
||||
this.personService = personService;
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public String listPosts() {
|
||||
streamProducer.sendMessage("hi hi hi");
|
||||
return "aaa";
|
||||
}
|
||||
|
||||
@CrossOrigin(origins = "http://localhost:3001")
|
||||
@PostMapping("/create")
|
||||
public ResponseEntity<?> create(@Valid @RequestBody PersonModel person) {
|
||||
return ResponseEntity.ok(personService.createPerson(person));
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public ResponseEntity<?> update(@Valid @RequestBody PersonModel person) {
|
||||
return ResponseEntity.ok(personService.updatePerson(person));
|
||||
}
|
||||
|
||||
@PostMapping("/get/{id}")
|
||||
public ResponseEntity<?> getPerson(@PathVariable Long id) {
|
||||
return ResponseEntity.ok(personService.getPerson(id));
|
||||
}
|
||||
|
||||
@PostMapping("/delete/{id}")
|
||||
public ResponseEntity<?> deletePerson(@PathVariable Long id) {
|
||||
personService.deletePerson(id);
|
||||
return ResponseEntity.ok("ok");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user