diff --git a/CHANGELOG.md b/CHANGELOG.md index 05fd5a9..c5d18a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [1.6.0] - 2024-007-23 +### Added +- Archived flag [#40](https://github.com/rokwire/surveys-building-block/issues/40) +### Added +- Public flag [#37](https://github.com/rokwire/surveys-building-block/issues/37) +### Added +- Add extras field to survey data [#39](https://github.com/rokwire/surveys-building-block/issues/39) +### Fixed +- Fix "start_date" and "end_date" [#43](https://github.com/rokwire/surveys-building-block/issues/43) + ## [1.5.0] - 2024-007-22 ### Added - Start/end date [#38](https://github.com/rokwire/surveys-building-block/issues/38) diff --git a/SECURITY.md b/SECURITY.md index e64ab2a..ac399f1 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -6,8 +6,8 @@ Patches for **Surveys Building Block** in this repository will only be applied t | Version | Supported | | ------- | ------------------ | -| 1.5.0 | :white_check_mark: | -| < 1.5.0 | :x: | +| 1.6.0 | :white_check_mark: | +| < 1.6.0 | :x: | ## Reporting a Bug or Vulnerability diff --git a/core/app_admin.go b/core/app_admin.go index daa39ed..1b97152 100644 --- a/core/app_admin.go +++ b/core/app_admin.go @@ -37,8 +37,8 @@ func (a appAdmin) GetSurvey(id string, orgID string, appID string) (*model.Surve } // GetSurvey returns surveys matching the provided query -func (a appAdmin) GetSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, filter *model.SurveyTimeFilter) ([]model.Survey, error) { - return a.app.shared.getSurveys(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter) +func (a appAdmin) GetSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, filter *model.SurveyTimeFilter, public *bool, archived *bool) ([]model.Survey, error) { + return a.app.shared.getSurveys(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter, public, archived) } // GetAllSurveyResponses returns survey responses matching the provided query diff --git a/core/app_client.go b/core/app_client.go index 283897f..51e4e50 100644 --- a/core/app_client.go +++ b/core/app_client.go @@ -36,8 +36,8 @@ func (a appClient) GetSurvey(id string, orgID string, appID string) (*model.Surv // GetSurvey returns surveys matching the provided query func (a appClient) GetSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, - limit *int, offset *int, filter *model.SurveyTimeFilter) ([]model.Survey, error) { - return a.app.shared.getSurveys(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter) + limit *int, offset *int, filter *model.SurveyTimeFilter, public *bool, archived *bool) ([]model.Survey, error) { + return a.app.shared.getSurveys(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter, public, archived) } // CreateSurvey creates a new survey diff --git a/core/app_shared.go b/core/app_shared.go index 58915c3..f6fc596 100644 --- a/core/app_shared.go +++ b/core/app_shared.go @@ -34,8 +34,8 @@ func (a appShared) getSurvey(id string, orgID string, appID string) (*model.Surv return a.app.storage.GetSurvey(id, orgID, appID) } -func (a appShared) getSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, filter *model.SurveyTimeFilter) ([]model.Survey, error) { - return a.app.storage.GetSurveys(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter) +func (a appShared) getSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, filter *model.SurveyTimeFilter, public *bool, archived *bool) ([]model.Survey, error) { + return a.app.storage.GetSurveys(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter, public, archived) } func (a appShared) createSurvey(survey model.Survey, externalIDs map[string]string) (*model.Survey, error) { diff --git a/core/interfaces.go b/core/interfaces.go index b5d54c0..159fd3f 100644 --- a/core/interfaces.go +++ b/core/interfaces.go @@ -20,7 +20,7 @@ import "application/core/model" type Shared interface { // Surveys getSurvey(id string, orgID string, appID string) (*model.Survey, error) - getSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, filter *model.SurveyTimeFilter) ([]model.Survey, error) + getSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, filter *model.SurveyTimeFilter, public *bool, archived *bool) ([]model.Survey, error) createSurvey(survey model.Survey, externalIDs map[string]string) (*model.Survey, error) updateSurvey(survey model.Survey, userID string, externalIDs map[string]string, admin bool) error deleteSurvey(id string, orgID string, appID string, userID string, externalIDs map[string]string, admin bool) error diff --git a/core/interfaces/core.go b/core/interfaces/core.go index b7bc8e4..f5d18c5 100644 --- a/core/interfaces/core.go +++ b/core/interfaces/core.go @@ -30,7 +30,7 @@ type Default interface { type Client interface { // Surveys GetSurvey(id string, orgID string, appID string) (*model.Survey, error) - GetSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, filter *model.SurveyTimeFilter) ([]model.Survey, error) + GetSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, filter *model.SurveyTimeFilter, public *bool, archived *bool) ([]model.Survey, error) CreateSurvey(survey model.Survey, externalIDs map[string]string) (*model.Survey, error) UpdateSurvey(survey model.Survey, userID string, externalIDs map[string]string) error DeleteSurvey(id string, orgID string, appID string, userID string, externalIDs map[string]string) error @@ -59,7 +59,7 @@ type Admin interface { // Surveys GetSurvey(id string, orgID string, appID string) (*model.Survey, error) - GetSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, filter *model.SurveyTimeFilter) ([]model.Survey, error) + GetSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, filter *model.SurveyTimeFilter, public *bool, archived *bool) ([]model.Survey, error) CreateSurvey(survey model.Survey, externalIDs map[string]string) (*model.Survey, error) UpdateSurvey(survey model.Survey, userID string, externalIDs map[string]string) error DeleteSurvey(id string, orgID string, appID string, userID string, externalIDs map[string]string) error diff --git a/core/interfaces/driven.go b/core/interfaces/driven.go index 8922e88..db88dc3 100644 --- a/core/interfaces/driven.go +++ b/core/interfaces/driven.go @@ -33,7 +33,7 @@ type Storage interface { DeleteConfig(id string) error GetSurvey(id string, orgID string, appID string) (*model.Survey, error) - GetSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, filter *model.SurveyTimeFilter) ([]model.Survey, error) + GetSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, filter *model.SurveyTimeFilter, public *bool, archived *bool) ([]model.Survey, error) CreateSurvey(survey model.Survey) (*model.Survey, error) UpdateSurvey(survey model.Survey, admin bool) error DeleteSurvey(id string, orgID string, appID string, creatorID string, admin bool) error diff --git a/core/interfaces/mocks/Storage.go b/core/interfaces/mocks/Storage.go index c1dc2c7..266a3fe 100644 --- a/core/interfaces/mocks/Storage.go +++ b/core/interfaces/mocks/Storage.go @@ -503,9 +503,9 @@ func (_m *Storage) GetSurveyResponses(orgID *string, appID *string, userID *stri return r0, r1 } -// GetSurveys provides a mock function with given fields: orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter -func (_m *Storage) GetSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, filter *model.SurveyTimeFilter) ([]model.Survey, error) { - ret := _m.Called(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter) +// GetSurveys provides a mock function with given fields: orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter, public, archived +func (_m *Storage) GetSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, filter *model.SurveyTimeFilter, public *bool, archived *bool) ([]model.Survey, error) { + ret := _m.Called(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter, public, archived) if len(ret) == 0 { panic("no return value specified for GetSurveys") @@ -513,19 +513,19 @@ func (_m *Storage) GetSurveys(orgID string, appID string, creatorID *string, sur var r0 []model.Survey var r1 error - if rf, ok := ret.Get(0).(func(string, string, *string, []string, []string, string, *int, *int, *model.SurveyTimeFilter) ([]model.Survey, error)); ok { - return rf(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter) + if rf, ok := ret.Get(0).(func(string, string, *string, []string, []string, string, *int, *int, *model.SurveyTimeFilter, *bool, *bool) ([]model.Survey, error)); ok { + return rf(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter, public, archived) } - if rf, ok := ret.Get(0).(func(string, string, *string, []string, []string, string, *int, *int, *model.SurveyTimeFilter) []model.Survey); ok { - r0 = rf(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter) + if rf, ok := ret.Get(0).(func(string, string, *string, []string, []string, string, *int, *int, *model.SurveyTimeFilter, *bool, *bool) []model.Survey); ok { + r0 = rf(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter, public, archived) } else { if ret.Get(0) != nil { r0 = ret.Get(0).([]model.Survey) } } - if rf, ok := ret.Get(1).(func(string, string, *string, []string, []string, string, *int, *int, *model.SurveyTimeFilter) error); ok { - r1 = rf(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter) + if rf, ok := ret.Get(1).(func(string, string, *string, []string, []string, string, *int, *int, *model.SurveyTimeFilter, *bool, *bool) error); ok { + r1 = rf(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter, public, archived) } else { r1 = ret.Error(1) } diff --git a/core/model/surveys.go b/core/model/surveys.go index 00d091a..f73c3ff 100644 --- a/core/model/surveys.go +++ b/core/model/surveys.go @@ -63,8 +63,10 @@ type Survey struct { DateCreated time.Time `json:"date_created" bson:"date_created"` DateUpdated *time.Time `json:"date_updated" bson:"date_updated"` CalendarEventID string `json:"calendar_event_id" bson:"calendar_event_id"` - StartDate time.Time `json:"start_date" bson:"start_date"` + StartDate *time.Time `json:"start_date" bson:"start_date"` EndDate *time.Time `json:"end_date" bson:"end_date"` + Public *bool `json:"public" bson:"public"` + Archived *bool `json:"archived" bson:"archived"` } // SurveyResponseAnonymous represents an anonymized survey response @@ -92,17 +94,18 @@ type SurveyStats struct { // SurveyData is data stored for a Survey type SurveyData struct { - Section *string `json:"section,omitempty" bson:"section,omitempty"` - Sections []string `json:"sections,omitempty" bson:"sections,omitempty"` - AllowSkip bool `json:"allow_skip" bson:"allow_skip"` - Text string `json:"text" bson:"text"` - MoreInfo string `json:"more_info" bson:"more_info"` - DefaultFollowUpKey *string `json:"default_follow_up_key" bson:"default_follow_up_key"` - DefaultResponseRule *string `json:"default_response_rule" bson:"default_response_rule"` - FollowUpRule *string `json:"follow_up_rule" bson:"follow_up_rule"` - ScoreRule *string `json:"score_rule" bson:"score_rule"` - Replace bool `json:"replace" bson:"replace"` - Response interface{} `json:"response" bson:"response"` + Section *string `json:"section,omitempty" bson:"section,omitempty"` + Sections []string `json:"sections,omitempty" bson:"sections,omitempty"` + AllowSkip bool `json:"allow_skip" bson:"allow_skip"` + Text string `json:"text" bson:"text"` + MoreInfo string `json:"more_info" bson:"more_info"` + DefaultFollowUpKey *string `json:"default_follow_up_key" bson:"default_follow_up_key"` + DefaultResponseRule *string `json:"default_response_rule" bson:"default_response_rule"` + FollowUpRule *string `json:"follow_up_rule" bson:"follow_up_rule"` + ScoreRule *string `json:"score_rule" bson:"score_rule"` + Replace bool `json:"replace" bson:"replace"` + Response interface{} `json:"response" bson:"response"` + Extras *map[string]interface{} `json:"extras" bson:"extras"` Type string `json:"type" bson:"type"` @@ -193,8 +196,10 @@ type SurveyRequest struct { DateCreated time.Time `json:"date_created" bson:"date_created"` DateUpdated *time.Time `json:"date_updated" bson:"date_updated"` CalendarEventID string `json:"calendar_event_id" bson:"calendar_event_id"` - StartDate int64 `json:"start_date" bson:"start_date"` + StartDate *int64 `json:"start_date" bson:"start_date"` EndDate *int64 `json:"end_date" bson:"end_date"` + Public *bool `json:"public" bson:"public"` + Archived *bool `json:"archived" bson:"archived"` } // SurveyTimeFilter wraps the time filter for surveys diff --git a/driven/storage/adapter_surveys.go b/driven/storage/adapter_surveys.go index b1fb97b..ed104d2 100644 --- a/driven/storage/adapter_surveys.go +++ b/driven/storage/adapter_surveys.go @@ -37,7 +37,7 @@ func (a *Adapter) GetSurvey(id string, orgID string, appID string) (*model.Surve } // GetSurveys gets matching surveys -func (a *Adapter) GetSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, timeFilter *model.SurveyTimeFilter) ([]model.Survey, error) { +func (a *Adapter) GetSurveys(orgID string, appID string, creatorID *string, surveyIDs []string, surveyTypes []string, calendarEventID string, limit *int, offset *int, timeFilter *model.SurveyTimeFilter, public *bool, archived *bool) ([]model.Survey, error) { filter := bson.D{ {Key: "org_id", Value: orgID}, {Key: "app_id", Value: appID}, @@ -70,6 +70,14 @@ func (a *Adapter) GetSurveys(orgID string, appID string, creatorID *string, surv filter = append(filter, primitive.E{Key: "end_date", Value: primitive.M{"$lte": *timeFilter.EndTimeBefore}}) } + if public != nil { + filter = append(filter, bson.E{Key: "public", Value: public}) + } + + if archived != nil { + filter = append(filter, bson.E{Key: "archived", Value: archived}) + } + opts := options.Find() if limit != nil { opts.SetLimit(int64(*limit)) @@ -131,6 +139,8 @@ func (a *Adapter) UpdateSurvey(survey model.Survey, admin bool) error { "sub_rules": survey.SubRules, "start_date": survey.StartDate, "end_date": survey.EndDate, + "public": survey.Public, + "archived": survey.Archived, "date_updated": now, }} diff --git a/driver/web/apis_admin.go b/driver/web/apis_admin.go index 2d7cadb..6ffcfa6 100644 --- a/driver/web/apis_admin.go +++ b/driver/web/apis_admin.go @@ -21,6 +21,7 @@ import ( "io/ioutil" "log" "net/http" + "sort" "strconv" "strings" "time" @@ -233,12 +234,40 @@ func (h AdminAPIsHandler) getSurveys(l *logs.Log, r *http.Request, claims *token } offset = intParsed } + publicStr := r.URL.Query().Get("public") - resData, err := h.app.Admin.GetSurveys(claims.OrgID, claims.AppID, nil, surveyIDs, surveyTypes, calendarEventID, &limit, &offset, filter) + var public *bool + + if publicStr != "" { + value, err := strconv.ParseBool(publicStr) + if err != nil { + return l.HTTPResponseErrorAction(logutils.ActionGet, model.TypeSurvey, nil, err, http.StatusInternalServerError, true) + } + public = &value + } + archivedStr := r.URL.Query().Get("archived") + + var archived *bool + + if archivedStr != "" { + valueArchived, err := strconv.ParseBool(archivedStr) + if err != nil { + return l.HTTPResponseErrorAction(logutils.ActionGet, model.TypeSurvey, nil, err, http.StatusInternalServerError, true) + } + archived = &valueArchived + } + + resData, err := h.app.Admin.GetSurveys(claims.OrgID, claims.AppID, nil, surveyIDs, surveyTypes, calendarEventID, &limit, &offset, filter, public, archived) if err != nil { return l.HTTPResponseErrorAction(logutils.ActionGet, model.TypeSurvey, nil, err, http.StatusInternalServerError, true) } + surveys := surveysToSurveyRequests(resData) + + sort.Slice(surveys, func(i, j int) bool { + return surveys[i].DateCreated.After(surveys[j].DateCreated) + }) + rdata, err := json.Marshal(resData) if err != nil { return l.HTTPResponseErrorAction(logutils.ActionMarshal, logutils.TypeResponseBody, nil, err, http.StatusInternalServerError, false) diff --git a/driver/web/apis_client.go b/driver/web/apis_client.go index f6788dd..a116b2b 100644 --- a/driver/web/apis_client.go +++ b/driver/web/apis_client.go @@ -21,6 +21,7 @@ import ( "io/ioutil" "log" "net/http" + "sort" "strconv" "strings" "time" @@ -108,13 +109,43 @@ func (h ClientAPIsHandler) getSurveys(l *logs.Log, r *http.Request, claims *toke offset = intParsed } + publicStr := r.URL.Query().Get("public") + + var public *bool + + if publicStr != "" { + value, err := strconv.ParseBool(publicStr) + if err != nil { + return l.HTTPResponseErrorAction(logutils.ActionGet, model.TypeSurvey, nil, err, http.StatusInternalServerError, true) + } + public = &value + } + + archivedStr := r.URL.Query().Get("archived") + + var archived *bool + + if archivedStr != "" { + valueArchived, err := strconv.ParseBool(archivedStr) + if err != nil { + return l.HTTPResponseErrorAction(logutils.ActionGet, model.TypeSurvey, nil, err, http.StatusInternalServerError, true) + } + archived = &valueArchived + } + resData, err := h.app.Client.GetSurveys(claims.OrgID, claims.AppID, nil, surveyIDs, surveyTypes, calendarEventID, - &limit, &offset, filter) + &limit, &offset, filter, public, archived) if err != nil { return l.HTTPResponseErrorAction(logutils.ActionGet, model.TypeSurvey, nil, err, http.StatusInternalServerError, true) } - rdata, err := json.Marshal(resData) + surveys := surveysToSurveyRequests(resData) + + sort.Slice(surveys, func(i, j int) bool { + return surveys[i].DateCreated.After(surveys[j].DateCreated) + }) + + rdata, err := json.Marshal(surveys) if err != nil { return l.HTTPResponseErrorAction(logutils.ActionMarshal, logutils.TypeResponseBody, nil, err, http.StatusInternalServerError, false) } @@ -475,7 +506,7 @@ func (h ClientAPIsHandler) getCreatorSurveys(l *logs.Log, r *http.Request, claim offset = intParsed } - resData, err := h.app.Client.GetSurveys(claims.OrgID, claims.AppID, &claims.Subject, surveyIDs, surveyTypes, "", &limit, &offset, nil) + resData, err := h.app.Client.GetSurveys(claims.OrgID, claims.AppID, &claims.Subject, surveyIDs, surveyTypes, "", &limit, &offset, nil, nil, nil) if err != nil { return l.HTTPResponseErrorAction(logutils.ActionGet, model.TypeSurvey, nil, err, http.StatusInternalServerError, true) } diff --git a/driver/web/convertions_surveys.go b/driver/web/convertions_surveys.go index c98931e..e315062 100644 --- a/driver/web/convertions_surveys.go +++ b/driver/web/convertions_surveys.go @@ -10,7 +10,11 @@ import ( func surveyRequestToSurvey(claims *tokenauth.Claims, item model.SurveyRequest) model.Survey { item.Type = "user" //start - startValueValue := time.Unix(int64(item.StartDate), 0) + var startValue *time.Time + if item.StartDate != nil { + startValueValue := time.Unix(int64(*item.StartDate), 0) + startValue = &startValueValue + } //end var endValue *time.Time if item.EndDate != nil { @@ -22,11 +26,16 @@ func surveyRequestToSurvey(claims *tokenauth.Claims, item model.SurveyRequest) m MoreInfo: item.MoreInfo, Data: item.Data, Scored: item.Scored, ResultRules: item.ResultRules, ResultJSON: item.ResultJSON, SurveyStats: item.SurveyStats, Sensitive: item.Sensitive, Anonymous: item.Anonymous, DefaultDataKey: item.DefaultDataKey, DefaultDataKeyRule: item.DefaultDataKeyRule, Constants: item.Constants, Strings: item.Strings, SubRules: item.SubRules, - ResponseKeys: item.ResponseKeys, CalendarEventID: item.CalendarEventID, StartDate: startValueValue, EndDate: endValue} + ResponseKeys: item.ResponseKeys, CalendarEventID: item.CalendarEventID, StartDate: startValue, EndDate: endValue, + Public: item.Public, Archived: item.Archived} } func surveyToSurveyRequest(item model.Survey) model.SurveyRequest { - startDateUnixTimestamp := item.StartDate.Unix() + var startDateUnixTimestamp int64 + if item.StartDate != nil { + startDateUnixTimestamp = item.StartDate.Unix() + } + var endDateUnixTimestamp int64 if item.EndDate != nil { endDateUnixTimestamp = item.EndDate.Unix() @@ -36,14 +45,26 @@ func surveyToSurveyRequest(item model.Survey) model.SurveyRequest { MoreInfo: item.MoreInfo, Data: item.Data, Scored: item.Scored, ResultRules: item.ResultRules, ResultJSON: item.ResultJSON, Type: item.Type, SurveyStats: item.SurveyStats, Sensitive: item.Sensitive, Anonymous: item.Anonymous, DefaultDataKey: item.DefaultDataKey, DefaultDataKeyRule: item.DefaultDataKeyRule, Constants: item.Constants, Strings: item.Strings, SubRules: item.SubRules, - ResponseKeys: item.ResponseKeys, DateCreated: item.DateCreated, CalendarEventID: item.CalendarEventID, StartDate: startDateUnixTimestamp, - EndDate: &endDateUnixTimestamp} + ResponseKeys: item.ResponseKeys, DateCreated: item.DateCreated, CalendarEventID: item.CalendarEventID, StartDate: &startDateUnixTimestamp, + EndDate: &endDateUnixTimestamp, Public: item.Public, Archived: item.Archived} +} + +func surveysToSurveyRequests(items []model.Survey) []model.SurveyRequest { + list := make([]model.SurveyRequest, len(items)) + for index := range items { + list[index] = surveyToSurveyRequest(items[index]) + } + return list } func updateSurveyRequestToSurvey(claims *tokenauth.Claims, item model.SurveyRequest, id string) model.Survey { item.Type = "user" //start - startValueValue := time.Unix(int64(item.StartDate), 0) + var startValue *time.Time + if item.StartDate != nil { + startValueTime := time.Unix(int64(*item.StartDate), 0) + startValue = &startValueTime + } //end var endValue *time.Time if item.EndDate != nil { @@ -55,7 +76,8 @@ func updateSurveyRequestToSurvey(claims *tokenauth.Claims, item model.SurveyRequ MoreInfo: item.MoreInfo, Data: item.Data, Scored: item.Scored, ResultRules: item.ResultRules, ResultJSON: item.ResultJSON, SurveyStats: item.SurveyStats, Sensitive: item.Sensitive, Anonymous: item.Anonymous, DefaultDataKey: item.DefaultDataKey, DefaultDataKeyRule: item.DefaultDataKeyRule, Constants: item.Constants, Strings: item.Strings, SubRules: item.SubRules, - ResponseKeys: item.ResponseKeys, CalendarEventID: item.CalendarEventID, StartDate: startValueValue, EndDate: endValue} + ResponseKeys: item.ResponseKeys, CalendarEventID: item.CalendarEventID, StartDate: startValue, EndDate: endValue, + Public: item.Public, Archived: item.Archived} } func surveyTimeFilter(item *model.SurveyTimeFilterRequest) *model.SurveyTimeFilter { diff --git a/driver/web/docs/gen/def.yaml b/driver/web/docs/gen/def.yaml index 87d9a45..74b1f31 100644 --- a/driver/web/docs/gen/def.yaml +++ b/driver/web/docs/gen/def.yaml @@ -2,7 +2,7 @@ openapi: 3.0.3 info: title: Rokwire Surveys Building Block API description: Surveys Building Block API Documentation - version: 1.5.0 + version: 1.6.0 servers: - url: 'https://api.rokwire.illinois.edu/surveys' description: Production server @@ -92,6 +92,22 @@ paths: explode: false schema: type: number + - name: public + in: query + description: Shows if the survery is public or not + required: false + style: simple + explode: false + schema: + type: boolean + - name: archived + in: query + description: Shows if the survery is archived or not + required: false + style: simple + explode: false + schema: + type: boolean requestBody: description: Get survey time filter request body required: false @@ -943,6 +959,29 @@ paths: explode: false schema: type: number + - name: public + in: query + description: Shows if the survery is public or not + required: false + style: simple + explode: false + schema: + type: boolean + - name: archived + in: query + description: Shows if the survery is archived or not + required: false + style: simple + explode: false + schema: + type: boolean + requestBody: + description: Get survey time filter request body + required: false + content: + application/json: + schema: + $ref: '#/paths/~1api~1surveys/get/requestBody/content/application~1json/schema' responses: '200': description: Success @@ -1468,12 +1507,19 @@ components: start_date: type: integer format: int64 + nullable: true description: UNIX timestamp end_date: type: integer format: int64 nullable: true description: UNIX timestamp + public: + type: boolean + nullable: true + archived: + type: boolean + nullable: true SurveyData: type: object properties: @@ -1497,6 +1543,9 @@ components: type: boolean response: type: object + extras: + type: object + nullable: true type: type: string correct_answer: diff --git a/driver/web/docs/index.yaml b/driver/web/docs/index.yaml index d0e8bc5..e30a2db 100644 --- a/driver/web/docs/index.yaml +++ b/driver/web/docs/index.yaml @@ -2,7 +2,7 @@ openapi: 3.0.3 info: title: Rokwire Surveys Building Block API description: Surveys Building Block API Documentation - version: 1.5.0 + version: 1.6.0 servers: - url: 'https://api.rokwire.illinois.edu/surveys' description: Production server diff --git a/driver/web/docs/resources/admin/surveys.yaml b/driver/web/docs/resources/admin/surveys.yaml index fb68dfc..c3d19aa 100644 --- a/driver/web/docs/resources/admin/surveys.yaml +++ b/driver/web/docs/resources/admin/surveys.yaml @@ -48,6 +48,29 @@ get: explode: false schema: type: number + - name: public + in: query + description: Shows if the survery is public or not + required: false + style: simple + explode: false + schema: + type: boolean + - name: archived + in: query + description: Shows if the survery is archived or not + required: false + style: simple + explode: false + schema: + type: boolean + requestBody: + description: Get survey time filter request body + required: false + content: + application/json: + schema: + $ref: "../../schemas/surveys/SurveyTimeFilter.yaml" responses: 200: description: Success diff --git a/driver/web/docs/resources/client/surveys.yaml b/driver/web/docs/resources/client/surveys.yaml index ce8075a..c1c8cb4 100644 --- a/driver/web/docs/resources/client/surveys.yaml +++ b/driver/web/docs/resources/client/surveys.yaml @@ -46,6 +46,22 @@ get: explode: false schema: type: number + - name: public + in: query + description: Shows if the survery is public or not + required: false + style: simple + explode: false + schema: + type: boolean + - name: archived + in: query + description: Shows if the survery is archived or not + required: false + style: simple + explode: false + schema: + type: boolean requestBody: description: Get survey time filter request body required: false diff --git a/driver/web/docs/schemas/surveys/Survey.yaml b/driver/web/docs/schemas/surveys/Survey.yaml index a326237..e7f10a2 100644 --- a/driver/web/docs/schemas/surveys/Survey.yaml +++ b/driver/web/docs/schemas/surveys/Survey.yaml @@ -60,9 +60,16 @@ properties: start_date: type: integer format: int64 + nullable: true description: "UNIX timestamp" end_date: type: integer format: int64 nullable: true - description: "UNIX timestamp" \ No newline at end of file + description: "UNIX timestamp" + public: + type: boolean + nullable: true + archived: + type: boolean + nullable: true \ No newline at end of file diff --git a/driver/web/docs/schemas/surveys/SurveyData.yaml b/driver/web/docs/schemas/surveys/SurveyData.yaml index f904639..2e44a5f 100644 --- a/driver/web/docs/schemas/surveys/SurveyData.yaml +++ b/driver/web/docs/schemas/surveys/SurveyData.yaml @@ -20,6 +20,9 @@ properties: type: boolean response: type: object + extras: + type: object + nullable: true type: type: string correct_answer: