Created
June 30, 2018 02:26
-
-
Save mohashari/f6c807f618732c20edebd8d57d20e124 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.codecika.kotlindemo.controller | |
| import com.codecika.kotlindemo.converter.toModel | |
| import com.codecika.kotlindemo.model.domain.Student | |
| import com.codecika.kotlindemo.service.StudentService | |
| import com.codecika.kotlindemo.vo.StudentVO | |
| import org.springframework.beans.factory.annotation.Autowired | |
| import org.springframework.web.bind.annotation.* | |
| import java.util.* | |
| import javax.validation.Valid | |
| @RestController | |
| @RequestMapping("/student") | |
| class StudentController() { | |
| @Autowired | |
| lateinit var studentService: StudentService | |
| @GetMapping("/get-all") | |
| fun getAllStudent(): List<StudentVO> { | |
| return studentService.getAll() | |
| } | |
| @PostMapping("/add") | |
| fun addData(@Valid @RequestBody student: StudentVO): StudentVO { | |
| return studentService.saveData(student.toModel()) | |
| } | |
| @GetMapping("/student/{id}") | |
| fun getStudentById(@PathVariable(value = "id") id: Long): Optional<StudentVO> { | |
| return studentService.getDetail(id) | |
| } | |
| @PutMapping("/edit") | |
| fun updateArticleById(@RequestBody student: Student): StudentVO { | |
| return studentService.editData(student) | |
| } | |
| @DeleteMapping("/delete/{id}") | |
| fun deleteStudent(@PathVariable(value = "id") id: Long): String { | |
| return studentService.deleteStudent(id) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment