Skip to content

Commit

Permalink
feat: support publish reviewers settings (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
gangb-tech authored Sep 16, 2022
1 parent 47e038a commit cfcb5d8
Show file tree
Hide file tree
Showing 50 changed files with 1,705 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.featureprobe.api.base.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

public enum ApprovalStatusEnum {
PENDING,
PASS,
REJECT,
JUMP,
REVOKE;

private static final Map<String, ApprovalStatusEnum> namesMap = Arrays.stream(ApprovalStatusEnum.values())
.collect(Collectors.toMap(pt -> pt.name(), pt -> pt));

@JsonCreator
public static ApprovalStatusEnum forValue(String value) {
return namesMap.get(value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.featureprobe.api.base.enums;

public enum ApprovalTypeEnum {
APPROVAL,APPLY
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

public enum ResourceType {
PROJECT("projectKey"), TOGGLE("toggleKey"), ENVIRONMENT("environmentKey"),
MEMBER("account"),SEGMENT("segment"),DICTIONARY("dictionary"),
TARGETING("projectKey_environmentKey_toggleKey"), MEMBER("account"),
SEGMENT("segment"), DICTIONARY("dictionary"),
ORGANIZATION_MEMBER("organization_member");

private String paramName;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.featureprobe.api.base.enums;

import com.fasterxml.jackson.annotation.JsonCreator;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

public enum SketchStatusEnum {

PENDING,REVOKE,RELEASE,CANCEL;

private static final Map<String, SketchStatusEnum> namesMap = Arrays.stream(SketchStatusEnum.values())
.collect(Collectors.toMap(pt -> pt.name(), pt -> pt));

@JsonCreator
public static SketchStatusEnum forValue(String value) {
return namesMap.get(value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.featureprobe.api.controller;

import com.featureprobe.api.base.doc.DefaultApiResponses;
import com.featureprobe.api.dto.ApprovalRecordQueryRequest;
import com.featureprobe.api.dto.ApprovalRecordResponse;
import com.featureprobe.api.service.ApprovalRecordService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Slf4j
@DefaultApiResponses
@Tag(name = "Approval record", description = "Using the approval API, you can query approval record")
@RequestMapping("/approvalRecords")
@AllArgsConstructor
@RestController
public class ApprovalRecordController {

private ApprovalRecordService approvalRecordService;

@GetMapping
public Page<ApprovalRecordResponse> list(@Validated ApprovalRecordQueryRequest queryRequest) {
return approvalRecordService.list(queryRequest);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public DictionaryResponse query(@PathVariable("key") String key) {
@PostMapping("/{key}")
public DictionaryResponse save(@PathVariable("key") String key,
@RequestBody String value) {
return dictionaryService.save(key, value);
return dictionaryService.create(key, value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import com.featureprobe.api.base.doc.ProjectKeyParameter;
import com.featureprobe.api.base.enums.ResponseCodeEnum;
import com.featureprobe.api.base.enums.ValidateTypeEnum;
import com.featureprobe.api.dto.ApprovalSettings;
import com.featureprobe.api.dto.BaseResponse;
import com.featureprobe.api.dto.PreferenceCreateRequest;
import com.featureprobe.api.dto.ProjectCreateRequest;
import com.featureprobe.api.dto.ProjectQueryRequest;
import com.featureprobe.api.dto.ProjectResponse;
Expand Down Expand Up @@ -81,5 +83,19 @@ public BaseResponse exists(
return new BaseResponse(ResponseCodeEnum.SUCCESS);
}


@PostMapping("/{projectKey}")
@CreateApiResponse
@Operation(summary = "Save project setting", description = "Update a project settings.")
public BaseResponse preference(@PathVariable("projectKey") String projectKey,
@RequestBody @Validated PreferenceCreateRequest createRequest) {
projectService.createPreference(projectKey, createRequest);
return new BaseResponse(ResponseCodeEnum.SUCCESS);
}

@GetMapping("/{projectKey}/approvalSettings")
@CreateApiResponse
@Operation(summary = "Query project settings", description = "Query a project settings.")
public List<ApprovalSettings> approvalSettingsList(@PathVariable("projectKey") String projectKey) {
return projectService.approvalSettingsList(projectKey);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package com.featureprobe.api.controller;

import com.featureprobe.api.base.doc.CreateApiResponse;
import com.featureprobe.api.base.doc.DefaultApiResponses;
import com.featureprobe.api.base.doc.EnvironmentKeyParameter;
import com.featureprobe.api.base.doc.GetApiResponse;
import com.featureprobe.api.base.doc.PatchApiResponse;
import com.featureprobe.api.base.doc.ProjectKeyParameter;
import com.featureprobe.api.base.doc.ToggleKeyParameter;
import com.featureprobe.api.base.enums.ResponseCodeEnum;
import com.featureprobe.api.dto.AfterTargetingVersionResponse;
import com.featureprobe.api.dto.BaseResponse;
import com.featureprobe.api.dto.TargetingDiffResponse;
import com.featureprobe.api.dto.TargetingRequest;
import com.featureprobe.api.dto.TargetingResponse;
import com.featureprobe.api.dto.TargetingVersionRequest;
import com.featureprobe.api.dto.TargetingVersionResponse;
import com.featureprobe.api.dto.UpdateApprovalStatusRequest;
import com.featureprobe.api.service.TargetingService;
import com.featureprobe.api.validate.ResourceExistsValidate;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -43,13 +48,43 @@ public class TargetingController {
@PatchApiResponse
@PatchMapping
@Operation(summary = "Update targeting", description = "Update targeting.")
public TargetingRequest update(
public TargetingResponse update(
@PathVariable("projectKey") String projectKey,
@PathVariable("environmentKey") String environmentKey,
@PathVariable("toggleKey") String toggleKey,
@RequestBody @Validated TargetingRequest targetingRequest) {
targetingService.update(projectKey, environmentKey, toggleKey, targetingRequest);
return targetingRequest;
return targetingService.update(projectKey, environmentKey, toggleKey, targetingRequest);
}

@PatchMapping("/sketch/publish")
@CreateApiResponse
@Operation(summary = "Publish targeting sketch", description = "Publish targeting sketch.")
public TargetingResponse publishSketch(@PathVariable("projectKey") String projectKey,
@PathVariable("environmentKey") String environmentKey,
@PathVariable("toggleKey") String toggleKey) {
return targetingService.publishSketch(projectKey, environmentKey, toggleKey);
}

@PatchMapping("/sketch/cancel")
@CreateApiResponse
@Operation(summary = "Cancel targeting sketch", description = "Cancel targeting sketch.")
public BaseResponse cancelSketch(@PathVariable("projectKey") String projectKey,
@PathVariable("environmentKey") String environmentKey,
@PathVariable("toggleKey") String toggleKey) {
targetingService.cancelSketch(projectKey, environmentKey, toggleKey);
return new BaseResponse(ResponseCodeEnum.SUCCESS);
}


@PatchApiResponse
@PatchMapping("/approvalStatus")
@Operation(summary = "Update targeting approval status", description = "Update targeting approval status.")
public BaseResponse updateApprovalStatus(@PathVariable("projectKey") String projectKey,
@PathVariable("environmentKey") String environmentKey,
@PathVariable("toggleKey") String toggleKey,
@RequestBody @Validated UpdateApprovalStatusRequest updateRequest) {
targetingService.updateApprovalStatus(projectKey, environmentKey, toggleKey, updateRequest);
return new BaseResponse(ResponseCodeEnum.SUCCESS);
}

@GetApiResponse
Expand Down Expand Up @@ -83,4 +118,14 @@ public AfterTargetingVersionResponse allAfterVersions(@PathVariable("projectKey"
@PathVariable("version") Long version) {
return targetingService.queryAfterVersion(projectKey, environmentKey, toggleKey, version);
}

@GetApiResponse
@GetMapping("/diff")
@Operation(summary = "Get targeting diff.", description = "Get targeting diff.")
public TargetingDiffResponse diff(@PathVariable("projectKey") String projectKey,
@PathVariable("environmentKey") String environmentKey,
@PathVariable("toggleKey") String toggleKey) {
return targetingService.diff(projectKey, environmentKey, toggleKey);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class ToggleController {
public Page<ToggleItemResponse> list(
@PathVariable(name = "projectKey") String projectKey,
@Validated ToggleSearchRequest filter) {
return toggleService.query(projectKey, filter);
return toggleService.list(projectKey, filter);
}

@CreateApiResponse
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.featureprobe.api.dto;

import com.featureprobe.api.base.enums.ApprovalTypeEnum;
import lombok.Data;

import javax.validation.constraints.NotNull;

@Data
public class ApprovalRecordQueryRequest extends PaginationRequest{

private String keyword;

@NotNull
private String status;

@NotNull
private ApprovalTypeEnum type;

}
46 changes: 46 additions & 0 deletions src/main/java/com/featureprobe/api/dto/ApprovalRecordResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.featureprobe.api.dto;

import com.featureprobe.api.base.enums.ApprovalStatusEnum;
import lombok.Data;

import java.util.Date;
import java.util.List;

@Data
public class ApprovalRecordResponse {

private String title;

private String projectName;

private String projectKey;

private String toggleName;

private String toggleKey;

private String environmentName;

private String environmentKey;

private ApprovalStatusEnum status;

private String submitBy;

private boolean locked;

private Date lockedTime;

private List<String> reviewers;

private String approvedBy;

private String comment;

private Date approvalTime;

private Date sketchTime;

private Date cancelTime;

}
16 changes: 16 additions & 0 deletions src/main/java/com/featureprobe/api/dto/ApprovalSettings.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.featureprobe.api.dto;

import lombok.Data;

import java.util.List;

@Data
public class ApprovalSettings {

private String environmentKey;

private Boolean enable;

private List<String> reviewers;

}
1 change: 0 additions & 1 deletion src/main/java/com/featureprobe/api/dto/BaseResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class BaseResponse {
private String message;

public BaseResponse(ResponseCodeEnum responseCode) {
this.code = responseCode.code();
this.message = responseCode.message();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.featureprobe.api.dto;

import lombok.Data;

import java.util.List;

@Data
public class PreferenceCreateRequest {

List<ApprovalSettings> approvalSettings;

}

12 changes: 12 additions & 0 deletions src/main/java/com/featureprobe/api/dto/TargetingDiffRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.featureprobe.api.dto;

import lombok.Data;

@Data
public class TargetingDiffRequest {

private Long currentVersion;

private Long targetVersion;

}
15 changes: 15 additions & 0 deletions src/main/java/com/featureprobe/api/dto/TargetingDiffResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.featureprobe.api.dto;

import com.featureprobe.api.model.TargetingContent;
import lombok.Data;

@Data
public class TargetingDiffResponse {

private Boolean currentDisabled;
private TargetingContent currentContent;

private Boolean oldDisabled;
private TargetingContent oldContent;

}
10 changes: 8 additions & 2 deletions src/main/java/com/featureprobe/api/dto/TargetingRequest.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package com.featureprobe.api.dto;

import com.featureprobe.api.model.TargetingContent;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class TargetingRequest {

private TargetingContent content;

private String comment;

private Boolean disabled;
}

private List<String> reviewers;
}
Loading

0 comments on commit cfcb5d8

Please sign in to comment.