Промежуточный коммит
This commit is contained in:
@ -1,31 +0,0 @@
|
||||
package ru.cft.task.restServer;
|
||||
|
||||
public class BookStatus {
|
||||
private boolean status;
|
||||
private String message;
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public BookStatus setMessage(String message) {
|
||||
this.message = message;
|
||||
this.status = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BookStatus setError(String message) {
|
||||
this.message = message;
|
||||
this.status = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(boolean status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
}
|
@ -1,35 +1,8 @@
|
||||
package ru.cft.task.restServer;
|
||||
|
||||
import java.util.HashMap;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||
|
||||
public class EmailBook {
|
||||
private HashMap<Long, EmailRecord> book;
|
||||
private BookStatus status;
|
||||
|
||||
public EmailBook() {
|
||||
this.book = new HashMap();
|
||||
this.status.setStatus(true);
|
||||
}
|
||||
|
||||
public BookStatus addRecord(EmailRecord rec) {
|
||||
if (!this.book.containsKey(rec.getId())) {
|
||||
this.book.put(rec.getId(), rec);
|
||||
return this.status.setMessage("Запись успешно добавлена");
|
||||
}else{
|
||||
return this.status.setError("Запись с таким id уже существует");
|
||||
}
|
||||
}
|
||||
|
||||
public BookStatus removeRecord(Long id) {
|
||||
if (!this.book.containsKey(id)) {
|
||||
this.book.remove(id);
|
||||
return this.status.setMessage("Запись успешно удалена");
|
||||
}else{
|
||||
return this.status.setError("Записи с таким id не существует");
|
||||
}
|
||||
}
|
||||
|
||||
public int count() {
|
||||
return this.book.size();
|
||||
}
|
||||
@RepositoryRestResource
|
||||
public interface EmailBook extends CrudRepository{
|
||||
}
|
||||
|
@ -1,25 +1,34 @@
|
||||
package ru.cft.task.restServer;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
@RestController
|
||||
public class EmailBookController {
|
||||
final static Logger log = Logger.getLogger(EmailBookController.class);
|
||||
private final AtomicLong new_id = new AtomicLong();
|
||||
private EmailBook book = new EmailBook();
|
||||
|
||||
@RequestMapping(value = "/email", method = RequestMethod.POST)
|
||||
public BookStatus emailRec(@RequestParam(value = "name", defaultValue = "John Unknown") String name,
|
||||
@RequestParam(value = "email", defaultValue = "john@unknown.ru") String email) {
|
||||
@Autowired
|
||||
private EmailBook emailBook;
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST)
|
||||
public EmailRecord addEmailRec(@RequestParam(value = "name", defaultValue = "John Unknown") String name,
|
||||
@RequestParam(value = "email", defaultValue = "john@unknown.ru") String email) {
|
||||
EmailRecord rec = new EmailRecord(new_id.incrementAndGet(), name, email);
|
||||
return this.book.addRecord(rec);
|
||||
return rec;
|
||||
}
|
||||
|
||||
//@RequestMapping(value = "/email", method = RequestMethod.DELETE)
|
||||
//public em
|
||||
@RequestMapping(method = RequestMethod.DELETE)
|
||||
public boolean removeEmailRec(@RequestParam(value = "id", required = true) Long id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
public int sizeBook() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,32 @@
|
||||
package ru.cft.task.restServer;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class EmailRecord {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@Column(name = "id")
|
||||
private long id;
|
||||
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
|
||||
@Column(name = "email")
|
||||
private String email;
|
||||
|
||||
public EmailRecord() {
|
||||
super();
|
||||
}
|
||||
|
||||
public EmailRecord(long id, String name, String email) {
|
||||
setId(id);
|
||||
setName(name);
|
||||
setEmail(email);
|
||||
super();
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
@ -35,7 +53,8 @@ public class EmailRecord {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.valueOf(getId()).concat(": ").concat(getName()).concat(" - ").concat(getEmail());
|
||||
return "Rec[" + id + "]: " + name + "<" + email + ">";
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,12 @@
|
||||
package ru.cft.task.restServer;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Main {
|
||||
final static Logger log = Logger.getLogger(Main.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
log.debug("Run restServer");
|
||||
SpringApplication.run(Main.class, args);
|
||||
}
|
||||
}
|
||||
|
@ -1,2 +1,3 @@
|
||||
server.port = 8090
|
||||
spring.profiles.active=local
|
||||
spring.profiles.active=local
|
||||
logging.level.root=DEBUG
|
@ -1,8 +0,0 @@
|
||||
log4j.rootLogger=DEBUG, file
|
||||
|
||||
log4j.appender.file=org.apache.log4j.RollingFileAppender
|
||||
log4j.appender.file.File=restServer.log
|
||||
log4j.appender.file.MaxFileSize=5MB
|
||||
log4j.appender.file.MaxBackupIndex=10
|
||||
log4j.appender.file.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
|
Reference in New Issue
Block a user