Skip to content

Commit

Permalink
modify code details
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongyuanzhao000 committed Nov 28, 2019
1 parent c1d1404 commit e7553b0
Showing 10 changed files with 68 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -10,6 +10,9 @@
import org.springframework.web.client.RestTemplate;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
* @author fdse
*/
@SpringBootApplication
@EnableAspectJAutoProxy(proxyTargetClass = true)
@EnableAsync
Original file line number Diff line number Diff line change
@@ -18,24 +18,31 @@

import static org.springframework.web.cors.CorsConfiguration.ALL;

/**
* @author fdse
*/
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {

// load password encoder
/**
* load password encoder
*
* @return PasswordEncoder
*/
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}

/**
* allow cors domain
* header 在默认的情况下只能从头部取出6个字段,想要其他字段只能自己在头里指定
* credentials 默认不发送Cookie, 如果需要Cookie,这个值只能为true
* 本次请求检查的有效期
* header By default, only six fields can be taken from the header, and the other fields can only be specified in the header.
* credentials Cookies are not sent by default and can only be true if a Cookie is needed
* Validity of this request
*
* @return
* @return WebMvcConfigurer
*/
@Bean
public WebMvcConfigurer corsConfigurer() {
Original file line number Diff line number Diff line change
@@ -2,19 +2,25 @@

import adminbasic.entity.*;
import adminbasic.service.AdminBasicInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import static org.springframework.http.ResponseEntity.ok;

/**
* @author fdse
*/
@RestController
@RequestMapping("/api/v1/adminbasicservice")
public class AdminBasicInfoController {

@Autowired
AdminBasicInfoService adminBasicInfoService;
private static final Logger LOGGER = LoggerFactory.getLogger(AdminBasicInfoController.class);

@GetMapping(path = "/welcome")
public String home(@RequestHeader HttpHeaders headers) {
@@ -24,144 +30,140 @@ public String home(@RequestHeader HttpHeaders headers) {
@CrossOrigin(origins = "*")
@GetMapping(path = "/adminbasic/contacts")
public HttpEntity getAllContacts(@RequestHeader HttpHeaders headers) {
System.out.println("[Admin Basic Info Service][Find All Contacts by admin ");
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Find All Contacts by admin ");
return ok(adminBasicInfoService.getAllContacts(headers));
}

@CrossOrigin(origins = "*")
@DeleteMapping(path = "/adminbasic/contacts/{contactsId}")
public HttpEntity deleteContacts(@PathVariable String contactsId, @RequestHeader HttpHeaders headers) {
System.out.println("[Admin Basic Info Service][Delete Contacts by admin ");
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Delete Contacts by admin ");
return ok(adminBasicInfoService.deleteContact(contactsId, headers));
}

@CrossOrigin(origins = "*")
@PutMapping(path = "/adminbasic/contacts")
public HttpEntity modifyContacts(@RequestBody Contacts mci, @RequestHeader HttpHeaders headers) {
System.out.println("[Admin Basic Info Service][Modify Contacts by admin: ");
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Modify Contacts by admin: ");
return ok(adminBasicInfoService.modifyContact(mci, headers));
}

@CrossOrigin(origins = "*")
@PostMapping(path = "/adminbasic/contacts")
public HttpEntity addContacts(@RequestBody Contacts c, @RequestHeader HttpHeaders headers) {
System.out.println("[Admin Basic Info Service][Modify Contacts by admin ");
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Modify Contacts by admin ");
return ok(adminBasicInfoService.addContact(c, headers));
}

/////////////////////////station/////////////////////////////////////////////////////////////////////////////////
@CrossOrigin(origins = "*")
@GetMapping(path = "/adminbasic/stations")
public HttpEntity getAllStations(@RequestHeader HttpHeaders headers) {
System.out.println("[Admin Basic Info Service][Find All Station by admin ");
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Find All Station by admin ");
return ok(adminBasicInfoService.getAllStations(headers));
}

@CrossOrigin(origins = "*")
@DeleteMapping(path = "/adminbasic/stations")
public HttpEntity deleteStation(@RequestBody Station s, @RequestHeader HttpHeaders headers) {
System.out.println("[Admin Basic Info Service][Delete Station by admin ");
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Delete Station by admin ");
return ok(adminBasicInfoService.deleteStation(s, headers));
}

@CrossOrigin(origins = "*")
@PutMapping(path = "/adminbasic/stations")
public HttpEntity modifyStation(@RequestBody Station s, @RequestHeader HttpHeaders headers) {
System.out.println("[Admin Basic Info Service][Modify Station by admin ");
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Modify Station by admin ");
return ok(adminBasicInfoService.modifyStation(s, headers));
}

@CrossOrigin(origins = "*")
@PostMapping(path = "/adminbasic/stations")
public HttpEntity addStation(@RequestBody Station s, @RequestHeader HttpHeaders headers) {
System.out.println("[Admin Basic Info Service][Modify Station by admin");
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Modify Station by admin");
return ok(adminBasicInfoService.addStation(s, headers));
}

/////////////////////////train/////////////////////////////////////////////////////////////////////////////////
@CrossOrigin(origins = "*")
@GetMapping(path = "/adminbasic/trains")
public HttpEntity getAllTrains(@RequestHeader HttpHeaders headers) {
System.out.println("[Admin Basic Info Service][Find All Train by admin: ");
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Find All Train by admin: ");
return ok(adminBasicInfoService.getAllTrains(headers));
}

@CrossOrigin(origins = "*")
@DeleteMapping(path = "/adminbasic/trains/{id}")
public HttpEntity deleteTrain(@PathVariable String id, @RequestHeader HttpHeaders headers) {
System.out.println("[Admin Basic Info Service][Delete Train by admin");
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Delete Train by admin");
return ok(adminBasicInfoService.deleteTrain(id, headers));
}

@CrossOrigin(origins = "*")
@PutMapping(path = "/adminbasic/trains")
public HttpEntity modifyTrain(@RequestBody TrainType t, @RequestHeader HttpHeaders headers) {
System.out.println("[Admin Basic Info Service][Modify Train by admin ");
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Modify Train by admin ");
return ok(adminBasicInfoService.modifyTrain(t, headers));
}

@CrossOrigin(origins = "*")
@PostMapping(path = "/adminbasic/trains")
public HttpEntity addTrain(@RequestBody TrainType t, @RequestHeader HttpHeaders headers) {
System.out.println("[Admin Basic Info Service][Modify Train by admin ");
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Modify Train by admin ");
return ok(adminBasicInfoService.addTrain(t, headers));
}

/////////////////////////config/////////////////////////////////////////////////////////////////////////////////
@CrossOrigin(origins = "*")
@GetMapping(path = "/adminbasic/configs")
public HttpEntity getAllConfigs(@RequestHeader HttpHeaders headers) {
System.out.println("[Admin Basic Info Service][Find All Config by admin ");
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Find All Config by admin ");
return ok(adminBasicInfoService.getAllConfigs(headers));
}

@CrossOrigin(origins = "*")
@DeleteMapping(path = "/adminbasic/configs/{name}")
public HttpEntity deleteConfig(@PathVariable String name, @RequestHeader HttpHeaders headers) {
System.out.println("[Admin Basic Info Service][Delete Config by admin ");
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Delete Config by admin ");
return ok(adminBasicInfoService.deleteConfig(name, headers));
}

@CrossOrigin(origins = "*")
@PutMapping(path = "/adminbasic/configs")
public HttpEntity modifyConfig(@RequestBody Config c, @RequestHeader HttpHeaders headers) {
System.out.println("[Admin Basic Info Service][Modify Config by admin ");
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Modify Config by admin ");
return ok(adminBasicInfoService.modifyConfig(c, headers));
}

@CrossOrigin(origins = "*")
@PostMapping(path = "/adminbasic/configs")
public HttpEntity addConfig(@RequestBody Config c, @RequestHeader HttpHeaders headers) {
System.out.println("[Admin Basic Info Service][Modify Config by admin ");
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Modify Config by admin ");
return ok(adminBasicInfoService.addConfig(c, headers));
}

/////////////////////////price/////////////////////////////////////////////////////////////////////////////////
@CrossOrigin(origins = "*")
@GetMapping(path = "/adminbasic/prices")
public HttpEntity getAllPrices(@RequestHeader HttpHeaders headers) {
System.out.println("[Admin Basic Info Service][Find All Price by admin: ");
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Find All Price by admin: ");
return ok(adminBasicInfoService.getAllPrices(headers));
}

@CrossOrigin(origins = "*")
@DeleteMapping(path = "/adminbasic/prices")
public HttpEntity deletePrice(@RequestBody PriceInfo pi, @RequestHeader HttpHeaders headers) {
System.out.println("[Admin Basic Info Service][Delete Price by admin ");
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Delete Price by admin ");
return ok(adminBasicInfoService.deletePrice(pi, headers));
}

@CrossOrigin(origins = "*")
@PutMapping(path = "/adminbasic/prices")
public HttpEntity modifyPrice(@RequestBody PriceInfo pi, @RequestHeader HttpHeaders headers) {
System.out.println("[Admin Basic Info Service][Modify Price by admin ");
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Modify Price by admin ");
return ok(adminBasicInfoService.modifyPrice(pi, headers));
}

@CrossOrigin(origins = "*")
@PostMapping(path = "/adminbasic/prices")
public HttpEntity addPrice(@RequestBody PriceInfo pi, @RequestHeader HttpHeaders headers) {
System.out.println("[Admin Basic Info Service][Add Price by admin");
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Add Price by admin");
return ok(adminBasicInfoService.addPrice(pi, headers));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package adminbasic.entity;

/**
* @author fdse
*/
public class Config {

private String name;
@@ -11,7 +14,7 @@ public class Config {


public Config() {

//Default Constructor
}
public void setName(String name) {
this.name = name;
Original file line number Diff line number Diff line change
@@ -6,6 +6,9 @@
import java.io.Serializable;
import java.util.UUID;

/**
* @author fdse
*/
@ToString
@Data
public class Contacts implements Serializable {
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package adminbasic.entity;

/**
* @author fdse
*/
public class PriceInfo {

private String id;
@@ -14,7 +17,7 @@ public class PriceInfo {


public PriceInfo() {

//Default Constructor
}

public String getId() {
Original file line number Diff line number Diff line change
@@ -3,7 +3,9 @@
import javax.validation.Valid;
import javax.validation.constraints.NotNull;


/**
* @author fdse
*/
public class Station {

private String id;
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package adminbasic.entity;



/**
* @author fdse
*/
public class TrainType {

private String id;
Original file line number Diff line number Diff line change
@@ -4,11 +4,12 @@
import edu.fudan.common.util.Response;
import org.springframework.http.HttpHeaders;

import javax.annotation.Resource;

/**
* @author fdse
*/
public interface AdminBasicInfoService {

////////////contact/////////////////////////////////////////
Response getAllContacts( HttpHeaders headers);

Response addContact( Contacts c, HttpHeaders headers);
@@ -17,7 +18,7 @@ public interface AdminBasicInfoService {

Response modifyContact(Contacts mci, HttpHeaders headers);

////////////////////////////station///////////////////////////////

Response getAllStations( HttpHeaders headers);

Response addStation(Station s, HttpHeaders headers);
@@ -26,7 +27,7 @@ public interface AdminBasicInfoService {

Response modifyStation(Station s, HttpHeaders headers);

////////////////////////////train///////////////////////////////

Response getAllTrains( HttpHeaders headers);

Response addTrain(TrainType t, HttpHeaders headers);
@@ -35,7 +36,7 @@ public interface AdminBasicInfoService {

Response modifyTrain(TrainType t, HttpHeaders headers);

////////////////////////////config///////////////////////////////

Response getAllConfigs( HttpHeaders headers);

Response addConfig(Config c, HttpHeaders headers);
@@ -45,7 +46,7 @@ public interface AdminBasicInfoService {

Response modifyConfig(Config c, HttpHeaders headers);

////////////////////////////price///////////////////////////////

Response getAllPrices( HttpHeaders headers);

Response addPrice(PriceInfo pi, HttpHeaders headers);
@@ -54,6 +55,5 @@ public interface AdminBasicInfoService {

Response modifyPrice(PriceInfo pi, HttpHeaders headers);

// Contacts login(String name, String password);

}
Loading

0 comments on commit e7553b0

Please sign in to comment.