@@ -10,7 +10,6 @@ import (
10
10
11
11
"go.mongodb.org/mongo-driver/bson"
12
12
"go.mongodb.org/mongo-driver/bson/primitive"
13
- "go.mongodb.org/mongo-driver/mongo/options"
14
13
)
15
14
16
15
func submitForm (w http.ResponseWriter , r * http.Request ) {
@@ -67,47 +66,15 @@ func listForm(w http.ResponseWriter, r *http.Request) {
67
66
return
68
67
}
69
68
70
- db := client .Database (conf .Name )
71
-
72
- opt := options .Find ()
73
- opt .SetLimit (100 )
74
- opt .SetSort (bson.M {internal .FieldID : - 1 })
69
+ curDB := client .Database (conf .Name )
75
70
76
- filter := bson.M {}
77
- if fn := r .URL .Query ().Get ("name" ); len (fn ) > 0 {
78
- filter ["form" ] = fn
79
- }
71
+ formName := r .URL .Query ().Get ("name" )
80
72
81
- cur , err := db . Collection ( "sb_forms" ). Find ( context . Background (), filter , opt )
73
+ results , err := internal . ListFormSubmissions ( curDB , formName )
82
74
if err != nil {
83
75
http .Error (w , err .Error (), http .StatusInternalServerError )
84
76
return
85
77
}
86
- defer cur .Close (context .Background ())
87
-
88
- var results []bson.M
89
-
90
- for cur .Next (context .Background ()) {
91
- var result bson.M
92
- err := cur .Decode (& result )
93
- if err != nil {
94
- http .Error (w , err .Error (), http .StatusInternalServerError )
95
- return
96
- }
97
-
98
- result ["id" ] = result ["_id" ]
99
- delete (result , internal .FieldID )
100
-
101
- results = append (results , result )
102
- }
103
- if err := cur .Err (); err != nil {
104
- http .Error (w , err .Error (), http .StatusInternalServerError )
105
- return
106
- }
107
-
108
- if len (results ) == 0 {
109
- results = make ([]bson.M , 1 )
110
- }
111
78
112
79
respond (w , http .StatusOK , results )
113
80
}
0 commit comments