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

[ID-47]Consolidate the information, and make it accessible with a single API call #48

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ 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]
### Added
- Consolidate the information, and make it accessible with a single API call [#47](https://github.com/rokwire/wellness-building-block/issues/47)
## [1.5.1] - 2024-08-28
### Changed
- Updated notifications title [#35](https://github.com/rokwire/wellness-building-block/issues/35)
Expand Down
10 changes: 10 additions & 0 deletions core/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ type Services interface {
CreateRingsRecord(appID string, orgID string, userID string, record *model.RingRecord) (*model.RingRecord, error)
UpdateRingsRecord(appID string, orgID string, userID string, record *model.RingRecord) (*model.RingRecord, error)
DeleteRingsRecords(appID string, orgID string, userID string, ringID *string, recordID *string) error

GetUserData(userID string) (*model.UserDataResponse, error)
}

type servicesImpl struct {
Expand Down Expand Up @@ -147,11 +149,16 @@ func (s *servicesImpl) DeleteRingsRecords(appID string, orgID string, userID str
return s.app.deleteRingsRecords(appID, orgID, userID, ringID, recordID)
}

func (s *servicesImpl) GetUserData(userID string) (*model.UserDataResponse, error) {
return s.app.getUserData(userID)
}

// Storage is used by core to storage data - DB storage adapter, file storage adapter etc
type Storage interface {
PerformTransaction(transaction func(context storage.TransactionContext) error) error

GetTodoCategories(appID string, orgID string, userID string) ([]model.TodoCategory, error)
GetTodoCategoriesByUserID(userID string) ([]model.TodoCategory, error)
GetTodoCategory(appID string, orgID string, userID string, id string) (*model.TodoCategory, error)
CreateTodoCategory(appID string, orgID string, userID string, category *model.TodoCategory) (*model.TodoCategory, error)
UpdateTodoCategory(appID string, orgID string, userID string, category *model.TodoCategory) (*model.TodoCategory, error)
Expand All @@ -161,6 +168,7 @@ type Storage interface {
GetTodoEntriesWithCurrentReminderTime(context storage.TransactionContext, reminderTime time.Time) ([]model.TodoEntry, error)
GetTodoEntriesWithCurrentDueTime(context storage.TransactionContext, dueTime time.Time) ([]model.TodoEntry, error)
GetTodoEntries(appID string, orgID string, userID string) ([]model.TodoEntry, error)
GetTodoEntriesByUserID(userID string) ([]model.TodoEntry, error)
GetTodoEntriesForMigration() ([]model.TodoEntry, error)
GetTodoEntry(context storage.TransactionContext, appID string, orgID string, userID string, id string) (*model.TodoEntry, error)
CreateTodoEntry(appID string, orgID string, userID string, todo *model.TodoEntry, messageIDs model.MessageIDs, entityID string) (*model.TodoEntry, error)
Expand All @@ -171,6 +179,7 @@ type Storage interface {
DeleteTodoEntriesForUsers(appID string, orgID string, accountsIDs []string) error

GetRings(appID string, orgID string, userID string) ([]model.Ring, error)
GetRingsByUserID(userID string) ([]model.Ring, error)
GetRing(appID string, orgID string, userID string, id string) (*model.Ring, error)
CreateRing(appID string, orgID string, userID string, category *model.Ring) (*model.Ring, error)
DeleteRing(appID string, orgID string, userID string, id string) error
Expand All @@ -179,6 +188,7 @@ type Storage interface {
DeleteRingsForUsers(appID string, orgID string, accountsIDs []string) error

GetRingsRecords(appID string, orgID string, userID string, ringID *string, startDateEpoch *int64, endDateEpoch *int64, offset *int64, limit *int64, order *string) ([]model.RingRecord, error)
GetRingsRecordsByUserID(userID string) ([]model.RingRecord, error)
GetRingsRecord(appID string, orgID string, userID string, id string) (*model.RingRecord, error)
CreateRingsRecord(appID string, orgID string, userID string, record *model.RingRecord) (*model.RingRecord, error)
UpdateRingsRecord(appID string, orgID string, userID string, record *model.RingRecord) (*model.RingRecord, error)
Expand Down
47 changes: 47 additions & 0 deletions core/model/user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2022 Board of Trustees of the University of Illinois.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package model

// RingResponse represents wellness ring wrapper
type RingResponse struct {
ID string `json:"id" bson:"_id"`
UserID string `json:"user_id" bson:"user_id"`
} // @name RingResponse

// RingRecordResponse represents individual daily records for an individual ring
type RingRecordResponse struct {
ID string `json:"id" bson:"_id"`
UserID string `json:"user_id" bson:"user_id"`
} //@name RingRecordResponse

// TodoCategoryResponse user defined todo category
type TodoCategoryResponse struct {
ID string `json:"id" bson:"_id"`
UserID string `json:"user_id" bson:"user_id"`
} // @name TodoCategoryResponse

// TodoEntryResponse user todo entry
type TodoEntryResponse struct {
ID string `json:"id" bson:"_id"`
UserID string `json:"user_id" bson:"user_id"`
} // @name TodoEntryResponse

// UserDataResponse user todo entry
type UserDataResponse struct {
Rings []RingResponse `json:"rings"`
RingsRecord []RingRecordResponse `json:"rings_records"`
TodoEntries []TodoEntryResponse `json:"todo_entries"`
TodoCategories []TodoCategoryResponse `json:"todo_categories"`
} // @name UserDataResponse
59 changes: 59 additions & 0 deletions core/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,62 @@ func (app *Application) updateRingsRecord(appID string, orgID string, userID str
func (app *Application) deleteRingsRecords(appID string, orgID string, userID string, ringID *string, recordID *string) error {
return app.storage.DeleteRingsRecords(appID, orgID, userID, ringID, recordID)
}

func (app *Application) getUserData(userID string) (*model.UserDataResponse, error) {
var ringsResponse []model.RingResponse
var ringsRecordsResponse []model.RingRecordResponse
var todoEntriesResponse []model.TodoEntryResponse
var todoCategoriesResponse []model.TodoCategoryResponse

rings, err := app.storage.GetRingsByUserID(userID)
if err != nil {
return nil, err
}

if rings != nil {
for _, r := range rings {
ri := model.RingResponse{ID: r.ID, UserID: r.UserID}
ringsResponse = append(ringsResponse, ri)
}
}

ringsRecords, err := app.storage.GetRingsRecordsByUserID(userID)
if err != nil {
return nil, err
}

if ringsRecords != nil {
for _, rr := range ringsRecords {
rrr := model.RingRecordResponse{ID: rr.ID, UserID: rr.UserID}
ringsRecordsResponse = append(ringsRecordsResponse, rrr)
}
}

todoEnries, err := app.storage.GetTodoEntriesByUserID(userID)
if err != nil {
return nil, err
}

if todoEnries != nil {
for _, t := range todoEnries {
tr := model.TodoEntryResponse{ID: t.ID, UserID: t.UserID}
todoEntriesResponse = append(todoEntriesResponse, tr)
}
}

todoCategories, err := app.storage.GetTodoCategoriesByUserID(userID)
if err != nil {
return nil, err
}

if todoCategories != nil {
for _, c := range todoCategories {
cr := model.TodoCategoryResponse{ID: c.ID, UserID: c.UserID}
todoCategoriesResponse = append(todoCategoriesResponse, cr)
}
}

userDataResponse := model.UserDataResponse{Rings: ringsResponse, RingsRecord: ringsRecordsResponse, TodoEntries: todoEntriesResponse, TodoCategories: todoCategoriesResponse}

return &userDataResponse, nil
}
Loading
Loading