diff --git a/src/main/java/com/tecknobit/pandoro/controllers/ProjectsController.java b/src/main/java/com/tecknobit/pandoro/controllers/ProjectsController.java index 8d681e6..a36610d 100644 --- a/src/main/java/com/tecknobit/pandoro/controllers/ProjectsController.java +++ b/src/main/java/com/tecknobit/pandoro/controllers/ProjectsController.java @@ -497,7 +497,7 @@ private String manageUpdateStatus(String id, String token, String projectId, Str if (isPublishing) { if (status != IN_DEVELOPMENT) return failedResponse("An update to be published must be IN_DEVELOPMENT first"); - projectsHelper.publishUpdate(projectId, updateId, id); + projectsHelper.publishUpdate(projectId, updateId, id, update.getTargetVersion()); } else { if (status != SCHEDULED) return failedResponse("An update to be published must be SCHEDULED first"); diff --git a/src/main/java/com/tecknobit/pandoro/services/ProjectsHelper.java b/src/main/java/com/tecknobit/pandoro/services/ProjectsHelper.java index e7784eb..9847722 100644 --- a/src/main/java/com/tecknobit/pandoro/services/ProjectsHelper.java +++ b/src/main/java/com/tecknobit/pandoro/services/ProjectsHelper.java @@ -322,9 +322,11 @@ public void startUpdate(String projectId, String updateId, String userId) { * @param projectId: the project identifier * @param updateId: the update identifier * @param userId: the user identifier who publish the update + * @param updateVersion: the version of the update to set as last version of the project */ - public void publishUpdate(String projectId, String updateId, String userId) { + public void publishUpdate(String projectId, String updateId, String userId, String updateVersion) { updatesRepository.publishUpdate(updateId, System.currentTimeMillis(), userId); + projectsRepository.updateProjectVersion(userId, projectId, updateVersion); if (projectsRepository.getProjectById(projectId).hasGroups()) { changelogsCreator.updatePublished(updatesRepository.getUpdateById(projectId, updateId).getTargetVersion(), projectId, userId); diff --git a/src/main/java/com/tecknobit/pandoro/services/repositories/projects/ProjectsRepository.java b/src/main/java/com/tecknobit/pandoro/services/repositories/projects/ProjectsRepository.java index e9f7b1e..3732de0 100644 --- a/src/main/java/com/tecknobit/pandoro/services/repositories/projects/ProjectsRepository.java +++ b/src/main/java/com/tecknobit/pandoro/services/repositories/projects/ProjectsRepository.java @@ -213,6 +213,29 @@ void editProject( @Param(PROJECT_REPOSITORY_KEY) String repository ); + /** + * Method to execute the query to update to the last published update version + * the version of the {@link Project} + * + * @param author: the author of the project + * @param projectId: the project identifier + * @param version: the last version of the project + */ + @Modifying(clearAutomatically = true) + @Transactional + @Query( + value = "UPDATE " + PROJECTS_KEY + " SET " + + PROJECT_VERSION_KEY + "=:" + PROJECT_VERSION_KEY + + " WHERE " + AUTHOR_KEY + "=:" + AUTHOR_KEY + " AND " + + IDENTIFIER_KEY + "=:" + IDENTIFIER_KEY, + nativeQuery = true + ) + void updateProjectVersion( + @Param(AUTHOR_KEY) String author, + @Param(IDENTIFIER_KEY) String projectId, + @Param(PROJECT_VERSION_KEY) String version + ); + /** * Method to execute the query to select an existing {@link Project} *