Skip to content

Commit

Permalink
[ID-40]Archived flag (#47)
Browse files Browse the repository at this point in the history
* set the Changelog.md

* fix the Changelog.md

* set the docs

* add archived in progress

* set archived to the update filter

* add archived to the storage filter

* set the mocks

---------

Co-authored-by: Stefan Vitanov <[email protected]>
  • Loading branch information
stefanvit and Stefan Vitanov authored Jul 23, 2024
1 parent 2b56931 commit c56970e
Show file tree
Hide file tree
Showing 17 changed files with 102 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
### 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)
Expand Down
4 changes: 2 additions & 2 deletions core/app_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, public *bool) ([]model.Survey, error) {
return a.app.shared.getSurveys(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter, public)
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
Expand Down
4 changes: 2 additions & 2 deletions core/app_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, public *bool) ([]model.Survey, error) {
return a.app.shared.getSurveys(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter, public)
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
Expand Down
4 changes: 2 additions & 2 deletions core/app_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, public *bool) ([]model.Survey, error) {
return a.app.storage.GetSurveys(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter, public)
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) {
Expand Down
2 changes: 1 addition & 1 deletion core/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, public *bool) ([]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
Expand Down
4 changes: 2 additions & 2 deletions core/interfaces/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, public *bool) ([]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
Expand Down Expand Up @@ -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, public *bool) ([]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
Expand Down
2 changes: 1 addition & 1 deletion core/interfaces/driven.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, public *bool) ([]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
Expand Down
18 changes: 9 additions & 9 deletions core/interfaces/mocks/Storage.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions core/model/surveys.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type Survey struct {
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
Expand Down Expand Up @@ -198,6 +199,7 @@ type SurveyRequest struct {
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
Expand Down
7 changes: 6 additions & 1 deletion driven/storage/adapter_surveys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, public *bool) ([]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},
Expand Down Expand Up @@ -74,6 +74,10 @@ func (a *Adapter) GetSurveys(orgID string, appID string, creatorID *string, surv
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))
Expand Down Expand Up @@ -136,6 +140,7 @@ func (a *Adapter) UpdateSurvey(survey model.Survey, admin bool) error {
"start_date": survey.StartDate,
"end_date": survey.EndDate,
"public": survey.Public,
"archived": survey.Archived,
"date_updated": now,
}}

Expand Down
13 changes: 12 additions & 1 deletion driver/web/apis_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,19 @@ func (h AdminAPIsHandler) getSurveys(l *logs.Log, r *http.Request, claims *token
}
public = &value
}
archivedStr := r.URL.Query().Get("archived")

resData, err := h.app.Admin.GetSurveys(claims.OrgID, claims.AppID, nil, surveyIDs, surveyTypes, calendarEventID, &limit, &offset, filter, public)
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)
}
Expand Down
16 changes: 14 additions & 2 deletions driver/web/apis_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,20 @@ func (h ClientAPIsHandler) getSurveys(l *logs.Log, r *http.Request, claims *toke
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, public)
&limit, &offset, filter, public, archived)
if err != nil {
return l.HTTPResponseErrorAction(logutils.ActionGet, model.TypeSurvey, nil, err, http.StatusInternalServerError, true)
}
Expand Down Expand Up @@ -494,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, 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)
}
Expand Down
8 changes: 5 additions & 3 deletions driver/web/convertions_surveys.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ 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: startValue, EndDate: endValue, Public: item.Public}
ResponseKeys: item.ResponseKeys, CalendarEventID: item.CalendarEventID, StartDate: startValue, EndDate: endValue,
Public: item.Public, Archived: item.Archived}
}

func surveyToSurveyRequest(item model.Survey) model.SurveyRequest {
Expand All @@ -45,7 +46,7 @@ func surveyToSurveyRequest(item model.Survey) model.SurveyRequest {
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, Public: item.Public}
EndDate: &endDateUnixTimestamp, Public: item.Public, Archived: item.Archived}
}

func surveysToSurveyRequests(items []model.Survey) []model.SurveyRequest {
Expand Down Expand Up @@ -75,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: startValue, EndDate: endValue, Public: item.Public}
ResponseKeys: item.ResponseKeys, CalendarEventID: item.CalendarEventID, StartDate: startValue, EndDate: endValue,
Public: item.Public, Archived: item.Archived}
}

func surveyTimeFilter(item *model.SurveyTimeFilterRequest) *model.SurveyTimeFilter {
Expand Down
19 changes: 19 additions & 0 deletions driver/web/docs/gen/def.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ paths:
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
Expand Down Expand Up @@ -959,6 +967,14 @@ paths:
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
Expand Down Expand Up @@ -1501,6 +1517,9 @@ components:
public:
type: boolean
nullable: true
archived:
type: boolean
nullable: true
SurveyData:
type: object
properties:
Expand Down
8 changes: 8 additions & 0 deletions driver/web/docs/resources/admin/surveys.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ get:
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
Expand Down
10 changes: 9 additions & 1 deletion driver/web/docs/resources/client/surveys.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,15 @@ get:
style: simple
explode: false
schema:
type: boolean
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
Expand Down
5 changes: 4 additions & 1 deletion driver/web/docs/schemas/surveys/Survey.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,7 @@ properties:
description: "UNIX timestamp"
public:
type: boolean
nullable: true
nullable: true
archived:
type: boolean
nullable: true

0 comments on commit c56970e

Please sign in to comment.