reformatted as per standard formatter and incorporated review comments.
This commit is contained in:
+5
-5
@@ -5,9 +5,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+13
-13
@@ -3,23 +3,23 @@ package com.baeldung.adapter;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.baeldung.domain.Document;
|
||||
import com.baeldung.port.DocumentRepo;
|
||||
import com.baeldung.domain.port.DocumentRepo;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Repository
|
||||
public class DocumentRepositoryImpl implements DocumentRepo {
|
||||
|
||||
private Map<String, Document> documentMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void storeDocument(Document document) {
|
||||
documentMap.put(document.getId(), document);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document findDocumentById(String id) {
|
||||
return documentMap.get(id);
|
||||
}
|
||||
|
||||
private Map<String, Document> documentMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void storeDocument(Document document) {
|
||||
documentMap.put(document.getId(), document);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document findDocumentById(String id) {
|
||||
return documentMap.get(id);
|
||||
}
|
||||
}
|
||||
|
||||
+14
-15
@@ -1,26 +1,25 @@
|
||||
package com.baeldung.adapter;
|
||||
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import com.baeldung.domain.Document;
|
||||
import com.baeldung.port.DocumentService;
|
||||
import com.baeldung.domain.port.DocumentService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/doc")
|
||||
public class DocumentRestAdapter {
|
||||
@Autowired
|
||||
private DocumentService documentService;
|
||||
|
||||
@PostMapping
|
||||
public void createDocument(@RequestBody Document document) {
|
||||
documentService.createDocument(document);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public Document findById(@PathVariable String id) {
|
||||
return documentService.findById(id);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private DocumentService documentService;
|
||||
|
||||
@PostMapping
|
||||
public void createDocument(@RequestBody Document document) {
|
||||
documentService.createDocument(document);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public Document findById(@PathVariable String id) {
|
||||
return documentService.findById(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+19
-17
@@ -1,21 +1,23 @@
|
||||
package com.baeldung.domain;
|
||||
|
||||
public class Document {
|
||||
private String id;
|
||||
private String data;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
public void setData(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
|
||||
private String id;
|
||||
private String data;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.baeldung.domain.port;
|
||||
|
||||
import com.baeldung.domain.Document;
|
||||
|
||||
public interface DocumentRepo {
|
||||
void storeDocument(Document document);
|
||||
|
||||
Document findDocumentById(String id);
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package com.baeldung.domain.port;
|
||||
|
||||
import com.baeldung.domain.Document;
|
||||
|
||||
public interface DocumentService {
|
||||
|
||||
void createDocument(Document document);
|
||||
|
||||
Document findById(String id);
|
||||
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.baeldung.domain.port.impl;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baeldung.domain.Document;
|
||||
import com.baeldung.domain.port.DocumentRepo;
|
||||
import com.baeldung.domain.port.DocumentService;
|
||||
|
||||
@Service
|
||||
public class DocumentServiceImpl implements DocumentService {
|
||||
|
||||
@Autowired
|
||||
private DocumentRepo documentRepo;
|
||||
|
||||
@Override
|
||||
public void createDocument(Document document) {
|
||||
documentRepo.storeDocument(document);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document findById(String id) {
|
||||
return documentRepo.findDocumentById(id);
|
||||
}
|
||||
}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
package com.baeldung.port;
|
||||
|
||||
import com.baeldung.domain.Document;
|
||||
|
||||
public interface DocumentRepo {
|
||||
void storeDocument(Document document);
|
||||
|
||||
Document findDocumentById(String id);
|
||||
}
|
||||
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
package com.baeldung.port;
|
||||
|
||||
import com.baeldung.domain.Document;
|
||||
|
||||
public interface DocumentService {
|
||||
|
||||
void createDocument(Document document);
|
||||
|
||||
Document findById(String id);
|
||||
|
||||
}
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
package com.baeldung.port.impl;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baeldung.domain.Document;
|
||||
import com.baeldung.port.DocumentRepo;
|
||||
import com.baeldung.port.DocumentService;
|
||||
|
||||
@Service
|
||||
public class DocumentServiceImpl implements DocumentService {
|
||||
|
||||
@Autowired
|
||||
private DocumentRepo documentRepo;
|
||||
|
||||
@Override
|
||||
public void createDocument(Document document) {
|
||||
documentRepo.storeDocument(document);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document findById(String id) {
|
||||
return documentRepo.findDocumentById(id);
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -8,9 +8,9 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
@SpringBootTest
|
||||
@RunWith(SpringRunner.class)
|
||||
class ApplicationUnitTest {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user