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.
Files changed (93) hide show
  1. package/package.json +1 -1
  2. package/templates/fullstack-springboot-vue/backend/src/main/java/com/example/company/controller/CompanyController.java +88 -74
  3. package/templates/fullstack-springboot-vue/backend/src/main/java/com/example/company/model/Employee.java +73 -73
  4. package/templates/fullstack-springboot-vue/backend/src/main/java/com/example/company/service/CompanyService.java +90 -60
  5. package/templates/fullstack-springboot-vue/frontend/vue-axios-basic/src/App.vue +429 -405
  6. package/templates/fullstack-springboot-vue/frontend/vue-axios-interceptor/src/App.vue +177 -159
  7. package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia/src/App.vue +441 -427
  8. package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia/src/stores/companyStore.js +126 -96
  9. package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/App.vue +84 -69
  10. package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/components/DepartmentSection.vue +164 -152
  11. package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/components/EmployeeSection.vue +193 -181
  12. package/templates/fullstack-springboot-vue/frontend/vue-axios-pinia-props/src/stores/companyStore.js +126 -35
  13. package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/App.vue +191 -167
  14. package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/DepartmentForm.vue +98 -98
  15. package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/DepartmentList.vue +92 -91
  16. package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/EmployeeForm.vue +128 -128
  17. package/templates/fullstack-springboot-vue/frontend/vue-axios-props-emits/src/components/EmployeeList.vue +95 -94
  18. package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/App.vue +90 -90
  19. package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/AddEmployeeView.vue +247 -247
  20. package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/DepartmentView.vue +296 -273
  21. package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/EmployeeView.vue +219 -196
  22. package/templates/fullstack-springboot-vue/frontend/vue-axios-router/src/views/HomeDashboardView.vue +263 -263
  23. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-children/src/views/DepartmentListView.vue +250 -231
  24. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-children/src/views/EmployeeDetailView.vue +181 -159
  25. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-children/src/views/EmployeeListView.vue +315 -295
  26. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia/src/stores/companyStore.js +137 -70
  27. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia/src/views/DepartmentView.vue +229 -209
  28. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia/src/views/EmployeeView.vue +257 -237
  29. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/components/EntityTable.vue +106 -92
  30. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/stores/companyStore.js +139 -84
  31. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/views/ManageDepartmentsView.vue +73 -64
  32. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-pinia-props/src/views/ManageEmployeesView.vue +76 -67
  33. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/App.vue +59 -59
  34. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/components/DataCard.vue +72 -53
  35. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/views/DepartmentPage.vue +89 -77
  36. package/templates/fullstack-springboot-vue/frontend/vue-axios-router-props/src/views/EmployeePage.vue +128 -116
  37. package/templates/springboot-2model-1controller-api/src/main/java/com/example/company/controller/CompanyController.java +88 -74
  38. package/templates/springboot-2model-1controller-api/src/main/java/com/example/company/model/Employee.java +73 -73
  39. package/templates/springboot-2model-1controller-api/src/main/java/com/example/company/service/CompanyService.java +90 -60
  40. package/templates/springboot-course-registration/src/main/java/com/example/coursereg/controller/CourseController.java +46 -42
  41. package/templates/springboot-course-registration/src/main/java/com/example/coursereg/service/CourseService.java +70 -60
  42. package/templates/springboot-hospital-api/src/main/java/com/example/hospital/controller/HospitalController.java +54 -50
  43. package/templates/springboot-hospital-api/src/main/java/com/example/hospital/service/HospitalService.java +65 -54
  44. package/templates/springboot-library-api/src/main/java/com/example/library/controller/LibraryController.java +57 -51
  45. package/templates/springboot-library-api/src/main/java/com/example/library/service/LibraryService.java +70 -60
  46. package/templates/springboot-mockmvc/src/main/java/com/example/mockmvc/controller/ItemController.java +45 -41
  47. package/templates/springboot-mockmvc/src/main/java/com/example/mockmvc/service/ItemService.java +48 -38
  48. package/templates/springboot-mongo-aggregation/src/main/java/com/example/aggregation/controller/ItemController.java +45 -41
  49. package/templates/springboot-mongo-aggregation/src/main/java/com/example/aggregation/service/ItemService.java +48 -38
  50. package/templates/springboot-mongo-aggregation-mockmvc/src/main/java/com/example/aggmockmvc/controller/ItemController.java +45 -41
  51. package/templates/springboot-mongo-aggregation-mockmvc/src/main/java/com/example/aggmockmvc/service/ItemService.java +48 -38
  52. package/templates/springboot-mongo-crud/src/main/java/com/example/crud/controller/ItemController.java +45 -41
  53. package/templates/springboot-mongo-crud/src/main/java/com/example/crud/service/ItemService.java +48 -38
  54. package/templates/vue-axios/src/App.vue +264 -243
  55. package/templates/vue-axios/src/services/ItemService.js +27 -21
  56. package/templates/vue-axios-basic/src/App.vue +24 -0
  57. package/templates/vue-axios-interceptor/src/App.vue +177 -159
  58. package/templates/vue-axios-pinia/src/App.vue +14 -0
  59. package/templates/vue-axios-pinia/src/stores/companyStore.js +126 -96
  60. package/templates/vue-axios-pinia-props/src/App.vue +84 -69
  61. package/templates/vue-axios-pinia-props/src/components/DepartmentSection.vue +164 -152
  62. package/templates/vue-axios-pinia-props/src/components/EmployeeSection.vue +193 -181
  63. package/templates/vue-axios-pinia-props/src/stores/companyStore.js +126 -35
  64. package/templates/vue-axios-props-emits/src/App.vue +24 -0
  65. package/templates/vue-axios-props-emits/src/components/DepartmentList.vue +2 -1
  66. package/templates/vue-axios-props-emits/src/components/EmployeeList.vue +2 -1
  67. package/templates/vue-axios-router/src/views/DepartmentView.vue +23 -0
  68. package/templates/vue-axios-router/src/views/EmployeeView.vue +23 -0
  69. package/templates/vue-axios-router-children/src/views/DepartmentListView.vue +250 -231
  70. package/templates/vue-axios-router-children/src/views/EmployeeDetailView.vue +181 -159
  71. package/templates/vue-axios-router-children/src/views/EmployeeListView.vue +315 -295
  72. package/templates/vue-axios-router-pinia/src/stores/companyStore.js +137 -70
  73. package/templates/vue-axios-router-pinia/src/views/DepartmentView.vue +229 -209
  74. package/templates/vue-axios-router-pinia/src/views/EmployeeView.vue +257 -237
  75. package/templates/vue-axios-router-pinia-props/src/components/EntityTable.vue +106 -92
  76. package/templates/vue-axios-router-pinia-props/src/stores/companyStore.js +139 -84
  77. package/templates/vue-axios-router-pinia-props/src/views/ManageDepartmentsView.vue +73 -64
  78. package/templates/vue-axios-router-pinia-props/src/views/ManageEmployeesView.vue +76 -67
  79. package/templates/vue-axios-router-props/src/components/DataCard.vue +72 -53
  80. package/templates/vue-axios-router-props/src/views/DepartmentPage.vue +89 -77
  81. package/templates/vue-axios-router-props/src/views/EmployeePage.vue +128 -116
  82. package/templates/vue-fetch/src/App.vue +285 -259
  83. package/templates/vue-router-pinia-springboot/backend/src/main/java/com/example/crud/controller/ItemController.java +45 -41
  84. package/templates/vue-router-pinia-springboot/backend/src/main/java/com/example/crud/service/ItemService.java +45 -35
  85. package/templates/vue-router-pinia-springboot/frontend/src/services/ItemService.js +24 -21
  86. package/templates/vue-router-pinia-springboot/frontend/src/stores/itemStore.js +42 -37
  87. package/templates/vue-router-pinia-springboot/frontend/src/views/ListView.vue +76 -67
  88. package/templates/vue-springboot-mongo-aggregation/backend/src/main/java/com/example/aggregation/controller/ItemController.java +45 -41
  89. package/templates/vue-springboot-mongo-aggregation/backend/src/main/java/com/example/aggregation/service/ItemService.java +45 -35
  90. package/templates/vue-springboot-mongo-crud/backend/src/main/java/com/example/crud/controller/ItemController.java +45 -41
  91. package/templates/vue-springboot-mongo-crud/backend/src/main/java/com/example/crud/service/ItemService.java +45 -35
  92. package/templates/vue-springboot-mongo-crud/frontend/src/App.vue +158 -149
  93. package/templates/vue-springboot-mongo-crud/frontend/src/services/ItemService.js +24 -21
