Skip to content

Commit

Permalink
WIP Batch Delete Silos
Browse files Browse the repository at this point in the history
  • Loading branch information
amengus87 committed Aug 29, 2024
1 parent cf22833 commit 4537a67
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 41 deletions.
8 changes: 6 additions & 2 deletions backend/src/main/java/ai/dragon/config/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
public class WebConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(@NonNull CorsRegistry registry) {
// Allow CORS requests from all origins to all endpoints
registry.addMapping("/**").allowedOrigins("*");
// Allow CORS requests :
registry
.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS")
.allowedHeaders("*");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,10 @@ protected void delete(String uuid, AbstractRepository<T> repository) {
}
repository.delete(uuid);
}

protected void deleteMultiple(List<String> uuids, AbstractRepository<T> repository) {
for (String uuid : uuids) {
delete(uuid, repository);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import ai.dragon.dto.api.DataTableApiResponse;
import ai.dragon.dto.api.GenericApiResponse;
import ai.dragon.dto.api.SuccessApiResponse;
import ai.dragon.dto.api.backend.UUIDsBatchRequest;
import ai.dragon.entity.SiloEntity;
import ai.dragon.repository.SiloRepository;
import ai.dragon.repository.util.Pager;
Expand Down Expand Up @@ -59,49 +61,72 @@ public GenericApiResponse searchSilos(@RequestParam(name = "current", defaultVal
@ApiResponse(responseCode = "200", description = "Silo has been successfully created.")
@ApiResponse(responseCode = "409", description = "Constraint violation.", content = @Content)
@Operation(summary = "Create a new Silo", description = "Creates one Silo entity in the database.")
public SiloEntity createSilo() throws Exception {
return super.create(siloRepository);
public GenericApiResponse createSilo() throws Exception {
return SuccessApiResponse
.builder()
.data(super.create(siloRepository))
.build();
}

@GetMapping("/{uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}}")
@ApiResponse(responseCode = "200", description = "Silo has been successfully retrieved.")
@ApiResponse(responseCode = "404", description = "Silo not found.", content = @Content)
@Operation(summary = "Retrieve one Silo", description = "Returns one Silo entity from its UUID stored in the database.")
public SiloEntity getSilo(
public GenericApiResponse getSilo(
@PathVariable("uuid") @Parameter(description = "Identifier of the Silo", required = true) String uuid) {
return super.get(uuid, siloRepository);
return SuccessApiResponse
.builder()
.data(super.get(uuid, siloRepository))
.build();
}

@PatchMapping("/{uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}}")
@ApiResponse(responseCode = "200", description = "Silo has been successfully updated.")
@ApiResponse(responseCode = "404", description = "Silo not found.", content = @Content)
@Operation(summary = "Update a Silo", description = "Updates one Silo entity in the database.")
public SiloEntity updateSilo(
public GenericApiResponse updateSilo(
@PathVariable("uuid") @Parameter(description = "Identifier of the Silo", required = true) String uuid,
@RequestBody Map<String, Object> fields) throws JsonMappingException {
return super.update(uuid, fields, siloRepository);
return SuccessApiResponse
.builder()
.data(super.update(uuid, fields, siloRepository))
.build();
}

@PutMapping("/{uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}}")
@ApiResponse(responseCode = "200", description = "Silo has been successfully updated.")
@ApiResponse(responseCode = "404", description = "Silo not found.", content = @Content)
@Operation(summary = "Upsert a Silo", description = "Upsert one Silo entity in the database.")
public SiloEntity upsertSilo(
public GenericApiResponse upsertSilo(
@PathVariable("uuid") @Parameter(description = "Identifier of the Silo", required = false) String uuid,
@RequestBody Map<String, Object> fields) throws Exception {
if (uuid == null || UUIDUtil.zeroUUIDString().equals(uuid)) {
fields.remove("uuid");
uuid = super.create(siloRepository).getUuid().toString();
}
return super.update(uuid, fields, siloRepository);
return SuccessApiResponse
.builder()
.data(super.update(uuid, fields, siloRepository))
.build();
}

@DeleteMapping("/{uuid:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}}")
@ApiResponse(responseCode = "200", description = "Silo has been successfully deleted.")
@ApiResponse(responseCode = "404", description = "Silo not found.", content = @Content)
@Operation(summary = "Delete a Silo", description = "Deletes one Silo entity from its UUID stored in the database.")
public void deleteSilo(@PathVariable("uuid") @Parameter(description = "Identifier of the Silo") UUID uuid)
public GenericApiResponse deleteSilo(
@PathVariable("uuid") @Parameter(description = "Identifier of the Silo") UUID uuid)
throws Exception {
super.delete(uuid, siloRepository);
return SuccessApiResponse.builder().build();
}

@DeleteMapping("/deleteMultiple")
@ApiResponse(responseCode = "200", description = "Silo has been successfully deleted.")
@ApiResponse(responseCode = "404", description = "Silo not found.", content = @Content)
@Operation(summary = "Delete multiple Silos", description = "Deletes one or more Silo entity from their UUID stored in the database.")
public GenericApiResponse deleteMultipleSilos(@RequestBody UUIDsBatchRequest request) throws Exception {
super.deleteMultiple(request.getUuids(), siloRepository);
return SuccessApiResponse.builder().build();
}
}
5 changes: 0 additions & 5 deletions backend/src/main/java/ai/dragon/dto/api/GenericApiData.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ai.dragon.dto.api;

public interface GenericApiResponse {
public GenericApiData getData();
public Object getData();
public String getCode();
public String getMsg();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@Data
public class SuccessApiResponse implements GenericApiResponse {
@Builder.Default
private GenericApiData data = null;
private Object data = null;

@Builder.Default
private String code = "0000";
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/java/ai/dragon/dto/api/TableApiData.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.List;

public interface TableApiData extends GenericApiData {
public interface TableApiData {
public List<?> getRecords();
public long getCurrent();
public long getSize();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package ai.dragon.dto.api.app.auth;

import ai.dragon.dto.api.GenericApiData;
import lombok.Builder;
import lombok.Data;

@Builder
@Data
public class LoginAuthAppApiData implements GenericApiData {
public class LoginAuthAppApiData {
private String token;
private String refreshToken;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

import java.util.List;

import ai.dragon.dto.api.GenericApiData;
import lombok.Builder;
import lombok.Data;

@Builder
@Data
public class UserInfoAuthAppApiData implements GenericApiData {
public class UserInfoAuthAppApiData {
private String userId;
private String userName;
private List<String> roles;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package ai.dragon.dto.api.app.dashboard;

import ai.dragon.dto.api.GenericApiData;
import lombok.Builder;
import lombok.Data;

@Builder
@Data
public class NumbersDashboardAppApiData implements GenericApiData {
public class NumbersDashboardAppApiData {
private Long silos;
private Long farms;
private Long documents;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ai.dragon.dto.api.backend;

import java.util.List;

import lombok.Data;

@Data
public class UUIDsBatchRequest {
private List<String> uuids;
}
4 changes: 2 additions & 2 deletions frontend/src/service/api/app-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { request } from '../request';
export function fetchLogin(userName: string, password: string) {
return request<Api.Auth.LoginToken>({
url: '/api/app/auth/login',
method: 'post',
method: 'POST',
data: {
userName,
password
Expand All @@ -30,7 +30,7 @@ export function fetchGetUserInfo() {
export function fetchRefreshToken(refreshToken: string) {
return request<Api.Auth.LoginToken>({
url: '/api/app/auth/refreshToken',
method: 'post',
method: 'POST',
data: {
refreshToken
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/service/api/app-dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import { request } from '../request';
export function fetchApiAppDashboardGetNumbers() {
return request<Api.AppDashboard.Numbers>({
url: '/api/app/dashboard/numbers',
method: 'get'
method: 'GET'
});
}
19 changes: 19 additions & 0 deletions frontend/src/service/api/backend-silo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,22 @@ export function fetchUpsertSilo(data: Api.SiloManage.Silo) {
data
});
}

/** Delete Silo */
export function fetchDeleteSilo(uuid: string) {
return request<Api.Common.CommonRecord>({
url: `/api/backend/repository/silo/${uuid}`,
method: 'DELETE'
});
}

/** Delete Silos */
export function fetchDeleteMultipleSilos(uuids: string[]) {
return request<Api.Common.CommonRecord>({
url: `/api/backend/repository/silo/deleteMultiple`,
method: 'DELETE',
data: {
uuids
}
});
}
20 changes: 11 additions & 9 deletions frontend/src/views/infrastructure/silo-list/index.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="tsx">
import { NButton, NPopconfirm, NTag } from 'naive-ui';
import { fetchGetSilosList } from '@/service/api';
import { fetchDeleteMultipleSilos, fetchDeleteSilo, fetchGetSilosList } from '@/service/api';
import { $t } from '@/locales';
import { useAppStore } from '@/store/modules/app';
import { embeddingModelRecord, ingestorLoaderRecord, vectoreStoreRecord } from '@/constants/business';
Expand Down Expand Up @@ -149,17 +149,19 @@ const {
} = useTableOperate(data, getData);
async function handleBatchDelete() {
// request
// console.log(checkedRowKeys.value);
onBatchDeleted();
fetchDeleteMultipleSilos(checkedRowKeys.value).then(response => {
if (response.error === null) {
onBatchDeleted();
}
});
}
function handleDelete(_id: string) {
// request
// console.log(id);
onDeleted();
fetchDeleteSilo(_id).then(response => {
if (response.error === null) {
onDeleted();
}
});
}
function handleReset() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,13 @@ function closeDrawer() {
async function handleSubmit() {
await validate();
fetchUpsertSilo(model as Api.SiloManage.Silo);
window.$message?.success($t('common.updateSuccess'));
closeDrawer();
emit('submitted');
fetchUpsertSilo(model as Api.SiloManage.Silo).then(response => {
if (response.error === null) {
window.$message?.success($t('common.updateSuccess'));
closeDrawer();
emit('submitted');
}
});
}
watch(visible, () => {
Expand Down

0 comments on commit 4537a67

Please sign in to comment.