Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get Composite Modification endpoint #541

Merged
merged 15 commits into from
Nov 13, 2024

Conversation

Mathieu-Deharbe
Copy link
Contributor

No description provided.

@Mathieu-Deharbe Mathieu-Deharbe changed the title draft get Composite Modification endpoint get Composite Modification endpoint Oct 24, 2024
@GetMapping(value = "/network-composite-modification/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Get the content of a composite modification via its id")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Content of the composite modification"),
@ApiResponse(responseCode = "404", description = "This composite modification does not exist")}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

404 code is for not found response
for readability reasons I suggest
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Content of the composite modification"), @ApiResponse(responseCode = "404", description = "Composite modification not found") })

If the id is not found in the database, an exception should be thrown by networkModificationService
Currently, it returns 200 OK even if the id doesn’t exist !...
fix it (with try-catch or another solution)

Copy link
Contributor Author

@Mathieu-Deharbe Mathieu-Deharbe Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Message changed. Remobved that 404.

@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Content of the composite modification"),
@ApiResponse(responseCode = "404", description = "This composite modification does not exist")}
)
public ResponseEntity<List<ModificationInfos>> getCompositeModificationContent(@PathVariable("id") UUID compositeModificationId) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PathVariable(value = "id", required = true) UUID compositeModificationId

to ensure that the id is mandatory

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For PathVariable boolean required() default true

If I add a true, intellij calls it a redundant parameter.

@@ -220,6 +220,18 @@ public ResponseEntity<UUID> createNetworkCompositeModification(@RequestBody List
return ResponseEntity.ok().body(networkModificationService.createNetworkCompositeModification(modificationUuids));
}

@GetMapping(value = "/network-composite-modification/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Get the content of a composite modification via its id")
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Content of the composite modification"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Content is not clear enough and it is generic description
maybe "The modifications list of the composite"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of updated all of this to be closer to @GetMapping(value = "/groups/{groupUuid}/network-modifications", produces = MediaType.APPLICATION_JSON_VALUE)

I think it was clearer that my previous endpoint.

public ResponseEntity<List<ModificationInfos>> getCompositeModificationContent(@PathVariable("id") UUID compositeModificationId) {
return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_JSON)
.body(networkModificationService.getCompositeModificationContentMetadata(compositeModificationId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metadata ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed getNetworkModificationsFromComposite

I am still not very satisfied of it, but still better than metadata indeed.

@Transactional(readOnly = true)
public List<ModificationInfos> getCompositeModificationsInfos(@NonNull List<UUID> uuids) {
public List<ModificationInfos> getCompositeModificationsContentInfos(@NonNull List<UUID> uuids, boolean onlyCommonData) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need to rename this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok but I don't think this is a good name : it sounds like we are getting the infos of the composite modifications but we are not. We get the infos of the network modifications that are inside the composite modifications and don't get those of the composite modifications themselves.

It sent me in the wrong direction when I was looking at functions.

@@ -394,15 +394,28 @@ public List<ModificationInfos> getModificationsInfos(@NonNull List<UUID> uuids)
return uuids.stream().map(entities::get).filter(Objects::nonNull).map(this::getModificationInfos).toList();
}

/**
* @param onlyCommonData if true, only returns the basic data common to all the modifications. If false, returns complete modifications
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain the basic of the data and what do you mean by onlyCommonData?
It doesn't make sense to me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the network modifications use the ModificationInfos. The data inside this class is the common data to all the network modifications.

But they also have specific data extending this data like BatteryModificationInfos or LineCreationInfos.

.stream()
.map(this::getModificationInfo)
.toList();
List<UUID> networkModificationsUuids = modificationRepository.findModificationIdsByCompositeModificationId(uuid);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

foundEntities

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean renaming networkModificationsUuids ? But those are not entities.

List<UUID> networkModificationsUuids = modificationRepository.findModificationIdsByCompositeModificationId(uuid);
List<ModificationInfos> orderedModifications;
if (onlyCommonData) {
List<ModificationEntity> networkModifications = modificationRepository.findBaseDataByIdIn(networkModificationsUuids);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

networkModificationsEntities

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

.stream()
.map(this::getModificationInfo)
.toList();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

 if (uuids.isEmpty()) {
            return Collections.emptyList(); 
        }
            

and we can do better by fetching all modification uuids in one go like

 .collect(Collectors.toMap(
                        uuid -> uuid,
                        modificationRepository::findModificationIdsByCompositeModificationId));
            }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand, but I completely changed this funciton anyway so I don't think this is still needed.

.stream()
.map(this::getModificationInfo)
.toList();
}
entities.addAll(orderedModifications);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (UUID uuid : uuids) {
            List<UUID> networkModificationsUuids = networkModificationsMap.get(uuid);
            if (onlyMetadata) {
                List<ModificationEntity> networkModifications = modificationRepository.findBaseDataByIdIn(networkModificationsUuids);
                entities.addAll(networkModifications.stream()
                        .map(this::getModificationInfos)
                        .toList());
            } else {
                entities.addAll(networkModificationsUuids.stream()
                        .map(this::getModificationInfo)
                        .toList());
            }
        }

        return Collections.unmodifiableList(entities); 
        }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same answer than the previous comment.

@@ -220,6 +220,18 @@ public ResponseEntity<UUID> createNetworkCompositeModification(@RequestBody List
return ResponseEntity.ok().body(networkModificationService.createNetworkCompositeModification(modificationUuids));
}

@GetMapping(value = "/network-composite-modification/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@GetMapping(value = "/network-composite-modification/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
@GetMapping(value = "/network-composite-modification/{uuid}", produces = MediaType.APPLICATION_JSON_VALUE)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK done and updated with a /network-modifications. I think this is clearer.

@Transactional(readOnly = true)
public List<ModificationInfos> getCompositeModificationsInfos(@NonNull List<UUID> uuids) {
public List<ModificationInfos> getCompositeModificationsContentInfos(@NonNull List<UUID> uuids, boolean onlyCommonData) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this method should return wether a list of modification base infos or a modification full infos. You could rather implement 2 two methods

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it gets too confusing. I separated them.

Signed-off-by: Mathieu DEHARBE <[email protected]>
@Mathieu-Deharbe Mathieu-Deharbe merged commit 4276dda into main Nov 13, 2024
3 checks passed
@Mathieu-Deharbe Mathieu-Deharbe deleted the get-composite-modification-content branch November 13, 2024 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants