Collection book list: allow to directly input a position
This commit is contained in:
@@ -52,6 +52,7 @@ func TestPostCollectionChangePositionHandler_LastPosition(t *testing.T) {
|
||||
_, collection := testGetCollection(t, collectionId, "10", "0")
|
||||
assert.Equal(t, "Recherches philosophiques", collection.Items[7].Book.Title)
|
||||
assert.Equal(t, "Le château", collection.Items[6].Book.Title)
|
||||
assert.Equal(t, uint(8), collection.Items[7].Position)
|
||||
}
|
||||
|
||||
func TestPostCollectionChangePositionHandler_FirstPosition(t *testing.T) {
|
||||
|
||||
@@ -76,7 +76,7 @@ func PostCollectionChangePositionHandler(ac appcontext.AppContext) {
|
||||
newPosition = uint(count)
|
||||
}
|
||||
|
||||
if item.Position == collectionBookPosition.Position {
|
||||
if item.Position == newPosition {
|
||||
//nothing to do
|
||||
ac.C.String(http.StatusOK, "Success")
|
||||
return
|
||||
@@ -84,11 +84,11 @@ func PostCollectionChangePositionHandler(ac appcontext.AppContext) {
|
||||
lowerPosition := item.Position + 1
|
||||
higherPosition := item.Position - 1
|
||||
operationToDo := ""
|
||||
if item.Position < collectionBookPosition.Position {
|
||||
higherPosition = collectionBookPosition.Position
|
||||
if item.Position < newPosition {
|
||||
higherPosition = newPosition
|
||||
operationToDo = "position - 1"
|
||||
} else {
|
||||
lowerPosition = collectionBookPosition.Position
|
||||
lowerPosition = newPosition
|
||||
operationToDo = "position + 1"
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ func PostCollectionChangePositionHandler(ac appcontext.AppContext) {
|
||||
return
|
||||
}
|
||||
|
||||
item.Position = collectionBookPosition.Position
|
||||
item.Position = newPosition
|
||||
ac.Db.Save(&item)
|
||||
ac.C.String(http.StatusOK, "Success")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user