Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,21 @@ use soroban_sdk::{Address, Env, Vec};

use crate::schema::{DataKey, UserCourses};


/// Retrieves the list of courses associated with a specific user.
///
/// This function queries the persistent storage to fetch all courses
/// that the specified user has access to. If no courses are found for
/// the user, it returns an empty `UserCourses` struct.
///
/// # Arguments
///
/// * `env` - The Soroban environment context for accessing storage and other SDK features.
/// * `user` - The blockchain address of the user whose courses are being retrieved.
///
/// # Returns
///
/// * `UserCourses` - A struct containing the user's address and a vector of their course IDs.
/// If the user has no courses, returns a `UserCourses` with an empty courses vector.
pub fn list_user_courses(env: Env, user: Address) -> UserCourses {
let key: DataKey = DataKey::UserCourses(user.clone());
let res: UserCourses = env.storage().persistent().get(&key).unwrap_or(UserCourses {
Expand All @@ -23,6 +37,11 @@ mod test {
use soroban_sdk::{testutils::Address as _, vec, Address, Env, String};
use super::list_user_courses;

/// Tests the `list_user_courses` function to verify correct retrieval of user courses.
///
/// This test sets up a mock environment with a registered contract and user,
/// creates course data, stores it in persistent storage, and verifies that
/// `list_user_courses` correctly retrieves the stored data.
#[test]
fn test_list_user_courses() {
let env: Env = Env::default();
Expand Down