Adding the LayoutController that will store the DDL for the page layouts

Also adding the getById function in the BaseController so that all CRUD APIs will automatically support that API call.
This commit is contained in:
Arpit Mohan 2019-03-30 12:22:15 +05:30
parent f8b382940d
commit cef6946859
13 changed files with 89 additions and 6 deletions

View File

@ -39,6 +39,7 @@ public class SecurityConfig {
@Bean @Bean
public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) { public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
return http return http
.csrf().disable()
.authorizeExchange() .authorizeExchange()
.anyExchange() .anyExchange()
.authenticated() .authenticated()

View File

@ -5,4 +5,5 @@ public interface Url {
String VERSION = "/v1"; String VERSION = "/v1";
String WIDGET_URL = BASE_URL + VERSION + "/widgets"; String WIDGET_URL = BASE_URL + VERSION + "/widgets";
String TENANT_URL = BASE_URL + VERSION + "/tenants"; String TENANT_URL = BASE_URL + VERSION + "/tenants";
String LAYOUT_URL = BASE_URL + VERSION + "/layouts";
} }

View File

@ -29,6 +29,12 @@ public abstract class BaseController<S extends CrudService, T extends BaseDomain
.map(resources -> new ResponseDto<>(HttpStatus.OK.value(), resources, null)); .map(resources -> new ResponseDto<>(HttpStatus.OK.value(), resources, null));
} }
@GetMapping("/{id}")
public Mono<ResponseDto<T>> getById(@PathVariable ID id) {
return service.getById(id)
.map(resources -> new ResponseDto<>(HttpStatus.OK.value(), resources, null));
}
@PutMapping("/{id}") @PutMapping("/{id}")
public Mono<ResponseDto<T>> update(@PathVariable ID id, @RequestBody T resource) throws Exception { public Mono<ResponseDto<T>> update(@PathVariable ID id, @RequestBody T resource) throws Exception {
return service.update(id, resource) return service.update(id, resource)

View File

@ -1,8 +1,6 @@
package com.mobtools.server.controllers; package com.mobtools.server.controllers;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.oauth2.core.user.OAuth2User;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;

View File

@ -0,0 +1,18 @@
package com.mobtools.server.controllers;
import com.mobtools.server.constants.Url;
import com.mobtools.server.domains.Layout;
import com.mobtools.server.services.LayoutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(Url.LAYOUT_URL)
public class LayoutController extends BaseController<LayoutService, Layout, String> {
@Autowired
public LayoutController(LayoutService service) {
super(service);
}
}

View File

@ -22,7 +22,7 @@ public class WidgetController extends BaseController<WidgetService, Widget, Stri
this.widgetService = service; this.widgetService = service;
} }
@GetMapping("/{name}") @GetMapping("/name/{name}")
public Mono<ResponseDto<Widget>> getByName(@PathVariable String name) { public Mono<ResponseDto<Widget>> getByName(@PathVariable String name) {
return widgetService.getByName(name) return widgetService.getByName(name)
.map(widget -> new ResponseDto<>(HttpStatus.OK.value(), widget, null)); .map(widget -> new ResponseDto<>(HttpStatus.OK.value(), widget, null));

View File

@ -32,9 +32,6 @@ public abstract class BaseDomain implements Persistable<String> {
protected Boolean deleted = false; protected Boolean deleted = false;
// @Version
// protected Long version;
@Override @Override
public boolean isNew() { public boolean isNew() {
return this.getId() == null; return this.getId() == null;

View File

@ -0,0 +1,18 @@
package com.mobtools.server.domains;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import net.minidev.json.JSONObject;
import org.springframework.data.mongodb.core.mapping.Document;
@Getter
@Setter
@ToString
@NoArgsConstructor
@Document
public class Layout extends BaseDomain {
JSONObject data;
}

View File

@ -0,0 +1,8 @@
package com.mobtools.server.repositories;
import com.mobtools.server.domains.Layout;
import org.springframework.stereotype.Repository;
@Repository
public interface LayoutRepository extends BaseRepository<Layout, String>{
}

View File

@ -59,6 +59,11 @@ public abstract class BaseService<R extends BaseRepository, T extends BaseDomain
return repository.findAll(); return repository.findAll();
} }
@Override
public Mono<T> getById(ID id) {
return repository.findById(id);
}
@Override @Override
public Mono<T> create(T widget) { public Mono<T> create(T widget) {
return repository.save(widget); return repository.save(widget);

View File

@ -11,4 +11,6 @@ public interface CrudService<T extends BaseDomain, ID> {
Mono<T> create(T resource); Mono<T> create(T resource);
Mono<T> update(ID id, T resource) throws Exception; Mono<T> update(ID id, T resource) throws Exception;
Mono<T> getById(ID id);
} }

View File

@ -0,0 +1,6 @@
package com.mobtools.server.services;
import com.mobtools.server.domains.Layout;
public interface LayoutService extends CrudService<Layout, String> {
}

View File

@ -0,0 +1,23 @@
package com.mobtools.server.services;
import com.mobtools.server.domains.Layout;
import com.mobtools.server.repositories.LayoutRepository;
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.scheduler.Scheduler;
@Slf4j
@Service
public class LayoutServiceImpl extends BaseService<LayoutRepository, Layout, String> implements LayoutService {
@Autowired
public LayoutServiceImpl(Scheduler scheduler,
MongoConverter mongoConverter,
ReactiveMongoTemplate reactiveMongoTemplate,
LayoutRepository repository) {
super(scheduler, mongoConverter, reactiveMongoTemplate, repository);
}
}