-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cdsl #49
base: master
Are you sure you want to change the base?
cdsl #49
Changes from all commits
e96c420
0f14a29
1caa7cb
6f1c41e
ec5b398
7a82fbe
6587227
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
package com.jwb.bankservice; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.ModelAttribute; | ||
import com.jwb.bankservice.models.Customer; | ||
import com.jwb.bankservice.services.CustomerServices; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Controller | ||
@RestController | ||
public class AddingController { | ||
@Autowired | ||
CustomerServices cServices; | ||
|
||
@PostMapping(value="/add-customer") | ||
public String addCustomer(@ModelAttribute("customerInfo") Customer customer) { | ||
int id = CustomerList.customerList.size(); | ||
customer.setId(id); | ||
CustomerList.customerList.add(customer); | ||
return "redirect:/customer-list"; | ||
public String addCustomer(@RequestBody Customer customer) { | ||
cServices.addCustomer(customer); | ||
return "/"; | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.jwb.bankservice; | ||
|
||
import com.jwb.bankservice.services.CustomerServices; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
|
||
|
||
@RestController | ||
public class DeletingController { | ||
@Autowired | ||
CustomerServices cServices; | ||
|
||
@PostMapping(value="/delete") | ||
public void delCustomer(@RequestBody String delId) { | ||
delId = delId.substring(3,delId.length()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. e có thể dùng |
||
int id = Integer.parseInt(delId); | ||
cServices.delCustomerList(id); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
package com.jwb.bankservice; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.ModelAttribute; | ||
import com.jwb.bankservice.models.Customer; | ||
import com.jwb.bankservice.services.CustomerServices; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Controller | ||
@RestController | ||
public class EditingController { | ||
@Autowired | ||
CustomerServices cServices; | ||
|
||
@PostMapping(value="/edit-customer") | ||
public String addCustomer(@ModelAttribute("customerInfo") Customer customer) { | ||
int id = CustomerList.customerList.size()-1; | ||
CustomerList.customerList.get(id).setName(customer.getName()); | ||
CustomerList.customerList.get(id).setEmail(customer.getEmail()); | ||
CustomerList.customerList.get(id).setPhoneNumber(customer.getPhoneNumber()); | ||
CustomerList.customerList.get(id).setPassword(customer.getPassword()); | ||
return "redirect:/customer-list"; | ||
public String addCustomer(@RequestBody Customer customer) { | ||
cServices.editCustomer(customer); | ||
return "/"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,34 @@ | ||
package com.jwb.bankservice; | ||
|
||
import com.jwb.bankservice.models.Customer; | ||
import com.jwb.bankservice.services.CustomerServices; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.ModelMap; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
@Controller | ||
public class ListCustomerController { | ||
@Autowired | ||
CustomerServices cServices; | ||
|
||
@RequestMapping(value = {"/", "/customer-list" }, method = RequestMethod.GET) | ||
@GetMapping(value = {"/", "/customer-list" }) | ||
public String index(ModelMap modelMap) { | ||
modelMap.addAttribute("customerList", CustomerList.customerList); | ||
modelMap.addAttribute("customerList", cServices.getAllCustomer()); | ||
return "CustomerList"; | ||
} | ||
|
||
@RequestMapping(value = { "/adding-form" }, method = RequestMethod.GET) | ||
public String addForm(ModelMap modelmap) { | ||
modelmap.addAttribute("customerInfo", new Customer()); | ||
return "Add"; | ||
} | ||
@GetMapping(value="/editing-form") | ||
public String editForm(@RequestParam(name="customerId") Integer id, ModelMap modelMap) { | ||
modelMap.addAttribute("customerInfo", CustomerList.customerList.get(id)); | ||
Customer c = cServices.getCustomer(id); | ||
modelMap.addAttribute("customerInfo", c); | ||
return "Edit"; | ||
} | ||
@GetMapping(value="/login-form") | ||
public String loginForm(@RequestParam(name="customerId") Integer id, ModelMap modelMap){ | ||
modelMap.addAttribute("customerInfo", CustomerList.customerList.get(id)); | ||
return "Login"; | ||
} | ||
@GetMapping(value="/transfering-form") | ||
public String transferingForm(@RequestParam(name="customerId") Integer id, ModelMap modelMap){ | ||
modelMap.addAttribute("customerId", id); | ||
return "Transfer"; | ||
|
||
@GetMapping(value = { "/adding-form" }) | ||
public String addForm(ModelMap modelmap) { | ||
return "Add"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,30 @@ | ||
package com.jwb.bankservice; | ||
|
||
import com.jwb.bankservice.services.CustomerServices; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.ModelMap; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
@Controller | ||
public class LoginController { | ||
@Autowired | ||
CustomerServices cServices; | ||
|
||
@GetMapping(value="/login-form") | ||
public String loginForm(@RequestParam(name="customerId") Integer id, ModelMap modelMap){ | ||
modelMap.addAttribute("customerInfo", cServices.getCustomer(id)); | ||
return "Login"; | ||
} | ||
|
||
@PostMapping(value="/login") | ||
public String addCustomer(@RequestParam(name="id") Integer id, @RequestParam(name="pw") String password) { | ||
System.out.println(id); | ||
if (CustomerList.customerList.get(id).getPassword().equals(password)){ | ||
CustomerList.customerList.get(id).setLogin(1); | ||
if (cServices.login(id, password)){ | ||
return "redirect:/customer-list"; | ||
} | ||
return "redirect:/customer-list"; | ||
return "Error"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
package com.jwb.bankservice; | ||
|
||
import com.jwb.bankservice.services.CustomerServices; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
@Controller | ||
public class LogoutController { | ||
@Autowired | ||
CustomerServices cServices; | ||
|
||
@GetMapping(value="/logout") | ||
public String logout(@RequestParam(name="customerId") Integer id){ | ||
CustomerList.customerList.get(id).setLogin(0); | ||
cServices.logout(id); | ||
return "redirect:/customer-list"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.jwb.bankservice; | ||
|
||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
import com.jwb.bankservice.services.CustomerServices; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
|
||
|
||
@RestController | ||
public class Search { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sửa thành |
||
@Autowired | ||
CustomerServices cServices; | ||
|
||
@PostMapping(value="/search") | ||
public List<String> searchCustomer(@RequestBody String data) { | ||
int n = data.length(); | ||
data = data.substring(1, n-1); | ||
List<String> listResult = cServices.search(data); | ||
return listResult; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,30 @@ | ||
package com.jwb.bankservice; | ||
|
||
import com.jwb.bankservice.services.CustomerServices; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.ModelMap; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
@Controller | ||
public class TransferingController { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sai chính tả: |
||
@Autowired | ||
CustomerServices cServices; | ||
|
||
@PostMapping(value="/transfering-form") | ||
public String transferingForm(@RequestParam(name="customerId") Integer id, @RequestParam(name="availableBalance") Integer balance, ModelMap modelMap){ | ||
modelMap.addAttribute("customerId", id); | ||
modelMap.addAttribute("balance", balance); | ||
return "Transfer"; | ||
} | ||
|
||
@PostMapping(value="/transfer") | ||
public String transfer(@RequestParam(name = "sentId") Integer sId, @RequestParam(name="receivedId") Integer rId, @RequestParam(name="amount") Integer amount){ | ||
if (rId >= CustomerList.customerList.size() || rId == sId) return "Error"; | ||
else{ | ||
CustomerList.customerList.get(sId).transferMoney(amount); | ||
CustomerList.customerList.get(rId).receiveMoney(amount); | ||
} | ||
return "redirect:/customer-list"; | ||
if (rId == sId) return "Error"; | ||
if (amount > cServices.getCustomer(sId).getBalance()) return "Error"; | ||
cServices.transferMoney(sId, rId, amount); | ||
return "redirect:/"; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.jwb.bankservice.repositories; | ||
|
||
import com.jwb.bankservice.models.Customer; | ||
import org.springframework.stereotype.Repository; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
@Repository | ||
public interface CustomerRepository extends JpaRepository<Customer, Integer>{ | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tên của service sẽ là số ít
chuyển:
CustomerService
->CustomerService