2023-10-06 15:32:28 +00:00
|
|
|
package com.example.springdemo.controller;
|
|
|
|
|
|
|
|
import com.example.springdemo.entities.Merchants;
|
|
|
|
import com.example.springdemo.service.MerchantsService;
|
|
|
|
import jakarta.annotation.Resource;
|
2023-10-25 10:15:56 +00:00
|
|
|
import org.springframework.web.bind.annotation.*;
|
2023-10-06 15:32:28 +00:00
|
|
|
|
2023-10-25 10:15:56 +00:00
|
|
|
import java.util.Optional;
|
2023-10-06 15:32:28 +00:00
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("/merchants")
|
|
|
|
public class MerchantsController {
|
|
|
|
@Resource
|
|
|
|
private MerchantsService merchantsService;
|
|
|
|
|
2023-10-25 10:15:56 +00:00
|
|
|
@PostMapping("/add")
|
2023-10-26 03:43:45 +00:00
|
|
|
public Merchants addMerchants(@RequestBody Merchants merchants) {
|
2023-10-26 03:33:56 +00:00
|
|
|
return merchantsService.addMerchants(merchants);
|
2023-10-06 15:32:28 +00:00
|
|
|
}
|
|
|
|
|
2023-10-25 10:15:56 +00:00
|
|
|
@DeleteMapping("/delete/{id}")
|
|
|
|
public void deleteMerchants(@PathVariable("id") Long id) {
|
|
|
|
merchantsService.deleteMerchantsById(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
@PutMapping("/update")
|
|
|
|
public Merchants updateMerchants(@RequestBody Merchants merchants) {
|
|
|
|
return merchantsService.updateMerchants(merchants);
|
2023-10-06 15:32:28 +00:00
|
|
|
}
|
|
|
|
|
2023-10-25 10:15:56 +00:00
|
|
|
@GetMapping("/find")
|
2023-10-26 03:33:56 +00:00
|
|
|
public Iterable<Merchants> getMerchants() {
|
2023-10-25 10:15:56 +00:00
|
|
|
return merchantsService.findAllMerchants();
|
|
|
|
}
|
|
|
|
|
|
|
|
@GetMapping("/find/{name}")
|
|
|
|
public Merchants getMerchantsByName(@PathVariable("name") String name) {
|
|
|
|
return merchantsService.findByName(name);
|
2023-10-06 15:32:28 +00:00
|
|
|
}
|
|
|
|
|
2023-10-25 10:15:56 +00:00
|
|
|
@GetMapping("/find/{id}")
|
2023-11-07 14:42:22 +00:00
|
|
|
public Merchants getMerchantsById(@PathVariable("id") Long id) {
|
2023-10-25 10:15:56 +00:00
|
|
|
return merchantsService.findById(id);
|
2023-10-06 15:32:28 +00:00
|
|
|
}
|
|
|
|
}
|