Action CRUD implemented
This commit is contained in:
parent
06945ff10f
commit
bbbdfbada3
|
|
@ -10,4 +10,5 @@ public interface Url {
|
|||
String QUERY_URL = BASE_URL + VERSION + "/queries";
|
||||
String SETTING_URL = BASE_URL + VERSION + "/settings";
|
||||
String RESOURCE_URL = BASE_URL + VERSION + "/resources";
|
||||
String ACTION_URL = BASE_URL + VERSION + "/actions";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
package com.appsmith.server.controllers;
|
||||
|
||||
import com.appsmith.server.constants.Url;
|
||||
import com.appsmith.server.domains.Action;
|
||||
import com.appsmith.server.services.ActionService;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(Url.ACTION_URL)
|
||||
public class ActionController extends BaseController<ActionService, Action, String> {
|
||||
|
||||
public ActionController(ActionService service) {
|
||||
super(service);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package com.appsmith.server.repositories;
|
||||
|
||||
import com.appsmith.server.domains.Action;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ActionRepository extends BaseRepository<Action, String> {
|
||||
}
|
||||
|
|
@ -2,7 +2,9 @@ package com.appsmith.server.repositories;
|
|||
|
||||
import com.appsmith.server.domains.Resource;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@Repository
|
||||
public interface ResourceRepository extends BaseRepository<Resource, String>{
|
||||
public interface ResourceRepository extends BaseRepository<Resource, String> {
|
||||
Mono<Resource> findByName(String name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
package com.appsmith.server.services;
|
||||
|
||||
import com.appsmith.server.domains.Action;
|
||||
|
||||
public interface ActionService extends CrudService<Action, String> {
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package com.appsmith.server.services;
|
||||
|
||||
import com.appsmith.server.domains.Action;
|
||||
import com.appsmith.server.domains.Resource;
|
||||
import com.appsmith.server.exceptions.AppsmithException;
|
||||
import com.appsmith.server.repositories.ActionRepository;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
|
||||
import org.springframework.data.mongodb.core.convert.MongoConverter;
|
||||
import org.springframework.stereotype.Service;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Scheduler;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ActionServiceImpl extends BaseService<ActionRepository, Action, String> implements ActionService {
|
||||
|
||||
private final ActionRepository repository;
|
||||
private final ResourceService resourceService;
|
||||
|
||||
@Autowired
|
||||
public ActionServiceImpl(Scheduler scheduler, MongoConverter mongoConverter, ReactiveMongoTemplate reactiveMongoTemplate, ActionRepository repository, ResourceService resourceService) {
|
||||
super(scheduler, mongoConverter, reactiveMongoTemplate, repository);
|
||||
this.repository = repository;
|
||||
this.resourceService = resourceService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Action> create(@NotNull Action action) throws AppsmithException {
|
||||
if (action.getId() != null) {
|
||||
throw new AppsmithException("During create action, Id is not null. Can't create new action.");
|
||||
}
|
||||
|
||||
Mono<Resource> resourceMono = resourceService.findByName(action.getResource().getName());
|
||||
|
||||
return resourceMono
|
||||
.map(resource -> {
|
||||
action.setResource(resource);
|
||||
return action;
|
||||
})
|
||||
.flatMap(repository::save);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
package com.appsmith.server.services;
|
||||
|
||||
import com.appsmith.server.domains.Resource;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public interface ResourceService extends CrudService<Resource, String> {
|
||||
Mono<Resource> findByName(String name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,4 +74,9 @@ public class ResourceServiceImpl extends BaseService<ResourceRepository, Resourc
|
|||
})
|
||||
.flatMap(repository::save);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Resource> findByName(String name) {
|
||||
return repository.findByName(name);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user