Merge branch 'app-crud' into 'master'
Application CRUD See merge request theappsmith/internal-tools-server!13
This commit is contained in:
commit
59f85cef96
|
|
@ -12,4 +12,5 @@ public interface Url {
|
|||
String RESOURCE_URL = BASE_URL + VERSION + "/resources";
|
||||
String ACTION_URL = BASE_URL + VERSION + "/actions";
|
||||
String USER_URL = BASE_URL + VERSION + "/users";
|
||||
String APPLICATION_URL = BASE_URL + VERSION + "/applications";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
package com.appsmith.server.controllers;
|
||||
|
||||
import com.appsmith.server.constants.Url;
|
||||
import com.appsmith.server.domains.Application;
|
||||
import com.appsmith.server.services.ApplicationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(Url.APPLICATION_URL)
|
||||
public class ApplicationController extends BaseController<ApplicationService, Application, String> {
|
||||
@Autowired
|
||||
public ApplicationController(ApplicationService service) {
|
||||
super(service);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package com.appsmith.server.domains;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@Document
|
||||
public class Application extends BaseDomain {
|
||||
|
||||
@NotNull
|
||||
String name;
|
||||
|
||||
String organizationId;
|
||||
|
||||
List<ApplicationPage> pages;
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.appsmith.server.domains;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
public class ApplicationPage {
|
||||
|
||||
String id;
|
||||
|
||||
String name;
|
||||
|
||||
Boolean isDefault;
|
||||
}
|
||||
|
|
@ -5,14 +5,14 @@ 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 {
|
||||
|
||||
ScreenType screen;
|
||||
|
||||
JSONObject data;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
package com.appsmith.server.domains;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@NoArgsConstructor
|
||||
@Document
|
||||
public class Page extends BaseDomain {
|
||||
String name;
|
||||
|
||||
String applicationId;
|
||||
|
||||
List<Layout> layouts;
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package com.appsmith.server.domains;
|
||||
|
||||
public enum ScreenType {
|
||||
DESKTOP, MOBILE
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package com.appsmith.server.repositories;
|
||||
|
||||
import com.appsmith.server.domains.Application;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ApplicationRepository extends BaseRepository<Application, String> {
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
package com.appsmith.server.services;
|
||||
|
||||
import com.appsmith.server.domains.Application;
|
||||
|
||||
public interface ApplicationService extends CrudService<Application, String> {
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package com.appsmith.server.services;
|
||||
|
||||
import com.appsmith.server.domains.Application;
|
||||
import com.appsmith.server.domains.User;
|
||||
import com.appsmith.server.repositories.ApplicationRepository;
|
||||
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.Validator;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class ApplicationServiceImpl extends BaseService<ApplicationRepository, Application, String> implements ApplicationService {
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
@Autowired
|
||||
public ApplicationServiceImpl(Scheduler scheduler, Validator validator, MongoConverter mongoConverter, ReactiveMongoTemplate reactiveMongoTemplate, ApplicationRepository repository, UserService userService) {
|
||||
super(scheduler, validator, mongoConverter, reactiveMongoTemplate, repository);
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Application> create(Application application) {
|
||||
Mono<User> userMono = userService.getCurrentUser();
|
||||
|
||||
return userMono
|
||||
.map(user -> user.getOrganizationId())
|
||||
.map(orgId -> {
|
||||
application.setOrganizationId(orgId);
|
||||
return application;
|
||||
})
|
||||
.flatMap(repository::save);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user