feat(文件管理): 调用文件修改接口时确保标签不会重复

This commit is contained in:
song-tianyang 2023-11-17 17:13:45 +08:00 committed by 刘瑞斌
parent 8dcef99e4d
commit d0ba083172
3 changed files with 8 additions and 6 deletions

View File

@ -4,7 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotBlank;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.LinkedHashSet;
@Data @Data
public class FileUpdateRequest { public class FileUpdateRequest {
@ -15,8 +15,9 @@ public class FileUpdateRequest {
@Schema(description = "文件名称") @Schema(description = "文件名称")
private String name; private String name;
// tags内的数据确保不重复且有序所以使用这个数据结构接受
@Schema(description = "标签") @Schema(description = "标签")
private List< private LinkedHashSet<
@NotBlank @NotBlank
String> tags; String> tags;

View File

@ -975,7 +975,7 @@ public class FileManagementControllerTests extends BaseTest {
FileUpdateRequest updateRequest = new FileUpdateRequest(); FileUpdateRequest updateRequest = new FileUpdateRequest();
updateRequest.setId(updateFileId); updateRequest.setId(updateFileId);
updateRequest.setName("update_" + updateFileId); updateRequest.setName("update_" + updateFileId);
updateRequest.setTags(new ArrayList<>() {{ updateRequest.setTags(new LinkedHashSet<>() {{
this.add("tag1"); this.add("tag1");
}}); }});
updateRequest.setDescription("updateDesc_" + updateFileId); updateRequest.setDescription("updateDesc_" + updateFileId);
@ -997,7 +997,7 @@ public class FileManagementControllerTests extends BaseTest {
oldFileMetadata = fileMetadataMapper.selectByPrimaryKey(updateFileId); oldFileMetadata = fileMetadataMapper.selectByPrimaryKey(updateFileId);
updateRequest = new FileUpdateRequest(); updateRequest = new FileUpdateRequest();
updateRequest.setId(updateFileId); updateRequest.setId(updateFileId);
updateRequest.setTags(new ArrayList<>()); updateRequest.setTags(new LinkedHashSet<>());
this.requestPostWithOk(FileManagementRequestUtils.URL_FILE_UPDATE, updateRequest); this.requestPostWithOk(FileManagementRequestUtils.URL_FILE_UPDATE, updateRequest);
this.checkFileInformation(updateFileId, oldFileMetadata, updateRequest); this.checkFileInformation(updateFileId, oldFileMetadata, updateRequest);
@ -1013,7 +1013,7 @@ public class FileManagementControllerTests extends BaseTest {
oldFileMetadata = fileMetadataMapper.selectByPrimaryKey(updateFileId); oldFileMetadata = fileMetadataMapper.selectByPrimaryKey(updateFileId);
updateRequest = new FileUpdateRequest(); updateRequest = new FileUpdateRequest();
updateRequest.setId(updateFileId); updateRequest.setId(updateFileId);
updateRequest.setTags(new ArrayList<>()); updateRequest.setTags(new LinkedHashSet<>());
this.requestPostWithOk(FileManagementRequestUtils.URL_FILE_UPDATE, updateRequest); this.requestPostWithOk(FileManagementRequestUtils.URL_FILE_UPDATE, updateRequest);
this.checkFileInformation(updateFileId, oldFileMetadata, updateRequest); this.checkFileInformation(updateFileId, oldFileMetadata, updateRequest);

View File

@ -21,6 +21,7 @@ import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.Objects; import java.util.Objects;
@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT)
@ -121,7 +122,7 @@ public class FileManagementPermissionControllerTests extends BaseTest {
FileUpdateRequest updateRequest = new FileUpdateRequest(); FileUpdateRequest updateRequest = new FileUpdateRequest();
updateRequest.setId(TEST_ID); updateRequest.setId(TEST_ID);
updateRequest.setName("update_" + TEST_ID); updateRequest.setName("update_" + TEST_ID);
updateRequest.setTags(new ArrayList<>() {{ updateRequest.setTags(new LinkedHashSet<>() {{
this.add("tag1"); this.add("tag1");
}}); }});
this.requestPostPermissionTest(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ_UPDATE, FileManagementRequestUtils.URL_FILE_UPDATE, updateRequest); this.requestPostPermissionTest(PermissionConstants.PROJECT_FILE_MANAGEMENT_READ_UPDATE, FileManagementRequestUtils.URL_FILE_UPDATE, updateRequest);