X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=capifcore%2Finternal%2Fpublishservice%2Fpublishservice.go;h=a4b84f1a106bf081ee0a7d75c2a19eb7aae3a7a6;hb=c01d387b9ff3b5da35e6d9a635523e6747c5b72c;hp=2314039aeacbf5eb42c70471f1daa29ffa3b5238;hpb=0b4c4ecb52b1c04037a65644dc8c6c29981d9736;p=nonrtric%2Fplt%2Fsme.git diff --git a/capifcore/internal/publishservice/publishservice.go b/capifcore/internal/publishservice/publishservice.go index 2314039..a4b84f1 100644 --- a/capifcore/internal/publishservice/publishservice.go +++ b/capifcore/internal/publishservice/publishservice.go @@ -272,7 +272,59 @@ func (ps *PublishService) ModifyIndAPFPubAPI(ctx echo.Context, apfId string, ser // Update a published service API. func (ps *PublishService) PutApfIdServiceApisServiceApiId(ctx echo.Context, apfId string, serviceApiId string) error { - return ctx.NoContent(http.StatusNotImplemented) + ps.lock.Lock() + defer ps.lock.Unlock() + + pos, publishedService, shouldReturn, returnValue := ps.checkIfServiceIsPublished(apfId, serviceApiId, ctx) + if shouldReturn { + return returnValue + } + + updatedServiceDescription, shouldReturn, returnValue := getServiceFromRequest(ctx) + if shouldReturn { + return returnValue + } + + if updatedServiceDescription.Description != nil { + publishedService.Description = updatedServiceDescription.Description + ps.publishedServices[apfId][pos] = publishedService + } + + err := ctx.JSON(http.StatusOK, ps.publishedServices[apfId][pos]) + if err != nil { + // Something really bad happened, tell Echo that our handler failed + return err + } + + return nil +} + +func (ps *PublishService) checkIfServiceIsPublished(apfId string, serviceApiId string, ctx echo.Context) (int, publishapi.ServiceAPIDescription, bool, error) { + + publishedServices, ok := ps.publishedServices[apfId] + if !ok { + return 0, publishapi.ServiceAPIDescription{}, true, sendCoreError(ctx, http.StatusBadRequest, "Service must be published before updating it") + } else { + for pos, description := range publishedServices { + if *description.ApiId == serviceApiId { + return pos, description, false, nil + + } + + } + + } + return 0, publishapi.ServiceAPIDescription{}, true, sendCoreError(ctx, http.StatusBadRequest, "Service must be published before updating it") + +} + +func getServiceFromRequest(ctx echo.Context) (publishapi.ServiceAPIDescription, bool, error) { + var updatedServiceDescription publishapi.ServiceAPIDescription + err := ctx.Bind(&updatedServiceDescription) + if err != nil { + return publishapi.ServiceAPIDescription{}, true, sendCoreError(ctx, http.StatusBadRequest, "Invalid format for service") + } + return updatedServiceDescription, false, nil } // This function wraps sending of an error in the Error format, and