Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge develop into main #63

Merged
merged 2 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ 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.9.0] - 2024-007-26
### Added
- Add "complete" field to show if the survey is completed [#61](https://github.com/rokwire/surveys-building-block/issues/61)
## [1.8.2] - 2024-007-26
### Fixed
- Fix Get /surveys [#58](https://github.com/rokwire/surveys-building-block/issues/58)
Expand Down
4 changes: 2 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Patches for **Surveys Building Block** in this repository will only be applied t

| Version | Supported |
| ------- | ------------------ |
| 1.8.2 | :white_check_mark: |
| < 1.8.2 | :x: |
| 1.9.0 | :white_check_mark: |
| < 1.9.0 | :x: |

## Reporting a Bug or Vulnerability

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, archived *bool) ([]model.Survey, []model.SurveyResponse, error) {
return a.app.shared.getSurveys(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter, public, archived)
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, completed *bool) ([]model.Survey, []model.SurveyResponse, error) {
return a.app.shared.getSurveys(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter, public, archived, completed)
}

// 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, archived *bool) ([]model.Survey, []model.SurveyResponse, error) {
return a.app.shared.getSurveys(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter, public, archived)
limit *int, offset *int, filter *model.SurveyTimeFilter, public *bool, archived *bool, completed *bool) ([]model.Survey, []model.SurveyResponse, error) {
return a.app.shared.getSurveys(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter, public, archived, completed)
}

// 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, archived *bool) ([]model.Survey, []model.SurveyResponse, error) {
surveys, err := a.app.storage.GetSurveys(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter, public, archived)
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, completed *bool) ([]model.Survey, []model.SurveyResponse, error) {
surveys, err := a.app.storage.GetSurveys(orgID, appID, creatorID, surveyIDs, surveyTypes, calendarEventID, limit, offset, filter, public, archived, nil)
if err != nil {
return nil, nil, err
}
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, archived *bool) ([]model.Survey, []model.SurveyResponse, 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, completed *bool) ([]model.Survey, []model.SurveyResponse, 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, archived *bool) ([]model.Survey, []model.SurveyResponse, 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, completed *bool) ([]model.Survey, []model.SurveyResponse, 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, archived *bool) ([]model.Survey, []model.SurveyResponse, 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, completed *bool) ([]model.Survey, []model.SurveyResponse, 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, archived *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, completed *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: 1 addition & 1 deletion core/model/surveys.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,5 +250,5 @@ type SurveysResponseData struct {
Public *bool `json:"public"`
Archived *bool `json:"archived"`
EstimatedCompletionTime *int `json:"estimated_completion_time"`
Complete *bool `json:"complete"`
Completed *bool `json:"completed"`
}
2 changes: 1 addition & 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, archived *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, completed *bool) ([]model.Survey, error) {
filter := bson.D{
{Key: "org_id", Value: orgID},
{Key: "app_id", Value: appID},
Expand Down
16 changes: 14 additions & 2 deletions driver/web/apis_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,25 @@ func (h AdminAPIsHandler) getSurveys(l *logs.Log, r *http.Request, claims *token
archived = &valueArchived
}

completedStr := r.URL.Query().Get("completed")

var completed *bool

if completedStr != "" {
valueCompleted, err := strconv.ParseBool(completedStr)
if err != nil {
return l.HTTPResponseErrorAction(logutils.ActionGet, model.TypeSurvey, nil, err, http.StatusInternalServerError, true)
}
completed = &valueCompleted
}

surveys, surverysRsponse, err := h.app.Admin.GetSurveys(claims.OrgID, claims.AppID, nil, surveyIDs, surveyTypes, calendarEventID,
&limit, &offset, filter, public, archived)
&limit, &offset, filter, public, archived, completed)
if err != nil {
return l.HTTPResponseErrorAction(logutils.ActionGet, model.TypeSurvey, nil, err, http.StatusInternalServerError, true)
}

resData := getSurveysResData(surveys, surverysRsponse)
resData := getSurveysResData(surveys, surverysRsponse, completed)
sort.Slice(resData, func(i, j int) bool {
return resData[i].DateCreated.After(resData[j].DateCreated)
})
Expand Down
18 changes: 15 additions & 3 deletions driver/web/apis_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,25 @@ func (h ClientAPIsHandler) getSurveys(l *logs.Log, r *http.Request, claims *toke
archived = &valueArchived
}

completedStr := r.URL.Query().Get("completed")

var completed *bool

if completedStr != "" {
valueCompleted, err := strconv.ParseBool(completedStr)
if err != nil {
return l.HTTPResponseErrorAction(logutils.ActionGet, model.TypeSurvey, nil, err, http.StatusInternalServerError, true)
}
completed = &valueCompleted
}

surveys, surverysRsponse, err := h.app.Client.GetSurveys(claims.OrgID, claims.AppID, nil, surveyIDs, surveyTypes, calendarEventID,
&limit, &offset, filter, public, archived)
&limit, &offset, filter, public, archived, completed)
if err != nil {
return l.HTTPResponseErrorAction(logutils.ActionGet, model.TypeSurvey, nil, err, http.StatusInternalServerError, true)
}