@@ -1,35 +1,45 @@
1
- package com.example.crud.service;
2
-
3
- import com.example.crud.model.Item;
4
- import com.example.crud.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 getById(String id) {
20
- return repo.findById(id).orElse(null);
21
- }
22
-
23
- public Item create(Item item) {
24
- return repo.save(item);
25
- }
26
-
27
- public Item update(String id, Item item) {
28
- item.setId(id);
29
- return repo.save(item);
30
- }
31
-
32
- public void delete(String id) {
33
- repo.deleteById(id);
34
- }
35
- }
1
+ package com.example.crud.service;
2
+
3
+ import com.example.crud.model.Item;
4
+ import com.example.crud.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 getById(String id) {
20
+ return repo.findById(id).orElse(null);
21
+ }
22
+
23
+ public Item create(Item item) {
24
+ return repo.save(item);
25
+ }
26
+
27
+ public Item update(String id, Item item) {
28
+ item.setId(id);
29
+ return repo.save(item);
30
+ }
31
+
32
+ public void delete(String id) {
33
+ repo.deleteById(id);
34
+ }
35
+ public Item patch(String id, Item partial) {
36
+ Item existing = getOne(id);
37
+ if (existing != null) {
38
+ if (partial.getName() != null) existing.setName(partial.getName());
39
+ if (partial.getDescription() != null) existing.setDescription(partial.getDescription());
40
+ if (partial.getPrice() != 0) existing.setPrice(partial.getPrice());
41
+ return repo.save(existing);
42
+ }
43
+ return null;
44
+ }
45
+ }
@@ -1,21 +1,24 @@
1
- import axios from 'axios';
2
-
3
- const API_URL = 'http://localhost:8080/api/items';
4
-
5
- export default {
6
- getAll() {
7
- return axios.get(API_URL);
8
- },
9
- getById(id) {
10
- return axios.get(`${API_URL}/${id}`);
11
- },
12
- create(data) {
13
- return axios.post(API_URL, data);
14
- },
15
- update(id, data) {
16
- return axios.put(`${API_URL}/${id}`, data);
17
- },
18
- delete(id) {
19
- return axios.delete(`${API_URL}/${id}`);
20
- }
21
- };
1
+ import axios from 'axios';
2
+
3
+ const API_URL = 'http://localhost:8080/api/items';
4
+
5
+ export default {
6
+ getAll() {
7
+ return axios.get(API_URL);
8
+ },
9
+ getById(id) {
10
+ return axios.get(`${API_URL}/${id}`);
11
+ },
12
+ create(data) {
13
+ return axios.post(API_URL, data);
14
+ },
15
+ update(id, data) {
16
+ return axios.put(`${API_URL}/${id}`, data);
17
+ },
18
+ delete(id) {
19
+ return axios.delete(`${API_URL}/${id}`);
20
+ },
21
+ patch(id, data) {
22
+ return axios.patch(`${API_URL}/${id}`, data);
23
+ }
24
+ };
@@ -1,37 +1,42 @@
1
- import { defineStore } from 'pinia';
2
- import ItemService from '../services/ItemService';
3
-
4
- export const useItemStore = defineStore('item', {
5
- state: () => ({
6
- items: [],
7
- currentItem: null
8
- }),
9
- actions: {
10
- async fetchItems() {
11
- const res = await ItemService.getAll();
12
- this.items = res.data;
13
- },
14
- async fetchItemById(id) {
15
- const res = await ItemService.getById(id);
16
- this.currentItem = res.data;
17
- return res.data;
18
- },
19
- async addItem(data) {
20
- const res = await ItemService.create(data);
21
- await this.fetchItems();
22
- return res.data;
23
- },
24
- async editItem(id, data) {
25
- const res = await ItemService.update(id, data);
26
- await this.fetchItems();
27
- return res.data;
28
- },
29
- async removeItem(id) {
30
- await ItemService.delete(id);
31
- if (this.currentItem && this.currentItem.id === id) {
32
- this.currentItem = null;
33
- }
34
- await this.fetchItems();
35
- }
36
- }
37
- });
1
+ import { defineStore } from 'pinia';
2
+ import ItemService from '../services/ItemService';
3
+
4
+ export const useItemStore = defineStore('item', {
5
+ state: () => ({
6
+ items: [],
7
+ currentItem: null
8
+ }),
9
+ actions: {
10
+ async fetchItems() {
11
+ const res = await ItemService.getAll();
12
+ this.items = res.data;
13
+ },
14
+ async fetchItemById(id) {
15
+ const res = await ItemService.getById(id);
16
+ this.currentItem = res.data;
17
+ return res.data;
18
+ },
19
+ async addItem(data) {
20
+ const res = await ItemService.create(data);
21
+ await this.fetchItems();
22
+ return res.data;
23
+ },
24
+ async editItem(id, data) {
25
+ const res = await ItemService.update(id, data);
26
+ await this.fetchItems();
27
+ return res.data;
28
+ },
29
+ async removeItem(id) {
30
+ await ItemService.delete(id);
31
+ if (this.currentItem && this.currentItem.id === id) {
32
+ this.currentItem = null;
33
+ }
34
+ await this.fetchItems();
35
+ },
36
+ async patchItem(id, data) {
37
+ const res = await ItemService.patch(id, data);
38
+ await this.fetchItems();
39
+ return res.data;
40
+ }
41
+ }
42
+ });
@@ -1,67 +1,76 @@
1
- <script setup>
2
- import { ref, onMounted } from 'vue';
3
- import { useRouter } from 'vue-router';
4
- import { useItemStore } from '../stores/itemStore';
5
-
6
- const router = useRouter();
7
- const itemStore = useItemStore();
8
- const searchId = ref('');
9
-
10
- const goToSearch = () => {
11
- if (searchId.value) {
12
- router.push(`/item/${searchId.value}`);
13
- }
14
- };
15
-
16
- const goToItem = (id) => {
17
- router.push(`/item/${id}`);
18
- };
19
-
20
- const deleteItem = async (id) => {
21
- await itemStore.removeItem(id);
22
- };
23
-
24
- onMounted(() => {
25
- itemStore.fetchItems();
26
- });
27
- </script>
28
-
29
- <template>
30
- <h2>Item List</h2>
31
-
32
- <router-link to="/add">Add New Item</router-link>
33
- <br><br>
34
-
35
- <label>Find Item by ID:</label>
36
- <br>
37
- <input v-model="searchId" placeholder="Enter Item ID" />
38
- <button type="button" @click="goToSearch">View Details</button>
39
- <br><br>
40
-
41
- <button type="button" @click="itemStore.fetchItems()">Refresh List</button>
42
- <br><br>
43
-
44
- <table>
45
- <thead>
46
- <tr>
47
- <th>ID</th>
48
- <th>Name</th>
49
- <th>Description</th>
50
- <th>Price</th>
51
- <th>Actions</th>
52
- </tr>
53
- </thead>
54
- <tbody>
55
- <tr v-for="item in itemStore.items" :key="item.id">
56
- <td>{{ item.id }}</td>
57
- <td>{{ item.name }}</td>
58
- <td>{{ item.description }}</td>
59
- <td>{{ item.price }}</td>
60
- <td>
61
- <button type="button" @click="goToItem(item.id)">View / Edit</button>
62
- <button type="button" @click="deleteItem(item.id)">Delete</button>
63
- </td>
64
- </tr>
65
- </tbody>
66
- </table>
67
- </template>
1
+ <script setup>
2
+ import { ref, onMounted } from 'vue';
3
+ import { useRouter } from 'vue-router';
4
+ import { useItemStore } from '../stores/itemStore';
5
+
6
+ const router = useRouter();
7
+ const itemStore = useItemStore();
8
+ const store = itemStore;
9
+ const searchId = ref('');
10
+
11
+ const goToSearch = () => {
12
+ if (searchId.value) {
13
+ router.push(`/item/${searchId.value}`);
14
+ }
15
+ };
16
+
17
+ const goToItem = (id) => {
18
+ router.push(`/item/${id}`);
19
+ };
20
+
21
+ const deleteItem = async (id) => {
22
+ await itemStore.removeItem(id);
23
+ };
24
+
25
+ const patchItem = async (id) => {
26
+ const newPrice = prompt('Enter new price:');
27
+ if (newPrice !== null && newPrice !== '') {
28
+ await store.patchItem(id, { price: Number(newPrice) });
29
+ }
30
+ };
31
+
32
+ onMounted(() => {
33
+ itemStore.fetchItems();
34
+ });
35
+ </script>
36
+
37
+ <template>
38
+ <h2>Item List</h2>
39
+
40
+ <router-link to="/add">Add New Item</router-link>
41
+ <br><br>
42
+
43
+ <label>Find Item by ID:</label>
44
+ <br>
45
+ <input v-model="searchId" placeholder="Enter Item ID" />
46
+ <button type="button" @click="goToSearch">View Details</button>
47
+ <br><br>
48
+
49
+ <button type="button" @click="itemStore.fetchItems()">Refresh List</button>
50
+ <br><br>
51
+
52
+ <table>
53
+ <thead>
54
+ <tr>
55
+ <th>ID</th>
56
+ <th>Name</th>
57
+ <th>Description</th>
58
+ <th>Price</th>
59
+ <th>Actions</th>
60
+ </tr>
61
+ </thead>
62
+ <tbody>
63
+ <tr v-for="item in itemStore.items" :key="item.id">
64
+ <td>{{ item.id }}</td>
65
+ <td>{{ item.name }}</td>
66
+ <td>{{ item.description }}</td>
67
+ <td>{{ item.price }}</td>
68
+ <td>
69
+ <button type="button" @click="goToItem(item.id)">View / Edit</button>
70
+ <button type="button" @click="deleteItem(item.id)">Delete</button>
71
+ <button type="button" @click="patchItem(item.id)">Patch</button>
72
+ </td>
73
+ </tr>
74
+ </tbody>
75
+ </table>
76
+ </template>
@@ -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 getById(@PathVariable String id) {
24
- return service.getById(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 getById(@PathVariable String id) {
24
+ return service.getById(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,35 +1,45 @@
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 getById(String id) {
20
- return repo.findById(id).orElse(null);
21
- }
22
-
23
- public Item create(Item item) {
24
- return repo.save(item);
25
- }
26
-
27
- public Item update(String id, Item item) {
28
- item.setId(id);
29
- return repo.save(item);
30
- }
31
-
32
- public void delete(String id) {
33
- repo.deleteById(id);
34
- }
35
- }
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 getById(String id) {
20
+ return repo.findById(id).orElse(null);
21
+ }
22
+
23
+ public Item create(Item item) {
24
+ return repo.save(item);
25
+ }
26
+
27
+ public Item update(String id, Item item) {
28
+ item.setId(id);
29
+ return repo.save(item);
30
+ }
31
+
32
+ public void delete(String id) {
33
+ repo.deleteById(id);
34
+ }
35
+ public Item patch(String id, Item partial) {
36
+ Item existing = getOne(id);
37
+ if (existing != null) {
38
+ if (partial.getName() != null) existing.setName(partial.getName());
39
+ if (partial.getDescription() != null) existing.setDescription(partial.getDescription());
40
+ if (partial.getPrice() != 0) existing.setPrice(partial.getPrice());
41
+ return repo.save(existing);
42
+ }
43
+ return null;
44
+ }
45
+ }
@@ -1,41 +1,45 @@
1
- package com.example.crud.controller;
2
-
3
- import com.example.crud.model.Item;
4
- import com.example.crud.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 getById(@PathVariable String id) {
24
- return service.getById(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.crud.controller;
2
+
3
+ import com.example.crud.model.Item;
4
+ import com.example.crud.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 getById(@PathVariable String id) {
24
+ return service.getById(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
+ }