diff --git a/src/main/java/com/example/springdemo/controller/MerchantsController.java b/src/main/java/com/example/springdemo/controller/MerchantsController.java new file mode 100644 index 0000000..b84c0d5 --- /dev/null +++ b/src/main/java/com/example/springdemo/controller/MerchantsController.java @@ -0,0 +1,49 @@ +package com.example.springdemo.controller; + +import com.example.springdemo.entities.Merchants; +import com.example.springdemo.service.MerchantsService; +import jakarta.annotation.Resource; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequestMapping("/merchants") +public class MerchantsController { + @Resource + private MerchantsService merchantsService; + + @GetMapping("/findAll") + public List getMerchants() { + return merchantsService.findAll(); + } + + @GetMapping("/findByName") + public List getMerchantsByName(@RequestParam("name") String name) { + return merchantsService.findByName(name); + } + + @GetMapping("/save") + public String saveMerchants(@RequestParam("name") String name, + @RequestParam("address") String address, + @RequestParam("description") String description, + @RequestParam("phoneNumber") String phoneNumber) { + + Merchants merchants = new Merchants(); + merchants.setName(name); + merchants.setAddress(address); + merchants.setDescription(description); + merchants.setPhoneNumber(phoneNumber); + merchantsService.save(merchants); + return "success"; + } + + @GetMapping("/delete") + public String deleteMerchants(@RequestParam("id") Long id) { + merchantsService.deleteById(id); + return "success"; + } +} diff --git a/src/main/java/com/example/springdemo/controller/StudentController.java b/src/main/java/com/example/springdemo/controller/StudentController.java deleted file mode 100644 index 56161f2..0000000 --- a/src/main/java/com/example/springdemo/controller/StudentController.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.example.springdemo.controller; - -import com.example.springdemo.entities.Business; -import com.example.springdemo.config.DataBaseProperties; - -import jakarta.annotation.Resource; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import java.util.List; -import java.util.Objects; - -@RestController -@RequestMapping("/student") -public class StudentController { - - @Resource - DataBaseProperties dbProps; - - @GetMapping("/get") - public List getStudent() { - // DataBaseProperties dbProps = new DataBaseProperties(); - return List.of(dbProps.getUsername(), dbProps.getPassword(), dbProps.getDbUrl()); - } - - @GetMapping("/getBy") - public Business getStudentById(@RequestParam String id) { - - var bs = Business.builder() - .name(id) - .tel(dbProps.getPassword()) - .build(); - - if (!Objects.equals(bs.getTel(), "")) { - bs.setTel(""); - } - - return bs; - } -}