mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-12 00:34:13 +01:00
API: Refactor /batch/photos/edit endpoint to return "models" #271
The "photos" array in the response has been renamed to "models". This data is now always returned, so using the "return" flag in the request is no longer necessary. Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
@@ -76,18 +76,11 @@ func BatchPhotosEdit(router *gin.RouterGroup) {
|
||||
// Create batch edit form values form from photo metadata.
|
||||
batchFrm := batch.NewPhotosForm(photos)
|
||||
|
||||
var data gin.H
|
||||
|
||||
if frm.Return {
|
||||
data = gin.H{
|
||||
"photos": photos,
|
||||
// Return models and form values.
|
||||
data := gin.H{
|
||||
"models": photos,
|
||||
"values": batchFrm,
|
||||
}
|
||||
} else {
|
||||
data = gin.H{
|
||||
"values": batchFrm,
|
||||
}
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, data)
|
||||
})
|
||||
|
||||
@@ -27,12 +27,12 @@ func TestBatchPhotosEdit(t *testing.T) {
|
||||
body := response.Body.String()
|
||||
|
||||
assert.NotEmpty(t, body)
|
||||
assert.True(t, strings.HasPrefix(body, `{"values":{"`), "unexpected response")
|
||||
assert.True(t, strings.HasPrefix(body, `{"models":[{"ID"`), "unexpected response")
|
||||
|
||||
// fmt.Println(body)
|
||||
/* photos := gjson.Get(body, "photos")
|
||||
/* models := gjson.Get(body, "models")
|
||||
values := gjson.Get(body, "values")
|
||||
t.Logf("photos: %#v", photos)
|
||||
t.Logf("models: %#v", models)
|
||||
t.Logf("values: %#v", values) */
|
||||
|
||||
assert.Equal(t, http.StatusOK, response.Code)
|
||||
@@ -52,12 +52,12 @@ func TestBatchPhotosEdit(t *testing.T) {
|
||||
body := response.Body.String()
|
||||
|
||||
assert.NotEmpty(t, body)
|
||||
assert.True(t, strings.HasPrefix(body, `{"photos":[{"ID"`), "unexpected response")
|
||||
assert.True(t, strings.HasPrefix(body, `{"models":[{"ID"`), "unexpected response")
|
||||
|
||||
fmt.Println(body)
|
||||
/* photos := gjson.Get(body, "photos")
|
||||
/* models := gjson.Get(body, "models")
|
||||
values := gjson.Get(body, "values")
|
||||
t.Logf("photos: %#v", photos)
|
||||
t.Logf("models: %#v", models)
|
||||
t.Logf("values: %#v", values) */
|
||||
|
||||
assert.Equal(t, http.StatusOK, response.Code)
|
||||
@@ -95,7 +95,7 @@ func TestBatchPhotosEdit(t *testing.T) {
|
||||
body := response.Body.String()
|
||||
|
||||
assert.NotEmpty(t, body)
|
||||
assert.True(t, strings.HasPrefix(body, `{"values":{"`), "unexpected response")
|
||||
assert.True(t, strings.HasPrefix(body, `{"models":[{"ID"`), "unexpected response")
|
||||
|
||||
assert.Equal(t, http.StatusOK, response.Code)
|
||||
})
|
||||
|
||||
@@ -5,7 +5,6 @@ import "strings"
|
||||
// PhotosRequest represents items selected in the user interface.
|
||||
type PhotosRequest struct {
|
||||
Photos []string `json:"photos"`
|
||||
Return bool `json:"return,omitempty"`
|
||||
Values *PhotosForm `json:"values,omitempty"`
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ func TestPhotosRequest_Empty(t *testing.T) {
|
||||
t.Run("False", func(t *testing.T) {
|
||||
req := PhotosRequest{
|
||||
Photos: []string{"ps6sg6be2lvl0yh7", "ps6sg6be2lvl0yh0"},
|
||||
Return: true,
|
||||
Values: &PhotosForm{},
|
||||
}
|
||||
|
||||
@@ -19,7 +18,6 @@ func TestPhotosRequest_Empty(t *testing.T) {
|
||||
t.Run("True", func(t *testing.T) {
|
||||
req := PhotosRequest{
|
||||
Photos: []string{},
|
||||
Return: true,
|
||||
Values: &PhotosForm{},
|
||||
}
|
||||
|
||||
@@ -30,7 +28,6 @@ func TestPhotosRequest_Empty(t *testing.T) {
|
||||
func TestPhotosRequest_Get(t *testing.T) {
|
||||
req := PhotosRequest{
|
||||
Photos: []string{"ps6sg6be2lvl0yh7", "ps6sg6be2lvl0yh0"},
|
||||
Return: true,
|
||||
Values: &PhotosForm{},
|
||||
}
|
||||
|
||||
@@ -41,7 +38,6 @@ func TestPhotosRequest_Get(t *testing.T) {
|
||||
func TestPhotosRequest_String(t *testing.T) {
|
||||
req := PhotosRequest{
|
||||
Photos: []string{"ps6sg6be2lvl0yh7", "ps6sg6be2lvl0yh0"},
|
||||
Return: true,
|
||||
Values: &PhotosForm{},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user