changed base path of REST api and updated frontend api quering
This commit is contained in:
@@ -1,17 +1,19 @@
|
|||||||
package whattocook.configs;
|
package whattocook.configs;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
|
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
|
||||||
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer;
|
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurer;
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||||
@Component
|
import whattocook.models.Item;
|
||||||
public class RestRepositoryConfigurator implements RepositoryRestConfigurer {
|
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
class RepositoryConfig implements RepositoryRestConfigurer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config, CorsRegistry cors) {
|
public void configureRepositoryRestConfiguration(RepositoryRestConfiguration config, CorsRegistry cors) {
|
||||||
config.disableDefaultExposure();
|
config.exposeIdsFor(Item.class);
|
||||||
RepositoryRestConfigurer.super.configureRepositoryRestConfiguration(config, cors);
|
config.setBasePath("/api/v1");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5,14 +5,11 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import whattocook.models.Item;
|
import whattocook.models.Item;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import whattocook.models.Unit;
|
|
||||||
import whattocook.services.ItemService;
|
import whattocook.services.ItemService;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController()
|
@RestController()
|
||||||
@RequestMapping("/api/v1")
|
|
||||||
public class ItemController {
|
public class ItemController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|||||||
@@ -10,7 +10,11 @@ const instance = axios.create({
|
|||||||
export default {
|
export default {
|
||||||
createNew: (name, quantity, unit) => instance.post("/api/v1/items", {name: name, quantity : quantity, unit : unit}),
|
createNew: (name, quantity, unit) => instance.post("/api/v1/items", {name: name, quantity : quantity, unit : unit}),
|
||||||
|
|
||||||
getAll: () => instance.get('/api/v1/items'),
|
getAll: () => instance.get('/api/v1/items', {
|
||||||
|
transformResponse: [function (data) {
|
||||||
|
return data? JSON.parse(data)._embedded.items : data;
|
||||||
|
}]
|
||||||
|
}),
|
||||||
|
|
||||||
removeForId: (id) => instance.delete('/api/v1/items/'+ id)
|
removeForId: (id) => instance.delete('/api/v1/items/'+ id)
|
||||||
}
|
}
|
||||||
@@ -84,14 +84,14 @@
|
|||||||
|
|
||||||
api.createNew(components[0],
|
api.createNew(components[0],
|
||||||
parseInt(components[1].replace ( /[^\d.]/g, '' )),
|
parseInt(components[1].replace ( /[^\d.]/g, '' )),
|
||||||
components[1].replace(/[0-9]/g, ''))
|
components[1].replace(/[0-9]/g, '') === 'ml' ? 'MILLILETERS' : "GRAMMS"
|
||||||
.then( (response) => {
|
).then( (response) => {
|
||||||
this.$log.debug("New item created:", response);
|
this.$log.debug("New item created:", response);
|
||||||
this.items.push({
|
this.items.push({
|
||||||
id: response.data.id,
|
id: response.data.id,
|
||||||
name: components[0],
|
name: components[0],
|
||||||
quantity: parseInt(components[1].replace ( /[^\d.]/g, '' )),
|
quantity: parseInt(components[1].replace ( /[^\d.]/g, '' )),
|
||||||
unit: components[1].replace(/[0-9]/g, '')
|
unit: components[1].replace(/[0-9]/g, '') === 'MILLILETERS' ? 'ml' : 'g'
|
||||||
})
|
})
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
this.$log.debug(error);
|
this.$log.debug(error);
|
||||||
|
|||||||
Reference in New Issue
Block a user