@@ -152,6 +152,72 @@ func (a appShared) hasAttendedEvent(orgID string, appID string, eventID string,
152
152
return false , nil
153
153
}
154
154
155
+ func (a appShared ) getUserData (orgID string , appID string , userID * string ) (* model.UserData , error ) {
156
+ var serveyUserData []model.SurveysUserData
157
+ var surveyResponseUserData []model.SurveysResponseUserData
158
+
159
+ // Create channels for data and error handling
160
+ surveysChan := make (chan []model.Survey , 1 )
161
+ surveysErrChan := make (chan error , 1 )
162
+ surveyResponsesChan := make (chan []model.SurveyResponse , 1 )
163
+ surveyResponsesErrChan := make (chan error , 1 )
164
+
165
+ // Fetch surveys asynchronously
166
+ go func () {
167
+ surveys , err := a .app .storage .GetSurveysLight (orgID , appID , userID )
168
+ if err != nil {
169
+ surveysErrChan <- err
170
+ return
171
+ }
172
+ surveysChan <- surveys
173
+ }()
174
+
175
+ // Fetch survey responses asynchronously
176
+ go func () {
177
+ surveysResponses , err := a .app .storage .GetSurveyResponses (& orgID , & appID , userID , nil , nil , nil , nil , nil , nil )
178
+ if err != nil {
179
+ surveyResponsesErrChan <- err
180
+ return
181
+ }
182
+ surveyResponsesChan <- surveysResponses
183
+ }()
184
+
185
+ // Wait for both operations to complete or return an error
186
+ var surveys []model.Survey
187
+ var surveysResponses []model.SurveyResponse
188
+
189
+ for i := 0 ; i < 2 ; i ++ {
190
+ select {
191
+ case err := <- surveysErrChan :
192
+ return nil , err
193
+ case err := <- surveyResponsesErrChan :
194
+ return nil , err
195
+ case surveys = <- surveysChan :
196
+ // Handle the surveys data when received
197
+ case surveysResponses = <- surveyResponsesChan :
198
+ // Handle the survey responses data when received
199
+ }
200
+ }
201
+
202
+ // Process the surveys data
203
+ for _ , s := range surveys {
204
+ survey := model.SurveysUserData {ID : s .ID , CreatorID : s .CreatorID , AppID : s .AppID , AccountID : s .CreatorID ,
205
+ OrgID : s .OrgID , Title : s .Title , Type : s .Type }
206
+ serveyUserData = append (serveyUserData , survey )
207
+ }
208
+
209
+ // Process the survey responses data
210
+ for _ , sr := range surveysResponses {
211
+ surveyResponse := model.SurveysResponseUserData {ID : sr .ID , UserID : sr .UserID , AppID : sr .AppID , AccountID : sr .UserID ,
212
+ OrgID : sr .OrgID , Title : sr .Survey .Title }
213
+ surveyResponseUserData = append (surveyResponseUserData , surveyResponse )
214
+ }
215
+
216
+ // Return the user data after all data has been fetched and processed
217
+ userData := model.UserData {SurveyUserData : & serveyUserData , SurveyResponseUserData : & surveyResponseUserData }
218
+ return & userData , nil
219
+ }
220
+
155
221
// newAppShared creates new appShared
156
222
func newAppShared (app * Application ) appShared {
157
223
return appShared {app : app }
0 commit comments