From 93fa1e11d672e2169e30b2457943340837c6724f Mon Sep 17 00:00:00 2001 From: Emerson Majormaxx Daniel <125857575+Majormaxx@users.noreply.github.com> Date: Sat, 17 Jan 2026 02:31:18 +0100 Subject: [PATCH] docs: add docstrings to list_user_courses.rs Added comprehensive docstrings following the project template to: - `list_user_courses` function with description, arguments, and return value - `test_list_user_courses` test function with description Closes #203 --- .../src/functions/list_user_courses.rs | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/contracts/course/course_access/src/functions/list_user_courses.rs b/contracts/course/course_access/src/functions/list_user_courses.rs index cbdb396..2198690 100644 --- a/contracts/course/course_access/src/functions/list_user_courses.rs +++ b/contracts/course/course_access/src/functions/list_user_courses.rs @@ -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 { @@ -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();