Support followers for Database (#21169)

This commit is contained in:
sonika-shah 2025-05-14 09:50:23 +05:30 committed by GitHub
parent d4d1a16eaf
commit 829196f92b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 71 additions and 2 deletions

View File

@ -79,7 +79,7 @@ public class DatabaseResource extends EntityResource<Database, DatabaseRepositor
public static final String COLLECTION_PATH = "v1/databases/";
private final DatabaseMapper mapper = new DatabaseMapper();
static final String FIELDS =
"owners,databaseSchemas,usageSummary,location,tags,extension,domain,sourceHash";
"owners,databaseSchemas,usageSummary,location,tags,extension,domain,sourceHash,followers";
@Override
public Database addHref(UriInfo uriInfo, Database db) {
@ -757,4 +757,65 @@ public class DatabaseResource extends EntityResource<Database, DatabaseRepositor
Database database = repository.deleteDatabaseProfilerConfig(id);
return addHref(uriInfo, database);
}
@PUT
@Path("/{id}/followers")
@Operation(
operationId = "addFollowerToDatabase",
summary = "Add a follower",
description = "Add a user identified by `userId` as followed of this Database",
responses = {
@ApiResponse(
responseCode = "200",
description = "OK",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = ChangeEvent.class))),
@ApiResponse(responseCode = "404", description = "Database for instance {id} is not found")
})
public Response addFollower(
@Context UriInfo uriInfo,
@Context SecurityContext securityContext,
@Parameter(description = "Id of the Database", schema = @Schema(type = "UUID"))
@PathParam("id")
UUID id,
@Parameter(
description = "Id of the user to be added as follower",
schema = @Schema(type = "string"))
UUID userId) {
return repository
.addFollower(securityContext.getUserPrincipal().getName(), id, userId)
.toResponse();
}
@DELETE
@Path("/{id}/followers/{userId}")
@Operation(
operationId = "deleteFollower",
summary = "Remove a follower",
description = "Remove the user identified `userId` as a follower of the entity.",
responses = {
@ApiResponse(
responseCode = "200",
description = "OK",
content =
@Content(
mediaType = "application/json",
schema = @Schema(implementation = ChangeEvent.class)))
})
public Response deleteFollower(
@Context UriInfo uriInfo,
@Context SecurityContext securityContext,
@Parameter(description = "Id of the Entity", schema = @Schema(type = "UUID")) @PathParam("id")
UUID id,
@Parameter(
description = "Id of the user being removed as follower",
schema = @Schema(type = "string"))
@PathParam("userId")
String userId) {
return repository
.deleteFollower(securityContext.getUserPrincipal().getName(), id, UUID.fromString(userId))
.toResponse();
}
}

View File

@ -333,7 +333,7 @@ public class DatabaseResourceTest extends EntityResourceTest<Database, CreateDat
database.getUsageSummary(),
database.getLocation());
fields = "owners,databaseSchemas,usageSummary,location,tags";
fields = "owners,databaseSchemas,usageSummary,location,tags,followers";
database =
byName
? getEntityByName(database.getFullyQualifiedName(), fields, ADMIN_AUTH_HEADERS)

View File

@ -128,6 +128,10 @@
"certification": {
"$ref": "../../type/assetCertification.json"
},
"followers": {
"description": "Followers of this entity.",
"$ref": "../../type/entityReferenceList.json"
},
"sourceHash": {
"description": "Source hash of the entity",
"type": "string",

View File

@ -59,6 +59,10 @@ export interface Database {
* Entity extension data with custom attributes added to the entity.
*/
extension?: any;
/**
* Followers of this entity.
*/
followers?: EntityReference[];
/**
* Name that uniquely identifies a database in the format 'ServiceName.DatabaseName'.
*/