Created
August 1, 2020 11:13
Star
You must be signed in to star a gist
Get Image Detail for Image map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ImageMapController { | |
@auraenabled(cacheable=true) | |
public static List<Image__c> getAllImages() | |
{ | |
return [select id,name from Image__c]; | |
} | |
@auraenabled(cacheable=true) | |
public static ImageResponse getImage(string id) | |
{ | |
if(string.isEmpty(id)) | |
{ | |
throw new BaseException('Bad Input'); | |
} | |
List<ContentDocumentLink> links=[SELECT ContentDocumentId,LinkedEntityId FROM ContentDocumentLink where LinkedEntityId=:id]; | |
Set<Id> ids=new Set<Id>(); | |
for(ContentDocumentLink link:links) | |
{ | |
ids.add(link.ContentDocumentId); | |
} | |
List<ContentVersion> versions=[SELECT VersionData,Title,ContentDocumentId,FileExtension FROM ContentVersion WHERE ContentDocumentId = :ids AND IsLatest = true]; | |
List<ContentDistribution> cdts=[select ContentDocumentId,DistributionPublicUrl,ContentDownloadURL from ContentDistribution where ContentDocumentId =:ids]; | |
Map<String, ContentDistribution> contentList= new Map <String, ContentDistribution>(); | |
for(ContentDistribution cdt:cdts) | |
{ | |
contentList.put(cdt.ContentDocumentId, cdt); | |
} | |
List<ImageDetail__c> details=[select Id,Coordinate__c,Shape__c, LinkUrl__c,Detail__c from ImageDetail__c where Image__c=:id]; | |
for(ContentVersion attach:versions) | |
{ | |
ContentDistribution image=contentList.get(attach.ContentDocumentId); | |
if(image!=null) | |
{ | |
ImageResponse response=new ImageResponse(); | |
response.PublicUrl=image.DistributionPublicUrl; | |
response.DownloadableUrl=image.ContentDownloadUrl; | |
response.Details=details; | |
return response; | |
} | |
} | |
return null; | |
} | |
public class ImageResponse | |
{ | |
@auraenabled | |
public string PublicUrl; | |
@auraenabled | |
public string DownloadableUrl; | |
@auraenabled | |
public List<ImageDetail__c> Details; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment