wad-lab 1.1.6 → 1.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/templates/fullstack-springboot-vue/backend/src/main/java/com/example/company/controller/CompanyController.java +88 -74
- package/templates/fullstack-springboot-vue/backend/src/main/java/com/example/company/model/Employee.java +73 -73
- package/templates/fullstack-springboot-vue/backend/src/main/java/com/example/company/service/CompanyService.java +90 -60
- package/templates/fullstack-springboot-vue/frontend/vue-axios-basic/src/App.vue +429 -405
- package/templates/fullstack-springboot-vue/frontend/vue-axios-interceptor/src/App.vue +177 -159
- package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia/src/App.vue +441 -427
- package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia/src/stores/companyStore.js +126 -96
- package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/App.vue +84 -69
- package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/components/DepartmentSection.vue +164 -152
- package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/components/EmployeeSection.vue +193 -181
- package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/stores/companyStore.js +126 -35
- package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/App.vue +191 -167
- package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/DepartmentForm.vue +98 -98
- package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/DepartmentList.vue +92 -91
- package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/EmployeeForm.vue +128 -128
- package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/EmployeeList.vue +95 -94
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/App.vue +90 -90
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/AddEmployeeView.vue +247 -247
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/DepartmentView.vue +296 -273
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/EmployeeView.vue +219 -196
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/HomeDashboardView.vue +263 -263
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-children/src/views/DepartmentListView.vue +250 -231
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-children/src/views/EmployeeDetailView.vue +181 -159
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-children/src/views/EmployeeListView.vue +315 -295
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia/src/stores/companyStore.js +137 -70
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia/src/views/DepartmentView.vue +229 -209
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia/src/views/EmployeeView.vue +257 -237
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/components/EntityTable.vue +106 -92
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/stores/companyStore.js +139 -84
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/views/ManageDepartmentsView.vue +73 -64
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/views/ManageEmployeesView.vue +76 -67
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/App.vue +59 -59
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/components/DataCard.vue +72 -53
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/views/DepartmentPage.vue +89 -77
- package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/views/EmployeePage.vue +128 -116
- package/templates/springboot-2model-1controller-api/src/main/java/com/example/company/controller/CompanyController.java +88 -74
- package/templates/springboot-2model-1controller-api/src/main/java/com/example/company/model/Employee.java +73 -73
- package/templates/springboot-2model-1controller-api/src/main/java/com/example/company/service/CompanyService.java +90 -60
- package/templates/springboot-course-registration/src/main/java/com/example/coursereg/controller/CourseController.java +46 -42
- package/templates/springboot-course-registration/src/main/java/com/example/coursereg/service/CourseService.java +70 -60
- package/templates/springboot-hospital-api/src/main/java/com/example/hospital/controller/HospitalController.java +54 -50
- package/templates/springboot-hospital-api/src/main/java/com/example/hospital/service/HospitalService.java +65 -54
- package/templates/springboot-library-api/src/main/java/com/example/library/controller/LibraryController.java +57 -51
- package/templates/springboot-library-api/src/main/java/com/example/library/service/LibraryService.java +70 -60
- package/templates/springboot-mockmvc/src/main/java/com/example/mockmvc/controller/ItemController.java +45 -41
- package/templates/springboot-mockmvc/src/main/java/com/example/mockmvc/service/ItemService.java +48 -38
- package/templates/springboot-mongo-aggregation/src/main/java/com/example/aggregation/controller/ItemController.java +45 -41
- package/templates/springboot-mongo-aggregation/src/main/java/com/example/aggregation/service/ItemService.java +48 -38
- package/templates/springboot-mongo-aggregation-mockmvc/src/main/java/com/example/aggmockmvc/controller/ItemController.java +45 -41
- package/templates/springboot-mongo-aggregation-mockmvc/src/main/java/com/example/aggmockmvc/service/ItemService.java +48 -38
- package/templates/springboot-mongo-crud/src/main/java/com/example/crud/controller/ItemController.java +45 -41
- package/templates/springboot-mongo-crud/src/main/java/com/example/crud/service/ItemService.java +48 -38
- package/templates/vue-axios/src/App.vue +264 -243
- package/templates/vue-axios/src/services/ItemService.js +27 -21
- package/templates/vue-axios-basic/src/App.vue +24 -0
- package/templates/vue-axios-interceptor/src/App.vue +177 -159
- package/templates/vue-axios-pinia/src/App.vue +14 -0
- package/templates/vue-axios-pinia/src/stores/companyStore.js +126 -96
- package/templates/vue-axios-pinia-props/src/App.vue +84 -69
- package/templates/vue-axios-pinia-props/src/components/DepartmentSection.vue +164 -152
- package/templates/vue-axios-pinia-props/src/components/EmployeeSection.vue +193 -181
- package/templates/vue-axios-pinia-props/src/stores/companyStore.js +126 -35
- package/templates/vue-axios-props-emits/src/App.vue +24 -0
- package/templates/vue-axios-props-emits/src/components/DepartmentList.vue +2 -1
- package/templates/vue-axios-props-emits/src/components/EmployeeList.vue +2 -1
- package/templates/vue-axios-router/src/views/DepartmentView.vue +23 -0
- package/templates/vue-axios-router/src/views/EmployeeView.vue +23 -0
- package/templates/vue-axios-router-children/src/views/DepartmentListView.vue +250 -231
- package/templates/vue-axios-router-children/src/views/EmployeeDetailView.vue +181 -159
- package/templates/vue-axios-router-children/src/views/EmployeeListView.vue +315 -295
- package/templates/vue-axios-router-pinia/src/stores/companyStore.js +137 -70
- package/templates/vue-axios-router-pinia/src/views/DepartmentView.vue +229 -209
- package/templates/vue-axios-router-pinia/src/views/EmployeeView.vue +257 -237
- package/templates/vue-axios-router-pinia-props/src/components/EntityTable.vue +106 -92
- package/templates/vue-axios-router-pinia-props/src/stores/companyStore.js +139 -84
- package/templates/vue-axios-router-pinia-props/src/views/ManageDepartmentsView.vue +73 -64
- package/templates/vue-axios-router-pinia-props/src/views/ManageEmployeesView.vue +76 -67
- package/templates/vue-axios-router-props/src/components/DataCard.vue +72 -53
- package/templates/vue-axios-router-props/src/views/DepartmentPage.vue +89 -77
- package/templates/vue-axios-router-props/src/views/EmployeePage.vue +128 -116
- package/templates/vue-fetch/src/App.vue +285 -259
- package/templates/vue-router-pinia-springboot/backend/src/main/java/com/example/crud/controller/ItemController.java +45 -41
- package/templates/vue-router-pinia-springboot/backend/src/main/java/com/example/crud/service/ItemService.java +45 -35
- package/templates/vue-router-pinia-springboot/frontend/src/services/ItemService.js +24 -21
- package/templates/vue-router-pinia-springboot/frontend/src/stores/itemStore.js +42 -37
- package/templates/vue-router-pinia-springboot/frontend/src/views/ListView.vue +76 -67
- package/templates/vue-springboot-mongo-aggregation/backend/src/main/java/com/example/aggregation/controller/ItemController.java +45 -41
- package/templates/vue-springboot-mongo-aggregation/backend/src/main/java/com/example/aggregation/service/ItemService.java +45 -35
- package/templates/vue-springboot-mongo-crud/backend/src/main/java/com/example/crud/controller/ItemController.java +45 -41
- package/templates/vue-springboot-mongo-crud/backend/src/main/java/com/example/crud/service/ItemService.java +45 -35
- package/templates/vue-springboot-mongo-crud/frontend/src/App.vue +158 -149
- package/templates/vue-springboot-mongo-crud/frontend/src/services/ItemService.js +24 -21
|
@@ -1,51 +1,57 @@
|
|
|
1
|
-
package com.example.library.controller;
|
|
2
|
-
|
|
3
|
-
import com.example.library.model.Book;
|
|
4
|
-
import com.example.library.model.CategoryAnalytics;
|
|
5
|
-
import com.example.library.service.LibraryService;
|
|
6
|
-
import org.springframework.http.HttpStatus;
|
|
7
|
-
import org.springframework.http.ResponseEntity;
|
|
8
|
-
import org.springframework.web.bind.annotation.*;
|
|
9
|
-
|
|
10
|
-
import java.util.List;
|
|
11
|
-
|
|
12
|
-
@RestController
|
|
13
|
-
@RequestMapping("/api/books")
|
|
14
|
-
@CrossOrigin
|
|
15
|
-
public class LibraryController {
|
|
16
|
-
|
|
17
|
-
private final LibraryService libraryService;
|
|
18
|
-
|
|
19
|
-
public LibraryController(LibraryService libraryService) {
|
|
20
|
-
this.libraryService = libraryService;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
@GetMapping
|
|
24
|
-
public ResponseEntity<List<Book>> getAllBooks() {
|
|
25
|
-
return ResponseEntity.ok(libraryService.getAllBooks());
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
@GetMapping("/{id}")
|
|
29
|
-
public ResponseEntity<Book> getBookById(@PathVariable String id) {
|
|
30
|
-
return libraryService.getBookById(id)
|
|
31
|
-
.map(ResponseEntity::ok)
|
|
32
|
-
.orElse(ResponseEntity.notFound().build());
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
@PostMapping
|
|
36
|
-
public ResponseEntity<Book> addBook(@RequestBody Book book) {
|
|
37
|
-
Book savedBook = libraryService.addBook(book);
|
|
38
|
-
return new ResponseEntity<>(savedBook, HttpStatus.CREATED);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
@DeleteMapping("/{id}")
|
|
42
|
-
public ResponseEntity<Void> deleteBook(@PathVariable String id) {
|
|
43
|
-
libraryService.deleteBook(id);
|
|
44
|
-
return ResponseEntity.noContent().build();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
@GetMapping("/analytics")
|
|
48
|
-
public ResponseEntity<List<CategoryAnalytics>> getCategoryAnalytics() {
|
|
49
|
-
return ResponseEntity.ok(libraryService.getCategoryAnalytics());
|
|
50
|
-
}
|
|
51
|
-
}
|
|
1
|
+
package com.example.library.controller;
|
|
2
|
+
|
|
3
|
+
import com.example.library.model.Book;
|
|
4
|
+
import com.example.library.model.CategoryAnalytics;
|
|
5
|
+
import com.example.library.service.LibraryService;
|
|
6
|
+
import org.springframework.http.HttpStatus;
|
|
7
|
+
import org.springframework.http.ResponseEntity;
|
|
8
|
+
import org.springframework.web.bind.annotation.*;
|
|
9
|
+
|
|
10
|
+
import java.util.List;
|
|
11
|
+
|
|
12
|
+
@RestController
|
|
13
|
+
@RequestMapping("/api/books")
|
|
14
|
+
@CrossOrigin
|
|
15
|
+
public class LibraryController {
|
|
16
|
+
|
|
17
|
+
private final LibraryService libraryService;
|
|
18
|
+
|
|
19
|
+
public LibraryController(LibraryService libraryService) {
|
|
20
|
+
this.libraryService = libraryService;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@GetMapping
|
|
24
|
+
public ResponseEntity<List<Book>> getAllBooks() {
|
|
25
|
+
return ResponseEntity.ok(libraryService.getAllBooks());
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@GetMapping("/{id}")
|
|
29
|
+
public ResponseEntity<Book> getBookById(@PathVariable String id) {
|
|
30
|
+
return libraryService.getBookById(id)
|
|
31
|
+
.map(ResponseEntity::ok)
|
|
32
|
+
.orElse(ResponseEntity.notFound().build());
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@PostMapping
|
|
36
|
+
public ResponseEntity<Book> addBook(@RequestBody Book book) {
|
|
37
|
+
Book savedBook = libraryService.addBook(book);
|
|
38
|
+
return new ResponseEntity<>(savedBook, HttpStatus.CREATED);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@DeleteMapping("/{id}")
|
|
42
|
+
public ResponseEntity<Void> deleteBook(@PathVariable String id) {
|
|
43
|
+
libraryService.deleteBook(id);
|
|
44
|
+
return ResponseEntity.noContent().build();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@GetMapping("/analytics")
|
|
48
|
+
public ResponseEntity<List<CategoryAnalytics>> getCategoryAnalytics() {
|
|
49
|
+
return ResponseEntity.ok(libraryService.getCategoryAnalytics());
|
|
50
|
+
}
|
|
51
|
+
@PatchMapping("/{id}")
|
|
52
|
+
public ResponseEntity<Book> patchBook(@PathVariable String id, @RequestBody Book patch) {
|
|
53
|
+
return libraryService.patchBook(id, patch)
|
|
54
|
+
.map(ResponseEntity::ok)
|
|
55
|
+
.orElse(ResponseEntity.notFound().build());
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -1,60 +1,70 @@
|
|
|
1
|
-
package com.example.library.service;
|
|
2
|
-
|
|
3
|
-
import com.example.library.model.Book;
|
|
4
|
-
import com.example.library.model.CategoryAnalytics;
|
|
5
|
-
import com.example.library.repository.BookRepository;
|
|
6
|
-
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
7
|
-
import org.springframework.data.mongodb.core.aggregation.Aggregation;
|
|
8
|
-
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
|
|
9
|
-
import org.springframework.stereotype.Service;
|
|
10
|
-
|
|
11
|
-
import java.util.List;
|
|
12
|
-
import java.util.Optional;
|
|
13
|
-
|
|
14
|
-
import static org.springframework.data.mongodb.core.aggregation.Aggregation.*;
|
|
15
|
-
|
|
16
|
-
@Service
|
|
17
|
-
public class LibraryService {
|
|
18
|
-
|
|
19
|
-
private final BookRepository bookRepository;
|
|
20
|
-
private final MongoTemplate mongoTemplate;
|
|
21
|
-
|
|
22
|
-
public LibraryService(BookRepository bookRepository, MongoTemplate mongoTemplate) {
|
|
23
|
-
this.bookRepository = bookRepository;
|
|
24
|
-
this.mongoTemplate = mongoTemplate;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public List<Book> getAllBooks() {
|
|
28
|
-
return bookRepository.findAll();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public Optional<Book> getBookById(String id) {
|
|
32
|
-
return bookRepository.findById(id);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public Book addBook(Book book) {
|
|
36
|
-
return bookRepository.save(book);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public void deleteBook(String id) {
|
|
40
|
-
bookRepository.deleteById(id);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public List<CategoryAnalytics> getCategoryAnalytics() {
|
|
44
|
-
Aggregation aggregation = newAggregation(
|
|
45
|
-
group("category")
|
|
46
|
-
.sum("totalCopies").as("totalCopies")
|
|
47
|
-
.avg("price").as("averagePrice"),
|
|
48
|
-
project("totalCopies", "averagePrice")
|
|
49
|
-
.and("_id").as("category")
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
AggregationResults<CategoryAnalytics> results = mongoTemplate.aggregate(
|
|
53
|
-
aggregation,
|
|
54
|
-
"books",
|
|
55
|
-
CategoryAnalytics.class
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
return results.getMappedResults();
|
|
59
|
-
}
|
|
60
|
-
|
|
1
|
+
package com.example.library.service;
|
|
2
|
+
|
|
3
|
+
import com.example.library.model.Book;
|
|
4
|
+
import com.example.library.model.CategoryAnalytics;
|
|
5
|
+
import com.example.library.repository.BookRepository;
|
|
6
|
+
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
7
|
+
import org.springframework.data.mongodb.core.aggregation.Aggregation;
|
|
8
|
+
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
|
|
9
|
+
import org.springframework.stereotype.Service;
|
|
10
|
+
|
|
11
|
+
import java.util.List;
|
|
12
|
+
import java.util.Optional;
|
|
13
|
+
|
|
14
|
+
import static org.springframework.data.mongodb.core.aggregation.Aggregation.*;
|
|
15
|
+
|
|
16
|
+
@Service
|
|
17
|
+
public class LibraryService {
|
|
18
|
+
|
|
19
|
+
private final BookRepository bookRepository;
|
|
20
|
+
private final MongoTemplate mongoTemplate;
|
|
21
|
+
|
|
22
|
+
public LibraryService(BookRepository bookRepository, MongoTemplate mongoTemplate) {
|
|
23
|
+
this.bookRepository = bookRepository;
|
|
24
|
+
this.mongoTemplate = mongoTemplate;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public List<Book> getAllBooks() {
|
|
28
|
+
return bookRepository.findAll();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public Optional<Book> getBookById(String id) {
|
|
32
|
+
return bookRepository.findById(id);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public Book addBook(Book book) {
|
|
36
|
+
return bookRepository.save(book);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public void deleteBook(String id) {
|
|
40
|
+
bookRepository.deleteById(id);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public List<CategoryAnalytics> getCategoryAnalytics() {
|
|
44
|
+
Aggregation aggregation = newAggregation(
|
|
45
|
+
group("category")
|
|
46
|
+
.sum("totalCopies").as("totalCopies")
|
|
47
|
+
.avg("price").as("averagePrice"),
|
|
48
|
+
project("totalCopies", "averagePrice")
|
|
49
|
+
.and("_id").as("category")
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
AggregationResults<CategoryAnalytics> results = mongoTemplate.aggregate(
|
|
53
|
+
aggregation,
|
|
54
|
+
"books",
|
|
55
|
+
CategoryAnalytics.class
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
return results.getMappedResults();
|
|
59
|
+
}
|
|
60
|
+
public java.util.Optional<Book> patchBook(String id, Book patch) {
|
|
61
|
+
return bookRepository.findById(id).map(existing -> {
|
|
62
|
+
if (patch.getTitle() != null) existing.setTitle(patch.getTitle());
|
|
63
|
+
if (patch.getAuthor() != null) existing.setAuthor(patch.getAuthor());
|
|
64
|
+
if (patch.getCategory() != null) existing.setCategory(patch.getCategory());
|
|
65
|
+
if (patch.getPrice() != 0) existing.setPrice(patch.getPrice());
|
|
66
|
+
if (patch.getTotalCopies() > 0) existing.setTotalCopies(patch.getTotalCopies());
|
|
67
|
+
return bookRepository.save(existing);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -1,41 +1,45 @@
|
|
|
1
|
-
package com.example.mockmvc.controller;
|
|
2
|
-
|
|
3
|
-
import com.example.mockmvc.model.Item;
|
|
4
|
-
import com.example.mockmvc.service.ItemService;
|
|
5
|
-
import org.springframework.beans.factory.annotation.Autowired;
|
|
6
|
-
import org.springframework.web.bind.annotation.*;
|
|
7
|
-
|
|
8
|
-
import java.util.List;
|
|
9
|
-
|
|
10
|
-
@RestController
|
|
11
|
-
@RequestMapping("/api/items")
|
|
12
|
-
@CrossOrigin(origins = "*")
|
|
13
|
-
public class ItemController {
|
|
14
|
-
@Autowired
|
|
15
|
-
private ItemService service;
|
|
16
|
-
|
|
17
|
-
@GetMapping
|
|
18
|
-
public List<Item> getAll() {
|
|
19
|
-
return service.getAll();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
@GetMapping("/{id}")
|
|
23
|
-
public Item getOne(@PathVariable String id) {
|
|
24
|
-
return service.getOne(id);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
@PostMapping
|
|
28
|
-
public Item create(@RequestBody Item item) {
|
|
29
|
-
return service.create(item);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
@PutMapping("/{id}")
|
|
33
|
-
public Item update(@PathVariable String id, @RequestBody Item item) {
|
|
34
|
-
return service.update(id, item);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
@DeleteMapping("/{id}")
|
|
38
|
-
public void delete(@PathVariable String id) {
|
|
39
|
-
service.delete(id);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
1
|
+
package com.example.mockmvc.controller;
|
|
2
|
+
|
|
3
|
+
import com.example.mockmvc.model.Item;
|
|
4
|
+
import com.example.mockmvc.service.ItemService;
|
|
5
|
+
import org.springframework.beans.factory.annotation.Autowired;
|
|
6
|
+
import org.springframework.web.bind.annotation.*;
|
|
7
|
+
|
|
8
|
+
import java.util.List;
|
|
9
|
+
|
|
10
|
+
@RestController
|
|
11
|
+
@RequestMapping("/api/items")
|
|
12
|
+
@CrossOrigin(origins = "*")
|
|
13
|
+
public class ItemController {
|
|
14
|
+
@Autowired
|
|
15
|
+
private ItemService service;
|
|
16
|
+
|
|
17
|
+
@GetMapping
|
|
18
|
+
public List<Item> getAll() {
|
|
19
|
+
return service.getAll();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@GetMapping("/{id}")
|
|
23
|
+
public Item getOne(@PathVariable String id) {
|
|
24
|
+
return service.getOne(id);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@PostMapping
|
|
28
|
+
public Item create(@RequestBody Item item) {
|
|
29
|
+
return service.create(item);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@PutMapping("/{id}")
|
|
33
|
+
public Item update(@PathVariable String id, @RequestBody Item item) {
|
|
34
|
+
return service.update(id, item);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@DeleteMapping("/{id}")
|
|
38
|
+
public void delete(@PathVariable String id) {
|
|
39
|
+
service.delete(id);
|
|
40
|
+
}
|
|
41
|
+
@PatchMapping("/{id}")
|
|
42
|
+
public Item patch(@PathVariable String id, @RequestBody Item item) {
|
|
43
|
+
return service.patch(id, item);
|
|
44
|
+
}
|
|
45
|
+
}
|
package/templates/springboot-mockmvc/src/main/java/com/example/mockmvc/service/ItemService.java
CHANGED
|
@@ -1,38 +1,48 @@
|
|
|
1
|
-
package com.example.mockmvc.service;
|
|
2
|
-
|
|
3
|
-
import com.example.mockmvc.model.Item;
|
|
4
|
-
import com.example.mockmvc.repository.ItemRepository;
|
|
5
|
-
import org.springframework.beans.factory.annotation.Autowired;
|
|
6
|
-
import org.springframework.stereotype.Service;
|
|
7
|
-
|
|
8
|
-
import java.util.List;
|
|
9
|
-
|
|
10
|
-
@Service
|
|
11
|
-
public class ItemService {
|
|
12
|
-
@Autowired
|
|
13
|
-
private ItemRepository repo;
|
|
14
|
-
|
|
15
|
-
public List<Item> getAll() {
|
|
16
|
-
return repo.findAll();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public Item getOne(String id) {
|
|
20
|
-
return repo.findById(id).orElse(null);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public Item create(Item item) {
|
|
24
|
-
if (item.getId() != null && item.getId().trim().isEmpty()) {
|
|
25
|
-
item.setId(null);
|
|
26
|
-
}
|
|
27
|
-
return repo.save(item);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public Item update(String id, Item item) {
|
|
31
|
-
item.setId(id);
|
|
32
|
-
return repo.save(item);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public void delete(String id) {
|
|
36
|
-
repo.deleteById(id);
|
|
37
|
-
}
|
|
38
|
-
|
|
1
|
+
package com.example.mockmvc.service;
|
|
2
|
+
|
|
3
|
+
import com.example.mockmvc.model.Item;
|
|
4
|
+
import com.example.mockmvc.repository.ItemRepository;
|
|
5
|
+
import org.springframework.beans.factory.annotation.Autowired;
|
|
6
|
+
import org.springframework.stereotype.Service;
|
|
7
|
+
|
|
8
|
+
import java.util.List;
|
|
9
|
+
|
|
10
|
+
@Service
|
|
11
|
+
public class ItemService {
|
|
12
|
+
@Autowired
|
|
13
|
+
private ItemRepository repo;
|
|
14
|
+
|
|
15
|
+
public List<Item> getAll() {
|
|
16
|
+
return repo.findAll();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public Item getOne(String id) {
|
|
20
|
+
return repo.findById(id).orElse(null);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public Item create(Item item) {
|
|
24
|
+
if (item.getId() != null && item.getId().trim().isEmpty()) {
|
|
25
|
+
item.setId(null);
|
|
26
|
+
}
|
|
27
|
+
return repo.save(item);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public Item update(String id, Item item) {
|
|
31
|
+
item.setId(id);
|
|
32
|
+
return repo.save(item);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public void delete(String id) {
|
|
36
|
+
repo.deleteById(id);
|
|
37
|
+
}
|
|
38
|
+
public Item patch(String id, Item partial) {
|
|
39
|
+
Item existing = getOne(id);
|
|
40
|
+
if (existing != null) {
|
|
41
|
+
if (partial.getName() != null) existing.setName(partial.getName());
|
|
42
|
+
if (partial.getDescription() != null) existing.setDescription(partial.getDescription());
|
|
43
|
+
if (partial.getPrice() != 0) existing.setPrice(partial.getPrice());
|
|
44
|
+
return repo.save(existing);
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -1,41 +1,45 @@
|
|
|
1
|
-
package com.example.aggregation.controller;
|
|
2
|
-
|
|
3
|
-
import com.example.aggregation.model.Item;
|
|
4
|
-
import com.example.aggregation.service.ItemService;
|
|
5
|
-
import org.springframework.beans.factory.annotation.Autowired;
|
|
6
|
-
import org.springframework.web.bind.annotation.*;
|
|
7
|
-
|
|
8
|
-
import java.util.List;
|
|
9
|
-
|
|
10
|
-
@RestController
|
|
11
|
-
@RequestMapping("/api/items")
|
|
12
|
-
@CrossOrigin(origins = "*")
|
|
13
|
-
public class ItemController {
|
|
14
|
-
@Autowired
|
|
15
|
-
private ItemService service;
|
|
16
|
-
|
|
17
|
-
@GetMapping
|
|
18
|
-
public List<Item> getAll() {
|
|
19
|
-
return service.getAll();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
@GetMapping("/{id}")
|
|
23
|
-
public Item getOne(@PathVariable String id) {
|
|
24
|
-
return service.getOne(id);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
@PostMapping
|
|
28
|
-
public Item create(@RequestBody Item item) {
|
|
29
|
-
return service.create(item);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
@PutMapping("/{id}")
|
|
33
|
-
public Item update(@PathVariable String id, @RequestBody Item item) {
|
|
34
|
-
return service.update(id, item);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
@DeleteMapping("/{id}")
|
|
38
|
-
public void delete(@PathVariable String id) {
|
|
39
|
-
service.delete(id);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
1
|
+
package com.example.aggregation.controller;
|
|
2
|
+
|
|
3
|
+
import com.example.aggregation.model.Item;
|
|
4
|
+
import com.example.aggregation.service.ItemService;
|
|
5
|
+
import org.springframework.beans.factory.annotation.Autowired;
|
|
6
|
+
import org.springframework.web.bind.annotation.*;
|
|
7
|
+
|
|
8
|
+
import java.util.List;
|
|
9
|
+
|
|
10
|
+
@RestController
|
|
11
|
+
@RequestMapping("/api/items")
|
|
12
|
+
@CrossOrigin(origins = "*")
|
|
13
|
+
public class ItemController {
|
|
14
|
+
@Autowired
|
|
15
|
+
private ItemService service;
|
|
16
|
+
|
|
17
|
+
@GetMapping
|
|
18
|
+
public List<Item> getAll() {
|
|
19
|
+
return service.getAll();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@GetMapping("/{id}")
|
|
23
|
+
public Item getOne(@PathVariable String id) {
|
|
24
|
+
return service.getOne(id);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@PostMapping
|
|
28
|
+
public Item create(@RequestBody Item item) {
|
|
29
|
+
return service.create(item);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@PutMapping("/{id}")
|
|
33
|
+
public Item update(@PathVariable String id, @RequestBody Item item) {
|
|
34
|
+
return service.update(id, item);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@DeleteMapping("/{id}")
|
|
38
|
+
public void delete(@PathVariable String id) {
|
|
39
|
+
service.delete(id);
|
|
40
|
+
}
|
|
41
|
+
@PatchMapping("/{id}")
|
|
42
|
+
public Item patch(@PathVariable String id, @RequestBody Item item) {
|
|
43
|
+
return service.patch(id, item);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -1,38 +1,48 @@
|
|
|
1
|
-
package com.example.aggregation.service;
|
|
2
|
-
|
|
3
|
-
import com.example.aggregation.model.Item;
|
|
4
|
-
import com.example.aggregation.repository.ItemRepository;
|
|
5
|
-
import org.springframework.beans.factory.annotation.Autowired;
|
|
6
|
-
import org.springframework.stereotype.Service;
|
|
7
|
-
|
|
8
|
-
import java.util.List;
|
|
9
|
-
|
|
10
|
-
@Service
|
|
11
|
-
public class ItemService {
|
|
12
|
-
@Autowired
|
|
13
|
-
private ItemRepository repo;
|
|
14
|
-
|
|
15
|
-
public List<Item> getAll() {
|
|
16
|
-
return repo.findAll();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
public Item getOne(String id) {
|
|
20
|
-
return repo.findById(id).orElse(null);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
public Item create(Item item) {
|
|
24
|
-
if (item.getId() != null && item.getId().trim().isEmpty()) {
|
|
25
|
-
item.setId(null);
|
|
26
|
-
}
|
|
27
|
-
return repo.save(item);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public Item update(String id, Item item) {
|
|
31
|
-
item.setId(id);
|
|
32
|
-
return repo.save(item);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public void delete(String id) {
|
|
36
|
-
repo.deleteById(id);
|
|
37
|
-
}
|
|
38
|
-
|
|
1
|
+
package com.example.aggregation.service;
|
|
2
|
+
|
|
3
|
+
import com.example.aggregation.model.Item;
|
|
4
|
+
import com.example.aggregation.repository.ItemRepository;
|
|
5
|
+
import org.springframework.beans.factory.annotation.Autowired;
|
|
6
|
+
import org.springframework.stereotype.Service;
|
|
7
|
+
|
|
8
|
+
import java.util.List;
|
|
9
|
+
|
|
10
|
+
@Service
|
|
11
|
+
public class ItemService {
|
|
12
|
+
@Autowired
|
|
13
|
+
private ItemRepository repo;
|
|
14
|
+
|
|
15
|
+
public List<Item> getAll() {
|
|
16
|
+
return repo.findAll();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public Item getOne(String id) {
|
|
20
|
+
return repo.findById(id).orElse(null);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public Item create(Item item) {
|
|
24
|
+
if (item.getId() != null && item.getId().trim().isEmpty()) {
|
|
25
|
+
item.setId(null);
|
|
26
|
+
}
|
|
27
|
+
return repo.save(item);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public Item update(String id, Item item) {
|
|
31
|
+
item.setId(id);
|
|
32
|
+
return repo.save(item);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public void delete(String id) {
|
|
36
|
+
repo.deleteById(id);
|
|
37
|
+
}
|
|
38
|
+
public Item patch(String id, Item partial) {
|
|
39
|
+
Item existing = getOne(id);
|
|
40
|
+
if (existing != null) {
|
|
41
|
+
if (partial.getName() != null) existing.setName(partial.getName());
|
|
42
|
+
if (partial.getDescription() != null) existing.setDescription(partial.getDescription());
|
|
43
|
+
if (partial.getPrice() != 0) existing.setPrice(partial.getPrice());
|
|
44
|
+
return repo.save(existing);
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -1,41 +1,45 @@
|
|
|
1
|
-
package com.example.aggmockmvc.controller;
|
|
2
|
-
|
|
3
|
-
import com.example.aggmockmvc.model.Item;
|
|
4
|
-
import com.example.aggmockmvc.service.ItemService;
|
|
5
|
-
import org.springframework.beans.factory.annotation.Autowired;
|
|
6
|
-
import org.springframework.web.bind.annotation.*;
|
|
7
|
-
|
|
8
|
-
import java.util.List;
|
|
9
|
-
|
|
10
|
-
@RestController
|
|
11
|
-
@RequestMapping("/api/items")
|
|
12
|
-
@CrossOrigin(origins = "*")
|
|
13
|
-
public class ItemController {
|
|
14
|
-
@Autowired
|
|
15
|
-
private ItemService service;
|
|
16
|
-
|
|
17
|
-
@GetMapping
|
|
18
|
-
public List<Item> getAll() {
|
|
19
|
-
return service.getAll();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
@GetMapping("/{id}")
|
|
23
|
-
public Item getOne(@PathVariable String id) {
|
|
24
|
-
return service.getOne(id);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
@PostMapping
|
|
28
|
-
public Item create(@RequestBody Item item) {
|
|
29
|
-
return service.create(item);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
@PutMapping("/{id}")
|
|
33
|
-
public Item update(@PathVariable String id, @RequestBody Item item) {
|
|
34
|
-
return service.update(id, item);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
@DeleteMapping("/{id}")
|
|
38
|
-
public void delete(@PathVariable String id) {
|
|
39
|
-
service.delete(id);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
1
|
+
package com.example.aggmockmvc.controller;
|
|
2
|
+
|
|
3
|
+
import com.example.aggmockmvc.model.Item;
|
|
4
|
+
import com.example.aggmockmvc.service.ItemService;
|
|
5
|
+
import org.springframework.beans.factory.annotation.Autowired;
|
|
6
|
+
import org.springframework.web.bind.annotation.*;
|
|
7
|
+
|
|
8
|
+
import java.util.List;
|
|
9
|
+
|
|
10
|
+
@RestController
|
|
11
|
+
@RequestMapping("/api/items")
|
|
12
|
+
@CrossOrigin(origins = "*")
|
|
13
|
+
public class ItemController {
|
|
14
|
+
@Autowired
|
|
15
|
+
private ItemService service;
|
|
16
|
+
|
|
17
|
+
@GetMapping
|
|
18
|
+
public List<Item> getAll() {
|
|
19
|
+
return service.getAll();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@GetMapping("/{id}")
|
|
23
|
+
public Item getOne(@PathVariable String id) {
|
|
24
|
+
return service.getOne(id);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@PostMapping
|
|
28
|
+
public Item create(@RequestBody Item item) {
|
|
29
|
+
return service.create(item);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@PutMapping("/{id}")
|
|
33
|
+
public Item update(@PathVariable String id, @RequestBody Item item) {
|
|
34
|
+
return service.update(id, item);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@DeleteMapping("/{id}")
|
|
38
|
+
public void delete(@PathVariable String id) {
|
|
39
|
+
service.delete(id);
|
|
40
|
+
}
|
|
41
|
+
@PatchMapping("/{id}")
|
|
42
|
+
public Item patch(@PathVariable String id, @RequestBody Item item) {
|
|
43
|
+
return service.patch(id, item);
|
|
44
|
+
}
|
|
45
|
+
}
|