resData := getSurveysResData(surveys, surverysRsponse)
resData := getSurveysResData(surveys, surverysRsponse, completed)
sort.Slice(resData, func(i, j int) bool {
return resData[i].DateCreated.After(resData[j].DateCreated)
})
Expand Down Expand Up @@ -511,7 +523,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, nil)
resData, _, err := h.app.Client.GetSurveys(claims.OrgID, claims.AppID, &claims.Subject, surveyIDs, surveyTypes, "", &limit, &offset, nil, nil, nil, nil)
if err != nil {
return l.HTTPResponseErrorAction(logutils.ActionGet, model.TypeSurvey, nil, err, http.StatusInternalServerError, true)
}
Expand Down
62 changes: 41 additions & 21 deletions driver/web/convertions_surveys.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,31 +97,51 @@ func surveyTimeFilter(item *model.SurveyTimeFilterRequest) *model.SurveyTimeFilt
EndTimeBefore: filter.EndTimeBefore}
}

func getSurveyResData(item model.Survey, surveyResponse model.SurveyResponse) model.SurveysResponseData {
var complete bool
func getSurveysResData(items []model.Survey, surveyResponses []model.SurveyResponse, completed *bool) []model.SurveysResponseData {
var list []model.SurveysResponseData

if item.CreatorID == surveyResponse.UserID && item.AppID == surveyResponse.AppID && item.OrgID == surveyResponse.OrgID && item.ID == surveyResponse.Survey.ID {
complete = true
} else {
complete = false
}
for _, item := range items {
var isCompleted bool

return model.SurveysResponseData{ID: item.ID, CreatorID: item.CreatorID, OrgID: item.OrgID, AppID: item.AppID, Type: item.Type, Title: item.Title,
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: item.StartDate, EndDate: item.EndDate,
Public: item.Public, Archived: item.Archived, EstimatedCompletionTime: item.EstimatedCompletionTime, Complete: &complete}
}
for _, surveyResponse := range surveyResponses {
if item.ID == surveyResponse.Survey.ID {
isCompleted = true
break
}
}

func getSurveysResData(items []model.Survey, surveyResponses []model.SurveyResponse) []model.SurveysResponseData {
list := make([]model.SurveysResponseData, len(items))
for index := range items {
var surveyResponse model.SurveyResponse
if index < len(surveyResponses) {
surveyResponse = surveyResponses[index]
if completed == nil || *completed == isCompleted {
list = append(list, model.SurveysResponseData{
ID: item.ID,
CreatorID: item.CreatorID,
OrgID: item.OrgID,
AppID: item.AppID,
Type: item.Type,
Title: item.Title,
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: item.StartDate,
EndDate: item.EndDate,
Public: item.Public,
Archived: item.Archived,
EstimatedCompletionTime: item.EstimatedCompletionTime,
Completed: &isCompleted,
})
}
list[index] = getSurveyResData(items[index], surveyResponse)
}

return list
}
18 changes: 17 additions & 1 deletion driver/web/docs/gen/def.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ openapi: 3.0.3
info:
title: Rokwire Surveys Building Block API
description: Surveys Building Block API Documentation
version: 1.8.2
version: 1.9.0
servers:
- url: 'https://api.rokwire.illinois.edu/surveys'
description: Production server
Expand Down Expand Up @@ -108,6 +108,14 @@ paths:
explode: false
schema:
type: boolean
- name: completed
in: query
description: Shows if the survery is completed 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 @@ -975,6 +983,14 @@ paths:
explode: false
schema:
type: boolean
- name: completed
in: query
description: Shows if the survery is completed or not
required: false
style: simple
explode: false
schema:
type: boolean
requestBody:
description: Get survey time filter request body
required: false
Expand Down
2 changes: 1 addition & 1 deletion driver/web/docs/index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ openapi: 3.0.3
info:
title: Rokwire Surveys Building Block API
description: Surveys Building Block API Documentation
version: 1.8.2
version: 1.9.0
servers:
- url: 'https://api.rokwire.illinois.edu/surveys'
description: Production server
Expand Down
10 changes: 9 additions & 1 deletion driver/web/docs/resources/admin/surveys.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ get:
style: simple
explode: false
schema:
type: boolean
type: boolean
- name: completed
in: query
description: Shows if the survery is completed or not
required: false
style: simple
explode: false
schema:
type: boolean
requestBody:
description: Get survey time filter request body
required: false
Expand Down
Loading
Loading