Skip to content

Commit

Permalink
feat: remove includeDeleted query & add manager toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
jianggang committed Aug 17, 2022
1 parent 902cd73 commit 1d6c264
Show file tree
Hide file tree
Showing 20 changed files with 170 additions and 302 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public FeatureProbe featureProbe() throws MalformedURLException {
.eventUrl(new URL(LOCAL_HOST + ":" + serverProperties.getPort() + FEATURE_PROBE_API_EVENT_PATH))
.synchronizerUrl(new URL(LOCAL_HOST + ":" + serverProperties.getPort() +
FEATURE_PROBE_API_SYNCHRONIZER_PATH))
.pollingMode(Duration.ofSeconds(10))
.pollingMode(Duration.ofSeconds(10000))
.useMemoryRepository()
.build();
return new FeatureProbe(MANAGER_PROJECT_SDK_KEY, config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.featureprobe.api.dto.EnvironmentCreateRequest;
import com.featureprobe.api.dto.EnvironmentResponse;
import com.featureprobe.api.dto.EnvironmentUpdateRequest;
import com.featureprobe.api.service.EnvironmentIncludeDeletedService;
import com.featureprobe.api.service.EnvironmentService;
import com.featureprobe.api.validate.ResourceExistsValidate;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -36,8 +35,6 @@ public class EnvironmentController {

private EnvironmentService environmentService;

private EnvironmentIncludeDeletedService environmentIncludeDeletedService;

@PostMapping
@CreateApiResponse
@Operation(summary = "Create environment", description = "Create a new environment.")
Expand Down Expand Up @@ -69,7 +66,7 @@ public EnvironmentResponse query(@PathVariable("projectKey") String projectKey,
public BaseResponse exists(@PathVariable("projectKey") String projectKey,
@RequestParam ValidateTypeEnum type,
@RequestParam String value) {
environmentIncludeDeletedService.validateExists(projectKey, type, value);
environmentService.validateExists(projectKey, type, value);
return new BaseResponse(ResponseCodeEnum.SUCCESS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.featureprobe.api.dto.ProjectQueryRequest;
import com.featureprobe.api.dto.ProjectResponse;
import com.featureprobe.api.dto.ProjectUpdateRequest;
import com.featureprobe.api.service.ProjectIncludeDeletedService;
import com.featureprobe.api.service.ProjectService;
import com.featureprobe.api.validate.ResourceExistsValidate;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -28,7 +27,6 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
Expand All @@ -43,8 +41,6 @@ public class ProjectController {

private ProjectService projectService;

private ProjectIncludeDeletedService projectIncludeDeletedService;

@PostMapping
@CreateApiResponse
@Operation(summary = "Create project", description = "Create a new project.")
Expand Down Expand Up @@ -81,7 +77,7 @@ public ProjectResponse query(
public BaseResponse exists(
@RequestParam ValidateTypeEnum type,
@RequestParam String value) {
projectIncludeDeletedService.validateExists(type, value);
projectService.validateExists(type, value);
return new BaseResponse(ResponseCodeEnum.SUCCESS);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.featureprobe.api.dto.SegmentSearchRequest;
import com.featureprobe.api.dto.SegmentUpdateRequest;
import com.featureprobe.api.dto.ToggleSegmentResponse;
import com.featureprobe.api.service.SegmentIncludeDeletedService;
import com.featureprobe.api.service.SegmentService;
import com.featureprobe.api.validate.ResourceExistsValidate;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -42,8 +41,6 @@ public class SegmentController {

private SegmentService segmentService;

private SegmentIncludeDeletedService segmentIncludeDeletedService;

@GetMapping
@GetApiResponse
@Operation(summary = "List segments", description = "Get a list of all segments")
Expand Down Expand Up @@ -101,7 +98,7 @@ public SegmentResponse query(@PathVariable(name = "projectKey") String projectKe
public BaseResponse exists(@PathVariable("projectKey") String projectKey,
@RequestParam ValidateTypeEnum type,
@RequestParam String value) {
segmentIncludeDeletedService.validateExistsIncludeDeleted(projectKey, type, value);
segmentService.validateExists(projectKey, type, value);
return new BaseResponse(ResponseCodeEnum.SUCCESS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.featureprobe.api.dto.ToggleResponse;
import com.featureprobe.api.dto.ToggleSearchRequest;
import com.featureprobe.api.dto.ToggleUpdateRequest;
import com.featureprobe.api.service.ToggleIncludeDeletedService;
import com.featureprobe.api.validate.ResourceExistsValidate;
import com.featureprobe.api.service.ToggleService;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -45,8 +44,6 @@ public class ToggleController {

private ToggleService toggleService;

private ToggleIncludeDeletedService toggleIncludeDeletedService;

@GetMapping
@GetApiResponse
@Operation(summary = "List toggles", description = "Get a list of all toggles in the project.")
Expand Down Expand Up @@ -88,7 +85,7 @@ public ToggleResponse query(@PathVariable(name = "projectKey") String projectKey
public BaseResponse checkKey(@PathVariable("projectKey") String projectKey,
@RequestParam ValidateTypeEnum type,
@RequestParam String value){
toggleIncludeDeletedService.validateExists(projectKey, type, value);
toggleService.validateExists(projectKey, type, value);
return new BaseResponse(ResponseCodeEnum.SUCCESS);
}

Expand Down

This file was deleted.

35 changes: 29 additions & 6 deletions src/main/java/com/featureprobe/api/service/EnvironmentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import com.featureprobe.api.auth.TokenHelper;
import com.featureprobe.api.base.enums.ResourceType;
import com.featureprobe.api.base.enums.ValidateTypeEnum;
import com.featureprobe.api.base.exception.ResourceConflictException;
import com.featureprobe.api.base.exception.ResourceNotFoundException;
import com.featureprobe.api.base.exception.ResourceOverflowException;
import com.featureprobe.api.dto.EnvironmentCreateRequest;
import com.featureprobe.api.dto.EnvironmentResponse;
import com.featureprobe.api.dto.EnvironmentUpdateRequest;
import com.featureprobe.api.dto.SdkKeyResponse;
import com.featureprobe.api.entity.Environment;
import com.featureprobe.api.entity.Project;
import com.featureprobe.api.entity.Targeting;
Expand Down Expand Up @@ -43,8 +44,6 @@ public class EnvironmentService {

private TargetingRepository targetingRepository;

private EnvironmentIncludeDeletedService environmentIncludeDeletedService;

private FeatureProbe featureProbe;

@PersistenceContext
Expand All @@ -56,8 +55,8 @@ public class EnvironmentService {
public EnvironmentResponse create(String projectKey, EnvironmentCreateRequest createRequest) {
validateLimit(projectKey);
Project project = projectRepository.findByKey(projectKey).get();
environmentIncludeDeletedService.validateKeyIncludeDeleted(projectKey, createRequest.getKey());
environmentIncludeDeletedService.validateNameIncludeDeleted(projectKey, createRequest.getName());
validateKey(projectKey, createRequest.getKey());
validateName(projectKey, createRequest.getName());
Environment environment = EnvironmentMapper.INSTANCE.requestToEntity(createRequest);
environment.setServerSdkKey(SdkKeyGenerateUtil.getServerSdkKey());
environment.setClientSdkKey(SdkKeyGenerateUtil.getClientSdkKey());
Expand All @@ -71,7 +70,7 @@ public EnvironmentResponse update(String projectKey, String environmentKey,
EnvironmentUpdateRequest updateRequest) {
Environment environment = environmentRepository.findByProjectKeyAndKey(projectKey, environmentKey).get();
if (!StringUtils.equals(environment.getName(), updateRequest.getName())) {
environmentIncludeDeletedService.validateNameIncludeDeleted(projectKey, updateRequest.getName());
validateName(projectKey, updateRequest.getName());
}
EnvironmentMapper.INSTANCE.mapEntity(updateRequest, environment);
if (updateRequest.isResetServerSdk()) {
Expand Down Expand Up @@ -118,4 +117,28 @@ private Targeting createDefaultTargeting(Toggle toggle, String environmentKey) {
return targeting;
}

public void validateExists(String projectKey, ValidateTypeEnum type, String value) {
switch (type) {
case KEY:
validateKey(projectKey, value);
break;
case NAME:
validateName(projectKey, value);
break;
default:
break;
}
}

private void validateKey(String projectKey, String key) {
if (environmentRepository.existsByProjectKeyAndKey(projectKey, key)) {
throw new ResourceConflictException(ResourceType.ENVIRONMENT);
}
}

private void validateName(String projectKey, String name) {
if (environmentRepository.existsByProjectKeyAndName(projectKey, name)) {
throw new ResourceConflictException(ResourceType.ENVIRONMENT);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.featureprobe.api.auth.tenant.TenantContext;
import com.featureprobe.api.base.constants.MessageKey;
import com.featureprobe.api.base.enums.ResourceType;
import com.featureprobe.api.base.enums.RoleEnum;
import com.featureprobe.api.base.exception.ForbiddenException;
import com.featureprobe.api.base.exception.ResourceNotFoundException;
import com.featureprobe.api.dto.MemberCreateRequest;
Expand Down Expand Up @@ -109,6 +110,7 @@ private List<Member> newNumbers(MemberCreateRequest createRequest) {
private Member newMember(String account, String password) {
Member member = new Member();
member.setAccount(account);
member.setRole(RoleEnum.MEMBER);
member.setPassword(new BCryptPasswordEncoder().encode(password));
Organization organization = organizationRepository.findById(TenantContext.getCurrentOrganization()
.getOrganizationId()).get();
Expand Down Expand Up @@ -137,7 +139,7 @@ public Page<MemberResponse> query(MemberSearchRequest searchRequest) {
Specification<OrganizationMember> spec = (root, query, cb) -> {
Predicate p1 = cb.equal(root.get("organizationId"), TenantContext.getCurrentOrganization()
.getOrganizationId());
return query.where(cb.and(p1)).groupBy(root.get("userId"))
return query.where(cb.and(p1)).groupBy(root.get("memberId"))
.getRestriction();
};
Page<OrganizationMember> organizationMembers = organizationMemberRepository.findAll(spec, pageable);
Expand Down

This file was deleted.

37 changes: 32 additions & 5 deletions src/main/java/com/featureprobe/api/service/ProjectService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.featureprobe.api.auth.TokenHelper;
import com.featureprobe.api.base.enums.ResourceType;
import com.featureprobe.api.base.enums.ValidateTypeEnum;
import com.featureprobe.api.base.exception.ResourceConflictException;
import com.featureprobe.api.base.exception.ResourceNotFoundException;
import com.featureprobe.api.base.exception.ResourceOverflowException;
import com.featureprobe.api.dto.ProjectCreateRequest;
Expand Down Expand Up @@ -33,8 +35,6 @@ public class ProjectService {

private ProjectRepository projectRepository;

private ProjectIncludeDeletedService projectIncludeDeletedService;

private FeatureProbe featureProbe;

@PersistenceContext
Expand All @@ -52,7 +52,7 @@ public ProjectResponse create(ProjectCreateRequest createRequest) {
public ProjectResponse update(String projectKey, ProjectUpdateRequest updateRequest) {
Project project = projectRepository.findByKey(projectKey).get();
if (!StringUtils.equals(project.getName(), updateRequest.getName())) {
projectIncludeDeletedService.validateNameIncludeDeleted(updateRequest.getName());
validateName(updateRequest.getName());
}
ProjectMapper.INSTANCE.mapEntity(updateRequest, project);
return ProjectMapper.INSTANCE.entityToResponse(projectRepository.save(project));
Expand All @@ -69,8 +69,8 @@ private void validateLimit() {
}

private Project createProject(ProjectCreateRequest createRequest) {
projectIncludeDeletedService.validateKeyIncludeDeleted(createRequest.getKey());
projectIncludeDeletedService.validateNameIncludeDeleted(createRequest.getName());
validateKey(createRequest.getKey());
validateName(createRequest.getName());
Project createProject = ProjectMapper.INSTANCE.requestToEntity(createRequest);
createProject.setDeleted(false);
createProject.setEnvironments(createDefaultEnv(createProject));
Expand Down Expand Up @@ -112,4 +112,31 @@ private Environment createOnlineEnv(Project project) {
return onlineEnv;
}

public void validateExists(ValidateTypeEnum type, String value) {

switch (type) {
case KEY:
validateKey(value);
break;
case NAME:
validateName(value);
break;
default:
break;
}

}

private void validateKey(String key) {
if (projectRepository.existsByKey(key)) {
throw new ResourceConflictException(ResourceType.PROJECT);
}
}

private void validateName(String name) {
if (projectRepository.existsByName(name)) {
throw new ResourceConflictException(ResourceType.PROJECT);
}
}

}
Loading

0 comments on commit 1d6c264

Please sign in to comment.