diff --git a/.idea/dictionaries/afilippov.xml b/.idea/dictionaries/afilippov.xml
new file mode 100644
index 0000000..dc97e49
--- /dev/null
+++ b/.idea/dictionaries/afilippov.xml
@@ -0,0 +1,7 @@
+
+
+
+ succeful
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index b04e900..af4109c 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,69 +1,12 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
@@ -148,11 +91,11 @@
-
+
-
-
+
+
@@ -163,8 +106,8 @@
-
-
+
+
@@ -172,16 +115,46 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
-
-
+
+
@@ -208,12 +181,14 @@
@@ -331,15 +306,6 @@
-
-
-
-
-
-
-
-
-
@@ -435,10 +401,6 @@
-
-
-
-
@@ -458,7 +420,14 @@
1512033510258
-
+
+ 1512034509917
+
+
+
+ 1512034509917
+
+
@@ -468,7 +437,7 @@
-
+
@@ -631,35 +600,61 @@
-
+
-
-
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
+
-
-
+
+
-
+
+
diff --git a/src/main/java/ru/cft/task/restServer/BookStatus.java b/src/main/java/ru/cft/task/restServer/BookStatus.java
new file mode 100644
index 0000000..57200a3
--- /dev/null
+++ b/src/main/java/ru/cft/task/restServer/BookStatus.java
@@ -0,0 +1,31 @@
+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;
+ }
+
+}
diff --git a/src/main/java/ru/cft/task/restServer/EmailBook.java b/src/main/java/ru/cft/task/restServer/EmailBook.java
index 947f241..bee92fd 100644
--- a/src/main/java/ru/cft/task/restServer/EmailBook.java
+++ b/src/main/java/ru/cft/task/restServer/EmailBook.java
@@ -1,41 +1,35 @@
package ru.cft.task.restServer;
+import java.util.HashMap;
+
public class EmailBook {
- private long id;
- private String name;
- private String email;
+ private HashMap book;
+ private BookStatus status;
- public EmailBook(long id, String name, String email) {
- setId(id);
- setName(name);
- setEmail(email);
+ public EmailBook() {
+ this.book = new HashMap();
+ this.status.setStatus(true);
}
- public long getId() {
- return id;
+ 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 void setId(long id) {
- this.id = 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 String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getEmail() {
- return email;
- }
-
- public void setEmail(String email) {
- this.email = email;
- }
-
- public String toString(){
- return String.valueOf(getId()).concat(": ").concat(getName()).concat(" - ").concat(getEmail());
+ public int count() {
+ return this.book.size();
}
}
diff --git a/src/main/java/ru/cft/task/restServer/EmailBookController.java b/src/main/java/ru/cft/task/restServer/EmailBookController.java
index 311092d..a53db99 100644
--- a/src/main/java/ru/cft/task/restServer/EmailBookController.java
+++ b/src/main/java/ru/cft/task/restServer/EmailBookController.java
@@ -2,6 +2,7 @@ package ru.cft.task.restServer;
import org.apache.log4j.Logger;
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;
@@ -10,12 +11,15 @@ import java.util.concurrent.atomic.AtomicLong;
public class EmailBookController {
final static Logger log = Logger.getLogger(EmailBookController.class);
private final AtomicLong new_id = new AtomicLong();
+ private EmailBook book = new EmailBook();
- @RequestMapping("/email")
- public EmailBook emailRec(@RequestParam(value = "name", defaultValue = "John Unknown") String name,
- @RequestParam(value = "email", defaultValue = "john@unknown.ru") String email) {
- EmailBook emailBook = new EmailBook(new_id.incrementAndGet(), name, email);
- log.debug(emailBook.toString());
- return 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) {
+ EmailRecord rec = new EmailRecord(new_id.incrementAndGet(), name, email);
+ return this.book.addRecord(rec);
}
+
+ //@RequestMapping(value = "/email", method = RequestMethod.DELETE)
+ //public em
}
diff --git a/src/main/java/ru/cft/task/restServer/EmailRecord.java b/src/main/java/ru/cft/task/restServer/EmailRecord.java
new file mode 100644
index 0000000..0347a59
--- /dev/null
+++ b/src/main/java/ru/cft/task/restServer/EmailRecord.java
@@ -0,0 +1,41 @@
+package ru.cft.task.restServer;
+
+public class EmailRecord {
+ private long id;
+ private String name;
+ private String email;
+
+ public EmailRecord(long id, String name, String email) {
+ setId(id);
+ setName(name);
+ setEmail(email);
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public String toString() {
+ return String.valueOf(getId()).concat(": ").concat(getName()).concat(" - ").concat(getEmail());
+ }
+}