Clean up publish and edit handler and service logic (#319)
Thanks Camila for being a great Go consultant and advising on how to
tidy this up!
(I'm still a lil grumpy about some parts, but it's in much better shape
😄)
- Consolidated publisher extension validation into a single function.
- Updated the `Publish` and `EditServer` methods to directly use
`XPublisher` from the request.
- Removed outdated tests for publisher extension extraction and
validation.
- Introduced new validation functions for server details and remote URL
matching.
- Enhanced error handling for server name format and remote URL
validation.
- Updated existing tests to reflect changes in validation logic and
structure.
## Motivation and Context
<!-- Why is this change needed? What problem does it solve? -->
Things were starting to become a bit spaghetti-y after lots of small PRs
and contributions from many people. Camila and I went through and
figured out how we could make this a lot cleaner.
## How Has This Been Tested?
<!-- Have you tested this in a real application? Which scenarios were
tested? -->
Tested locally, plus all the integration and unit tests still pass.
## Breaking Changes
<!-- Will users need to update their code or configurations? -->
None
---------
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
parent
c0a94cca8c
commit
654cad4aa7
1 changed files with 232 additions and 570 deletions
|
|
@ -114,18 +114,16 @@ func (s *fakeRegistryService) Publish(req apiv0.PublishRequest) (*apiv0.ServerRe
|
|||
defer cancel()
|
||||
|
||||
// Validate the request
|
||||
if err := validators.ValidatePublisherExtensions(req); err != nil {
|
||||
if err := validators.ValidatePublishRequest(req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Validate server name exists
|
||||
if _, err := validators.ParseServerName(req.Server); err != nil {
|
||||
return nil, err
|
||||
// Use publisher extensions directly from request
|
||||
publisherExtensions := req.XPublisher
|
||||
if publisherExtensions == nil {
|
||||
publisherExtensions = make(map[string]interface{})
|
||||
}
|
||||
|
||||
// Extract publisher extensions from request
|
||||
publisherExtensions := validators.ExtractPublisherExtensions(req)
|
||||
|
||||
// Create registry metadata for fake service (always marks as latest)
|
||||
now := time.Now()
|
||||
registryMetadata := apiv0.RegistryExtensions{
|
||||
|
|
@ -152,18 +150,16 @@ func (s *fakeRegistryService) EditServer(id string, req apiv0.PublishRequest) (*
|
|||
defer cancel()
|
||||
|
||||
// Validate the request
|
||||
if err := validators.ValidatePublisherExtensions(req); err != nil {
|
||||
if err := validators.ValidatePublishRequest(req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Validate server name exists and format
|
||||
if _, err := validators.ParseServerName(req.Server); err != nil {
|
||||
return nil, err
|
||||
// Use publisher extensions directly from request
|
||||
publisherExtensions := req.XPublisher
|
||||
if publisherExtensions == nil {
|
||||
publisherExtensions = make(map[string]interface{})
|
||||
}
|
||||
|
||||
// Extract publisher extensions from request
|
||||
publisherExtensions := validators.ExtractPublisherExtensions(req)
|
||||
|
||||
// Update server in database
|
||||
serverRecord, err := s.db.UpdateServer(ctx, id, req.Server, publisherExtensions)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue