@@ -13,6 +13,7 @@ import code.api.util.ErrorMessages.{InsufficientAuthorisationToCreateTransaction
1313import code .api .{APIFailureNewStyle , Constant , JsonResponseException }
1414import code .apicollection .{ApiCollectionTrait , MappedApiCollectionsProvider }
1515import code .apicollectionendpoint .{ApiCollectionEndpointTrait , MappedApiCollectionEndpointsProvider }
16+ import code .featuredapicollection .{FeaturedApiCollectionTrait , MappedFeaturedApiCollectionsProvider }
1617import code .atmattribute .AtmAttribute
1718import code .authtypevalidation .{AuthenticationTypeValidationProvider , JsonAuthTypeValidation }
1819import code .bankattribute .BankAttribute
@@ -3715,11 +3716,35 @@ object NewStyle extends MdcLoggable{
37153716 }
37163717
37173718 def getFeaturedApiCollections (callContext : Option [CallContext ]) : OBPReturnType [List [ApiCollectionTrait ]] = {
3718- // we get the getFeaturedApiCollectionIds from props, and remove the deplication there.
3719- val featuredApiCollectionIds = APIUtil .getPropsValue(" featured_api_collection_ids" ," " ).split(" ," ).map(_.trim).toSet.toList
3720- // We filter the isDefined and is isSharable collections.
3721- val apiCollections = featuredApiCollectionIds.map(MappedApiCollectionsProvider .getApiCollectionById).filter(_.isDefined).filter(_.head.isSharable).map(_.head)
3722- Future {(apiCollections.sortBy(_.apiCollectionName), callContext)}
3719+ // First get featured collections from database, sorted by sortOrder
3720+ val dbFeaturedApiCollections = MappedFeaturedApiCollectionsProvider .getAllFeaturedApiCollections()
3721+ val dbApiCollectionIds = dbFeaturedApiCollections.map(_.apiCollectionId).toSet
3722+
3723+ // Get actual ApiCollections for database featured entries
3724+ val dbApiCollections = dbFeaturedApiCollections
3725+ .map(f => MappedApiCollectionsProvider .getApiCollectionById(f.apiCollectionId))
3726+ .filter(_.isDefined)
3727+ .filter(_.head.isSharable)
3728+ .map(_.head)
3729+
3730+ // Get props-based featured IDs that are NOT in database
3731+ val propsApiCollectionIds = APIUtil .getPropsValue(" featured_api_collection_ids" , " " )
3732+ .split(" ," )
3733+ .map(_.trim)
3734+ .filter(_.nonEmpty)
3735+ .toList
3736+ .filterNot(dbApiCollectionIds.contains)
3737+
3738+ // Get actual ApiCollections for props entries and sort them by name
3739+ val propsApiCollections = propsApiCollectionIds
3740+ .map(MappedApiCollectionsProvider .getApiCollectionById)
3741+ .filter(_.isDefined)
3742+ .filter(_.head.isSharable)
3743+ .map(_.head)
3744+ .sortBy(_.apiCollectionName)
3745+
3746+ // Merge: database entries first (preserve sortOrder), then props entries (sorted by name)
3747+ Future {(dbApiCollections ++ propsApiCollections, callContext)}
37233748 }
37243749
37253750 def createApiCollection (
@@ -3813,6 +3838,69 @@ object NewStyle extends MdcLoggable{
38133838 }
38143839 }
38153840
3841+ // Featured API Collections functions
3842+ def createFeaturedApiCollection (
3843+ apiCollectionId : String ,
3844+ sortOrder : Int ,
3845+ callContext : Option [CallContext ]
3846+ ): OBPReturnType [FeaturedApiCollectionTrait ] = {
3847+ Future (MappedFeaturedApiCollectionsProvider .createFeaturedApiCollection(apiCollectionId, sortOrder)) map {
3848+ i => (unboxFullOrFail(i, callContext, CreateFeaturedApiCollectionError ), callContext)
3849+ }
3850+ }
3851+
3852+ def getFeaturedApiCollectionByApiCollectionId (
3853+ apiCollectionId : String ,
3854+ callContext : Option [CallContext ]
3855+ ): OBPReturnType [FeaturedApiCollectionTrait ] = {
3856+ Future (MappedFeaturedApiCollectionsProvider .getFeaturedApiCollectionByApiCollectionId(apiCollectionId)) map {
3857+ i => (unboxFullOrFail(i, callContext, s " $FeaturedApiCollectionNotFound Current API_COLLECTION_ID( $apiCollectionId) " ), callContext)
3858+ }
3859+ }
3860+
3861+ def getAllFeaturedApiCollectionsAdmin (callContext : Option [CallContext ]): OBPReturnType [List [FeaturedApiCollectionTrait ]] = {
3862+ Future (MappedFeaturedApiCollectionsProvider .getAllFeaturedApiCollections(), callContext)
3863+ }
3864+
3865+ def updateFeaturedApiCollection (
3866+ apiCollectionId : String ,
3867+ sortOrder : Int ,
3868+ callContext : Option [CallContext ]
3869+ ): OBPReturnType [FeaturedApiCollectionTrait ] = {
3870+ Future {
3871+ val featured = MappedFeaturedApiCollectionsProvider .getFeaturedApiCollectionByApiCollectionId(apiCollectionId)
3872+ featured.flatMap { f =>
3873+ MappedFeaturedApiCollectionsProvider .updateFeaturedApiCollection(f.featuredApiCollectionId, sortOrder)
3874+ }
3875+ } map {
3876+ i => (unboxFullOrFail(i, callContext, s " $UpdateFeaturedApiCollectionError Current API_COLLECTION_ID( $apiCollectionId) " ), callContext)
3877+ }
3878+ }
3879+
3880+ def deleteFeaturedApiCollectionByApiCollectionId (
3881+ apiCollectionId : String ,
3882+ callContext : Option [CallContext ]
3883+ ): OBPReturnType [Boolean ] = {
3884+ Future (MappedFeaturedApiCollectionsProvider .deleteFeaturedApiCollectionByApiCollectionId(apiCollectionId)) map {
3885+ i => (unboxFullOrFail(i, callContext, s " $DeleteFeaturedApiCollectionError Current API_COLLECTION_ID( $apiCollectionId) " ), callContext)
3886+ }
3887+ }
3888+
3889+ def checkFeaturedApiCollectionDoesNotExist (
3890+ apiCollectionId : String ,
3891+ callContext : Option [CallContext ]
3892+ ): OBPReturnType [Boolean ] = {
3893+ Future {
3894+ val existing = MappedFeaturedApiCollectionsProvider .getFeaturedApiCollectionByApiCollectionId(apiCollectionId)
3895+ existing match {
3896+ case net.liftweb.common.Full (_) =>
3897+ throw new RuntimeException (FeaturedApiCollectionAlreadyExists )
3898+ case _ =>
3899+ (true , callContext)
3900+ }
3901+ }
3902+ }
3903+
38163904 def createJsonSchemaValidation (validation : JsonValidation , callContext : Option [CallContext ]): OBPReturnType [JsonValidation ] =
38173905 Future {
38183906 val newValidation = JsonSchemaValidationProvider .validationProvider.vend.create(validation)
0 commit comments