-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MODLISTS-62] Create new list version endpoint
- Loading branch information
1 parent
cd104de
commit fa58a1b
Showing
8 changed files
with
195 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/main/java/org/folio/list/exception/VersionNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.folio.list.exception; | ||
|
||
import java.util.UUID; | ||
import org.folio.list.domain.dto.ListAppError; | ||
import org.folio.list.domain.dto.Parameter; | ||
import org.folio.list.services.ListActions; | ||
import org.springframework.http.HttpStatus; | ||
|
||
public class VersionNotFoundException extends AbstractListException { | ||
|
||
private static final String ERROR_CODE = "version.not.found"; | ||
private static final String ERROR_MESSAGE_TEMPLATE = | ||
"List (id=%s) does not have a version number %d"; | ||
|
||
private final UUID listId; | ||
private final int versionNumber; | ||
private final ListActions failedAction; | ||
private final HttpStatus httpStatus; | ||
|
||
public VersionNotFoundException( | ||
UUID listId, | ||
int versionNumber, | ||
ListActions failedAction | ||
) { | ||
this(listId, versionNumber, failedAction, HttpStatus.NOT_FOUND); | ||
} | ||
|
||
public VersionNotFoundException( | ||
UUID listId, | ||
int versionNumber, | ||
ListActions failedAction, | ||
HttpStatus httpStatus | ||
) { | ||
this.listId = listId; | ||
this.versionNumber = versionNumber; | ||
this.httpStatus = httpStatus; | ||
this.failedAction = failedAction; | ||
} | ||
|
||
@Override | ||
public HttpStatus getHttpStatus() { | ||
return httpStatus; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return String.format(ERROR_MESSAGE_TEMPLATE, listId, versionNumber); | ||
} | ||
|
||
@Override | ||
public ListAppError getError() { | ||
return new ListAppError() | ||
.code(getErrorCode(failedAction, ERROR_CODE)) | ||
.message(getMessage()) | ||
.addParametersItem(new Parameter().key("id").value(listId.toString())) | ||
.addParametersItem( | ||
new Parameter() | ||
.key("versionNumber") | ||
.value(Integer.toString(versionNumber)) | ||
); | ||
} | ||
} |
10 changes: 6 additions & 4 deletions
10
src/main/java/org/folio/list/repository/ListVersionRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
package org.folio.list.repository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import org.folio.list.domain.ListVersion; | ||
import org.springframework.data.repository.CrudRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
@Repository | ||
public interface ListVersionRepository extends CrudRepository<ListVersion, UUID> { | ||
public interface ListVersionRepository | ||
extends CrudRepository<ListVersion, UUID> { | ||
List<ListVersion> findByListId(UUID listId); | ||
Optional<ListVersion> findByListIdAndVersion(UUID listId, int version); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters