Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

cdsl #49

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions 17020996_nguyen_trong_ruong/my-system/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
Expand All @@ -33,13 +33,28 @@
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<!-- JPA Data (We are going to use Repositories, Entities, Hibernate, etc...) -->

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<!-- Use MySQL Connector-J -->

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</dependencies>

<build>
<plugins>
Expand Down
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;
Copy link
Contributor

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


@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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e có thể dùng delId.substring(3) để thay thế

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sửa thành SearchController

@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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sai chính tả: transferring

@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
@@ -1,22 +1,32 @@
package com.jwb.bankservice;
package com.jwb.bankservice.models;

import javax.persistence.*;

@Entity
@Table(name = "Customer")
public class Customer {
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private int id;

private String name, email, phoneNumber, password = "123456";
private int id, balance, login = 0;
@Column(name = "name")
private String name;

public Customer() {
@Column(name = "email")
private String email;

}
@Column(name = "phone")
private String phoneNumber;

public Customer(int id, String name, String email, String phoneNumber, int balance) {
this.id = id;
this.name = name;
this.email = email;
this.phoneNumber = phoneNumber;
this.balance = balance;
}
@Column(name = "password")
private String password = "123456";

@Column(name = "balance")
private int balance;

@Column(name = "login")
private int login = 1;

public int getId(){
return id;
}
Expand Down
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>{

}
Loading