X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=capifcore%2Finternal%2Fpublishservice%2Fpublishservice.go;h=a267acfd242cabfd861bf33ac5aa31e043cd4da5;hb=36718abc0fb386770a182c2c01358e1ce3621c75;hp=54a7f675d2e30f82588e94c85ba0a8ad5aa0f50e;hpb=317d9716840650fbf1ebea4fc84bcdb6e8ffab76;p=nonrtric%2Fplt%2Fsme.git diff --git a/capifcore/internal/publishservice/publishservice.go b/capifcore/internal/publishservice/publishservice.go index 54a7f67..a267acf 100644 --- a/capifcore/internal/publishservice/publishservice.go +++ b/capifcore/internal/publishservice/publishservice.go @@ -121,16 +121,28 @@ func join(a, b []publishapi.ServiceAPIDescription) []publishapi.ServiceAPIDescri // Retrieve all published APIs. func (ps *PublishService) GetApfIdServiceApis(ctx echo.Context, apfId string) error { - if !ps.serviceRegister.IsPublishingFunctionRegistered(apfId) { - errorMsg := fmt.Sprintf("Unable to get the service due to %s api is only available for publishers", apfId) - return sendCoreError(ctx, http.StatusNotFound, errorMsg) - } + ps.lock.Lock() + serviceDescriptions, ok := ps.publishedServices[apfId] + ps.lock.Unlock() - serviceDescriptions := ps.publishedServices[apfId] - err := ctx.JSON(http.StatusOK, serviceDescriptions) - if err != nil { - // Something really bad happened, tell Echo that our handler failed - return err + if ok { + err := ctx.JSON(http.StatusOK, serviceDescriptions) + if err != nil { + // Something really bad happened, tell Echo that our handler failed + return err + } + } else { + if !ps.serviceRegister.IsPublishingFunctionRegistered(apfId) { + errorMsg := fmt.Sprintf("Unable to get the service due to %s api is only available for publishers", apfId) + return sendCoreError(ctx, http.StatusNotFound, errorMsg) + } + + serviceDescriptions = []publishapi.ServiceAPIDescription{} + err := ctx.JSON(http.StatusOK, serviceDescriptions) + if err != nil { + // Something really bad happened, tell Echo that our handler failed + return err + } } return nil }