Skip to content

Commit 587ccc0

Browse files
committed
Enhance API documentation and annotations across transaction modules
- Added concise, structured documentation for `transaction`, `account`, `currency`, and related APIs for improved clarity and usability. - Applied `@ApiStatus.NonExtendable` to several interfaces to clarify usage restrictions. - Updated and standardized parameter descriptions in transactional operations to ensure consistency. - Improved type annotations and metadata for interfaces and result objects.
1 parent 62b3c4d commit 587ccc0

File tree

19 files changed

+694
-176
lines changed

19 files changed

+694
-176
lines changed

surf-transaction-api/src/main/kotlin/dev/slne/surf/transaction/api/account/Account.kt

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,91 @@ import dev.slne.surf.transaction.api.account.result.AccountCreationResult
55
import dev.slne.surf.transaction.api.transactional.Transactional
66
import dev.slne.surf.transaction.api.util.InternalTransactionApi
77
import net.kyori.adventure.text.Component
8+
import org.jetbrains.annotations.ApiStatus
89
import java.util.*
910

11+
/**
12+
* Represents an account within the transaction system.
13+
*
14+
* An [Account] holds balances for one or more currencies and supports
15+
* transactional operations such as deposits, withdrawals, and transfers.
16+
* It also provides member management via [AccountMemberOperations].
17+
*
18+
* Accounts are managed by the [AccountService] and should be accessed
19+
* through the provided lookup and creation methods.
20+
*/
1021
@OptIn(InternalTransactionApi::class)
22+
@ApiStatus.NonExtendable
1123
interface Account : Transactional, AccountMemberOperations {
1224

25+
/**
26+
* The unique identifier of this account.
27+
*/
1328
val accountId: UUID
29+
30+
/**
31+
* The human-readable name of this account.
32+
*
33+
* The name length must be within [MIN_NAME_LENGTH] and [MAX_NAME_LENGTH].
34+
*/
1435
val name: String
36+
37+
/**
38+
* The UUID of the account owner.
39+
*
40+
* The owner typically has full permissions on the account.
41+
*/
1542
val ownerUuid: UUID
43+
44+
/**
45+
* Whether this account is the default account of its owner.
46+
*/
1647
val defaultAccount: Boolean
1748

49+
/**
50+
* Returns a component representation of this account.
51+
*
52+
* This component is typically used for user-facing displays and may
53+
* include formatting or additional contextual information.
54+
*
55+
* @return a display component representing this account
56+
*/
1857
suspend fun asComponent(): Component
1958

2059
companion object {
60+
/**
61+
* The minimum allowed length of an account name.
62+
*/
2163
const val MIN_NAME_LENGTH = 3
64+
/**
65+
* The maximum allowed length of an account name.
66+
*/
2267
const val MAX_NAME_LENGTH = 32
2368

69+
70+
/**
71+
* Returns an account by its unique [accountId], or `null` if none exists.
72+
*
73+
* @param accountId the account identifier
74+
*/
2475
suspend fun byId(accountId: UUID): Account? =
2576
AccountService.instance.getAccountByAccountId(accountId)
2677

78+
/**
79+
* Returns an account by its [name], or `null` if none exists.
80+
*
81+
* @param name the name of the account
82+
*/
2783
suspend fun byName(name: String): Account? = AccountService.instance.getAccountByName(name)
2884

85+
/**
86+
* Creates a new account for the given [owner] with the specified [name].
87+
*
88+
* @param owner the UUID of the account owner
89+
* @param name the name of the new account
90+
*
91+
* @return the result of the account creation attempt
92+
*/
2993
suspend fun create(
3094
owner: UUID,
3195
name: String

surf-transaction-api/src/main/kotlin/dev/slne/surf/transaction/api/account/AccountAccess.kt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,61 @@ package dev.slne.surf.transaction.api.account
33
import dev.slne.surf.transaction.api.account.result.AccountCreationResult
44
import dev.slne.surf.transaction.api.account.result.AccountDeleteResult
55
import dev.slne.surf.transaction.api.util.InternalTransactionApi
6+
import org.jetbrains.annotations.ApiStatus
67
import java.util.*
78

9+
/**
10+
* Provides user-scoped access to account management operations.
11+
*
12+
* An [AccountAccess] instance represents the view of accounts belonging to a
13+
* specific user and allows creating, retrieving, and deleting accounts owned
14+
* by that user.
15+
*/
816
@OptIn(InternalTransactionApi::class)
17+
@ApiStatus.NonExtendable
918
interface AccountAccess {
1019

20+
/**
21+
* The UUID of the user this access instance belongs to.
22+
*/
1123
val userUuid: UUID
24+
25+
/**
26+
* Returns the default account of the user.
27+
*
28+
* @return the user's default account
29+
*/
1230
suspend fun getDefaultAccount(): Account
31+
32+
/**
33+
* Returns all accounts owned by the user.
34+
*
35+
* @return a set of all user accounts
36+
*/
1337
suspend fun getAllAccounts(): Set<Account>
38+
39+
/**
40+
* Creates a new account with the given [name] for the user.
41+
*
42+
* @param name the name of the account to create
43+
* @return the result of the account creation attempt
44+
*/
1445
suspend fun createAccount(name: String): AccountCreationResult
46+
47+
/**
48+
* Returns an account owned by the user with the given [accountName],
49+
* or `null` if no such account exists.
50+
*
51+
* @param accountName the name of the account
52+
*/
1553
suspend fun getAccountByName(accountName: String): Account?
54+
55+
/**
56+
* Deletes the given [account].
57+
*
58+
* @param account the account to delete
59+
* @return the result of the account deletion attempt
60+
*/
1661
suspend fun deleteAccount(account: Account): AccountDeleteResult
1762

1863
}

surf-transaction-api/src/main/kotlin/dev/slne/surf/transaction/api/account/AccountService.kt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,43 @@ import dev.slne.surf.transaction.api.account.result.AccountCreationResult
55
import dev.slne.surf.transaction.api.util.InternalTransactionApi
66
import java.util.*
77

8+
/**
9+
* Internal service for managing accounts.
10+
*
11+
* [AccountService] is responsible for resolving, creating, and managing
12+
* accounts within the transaction system. It is used internally by the
13+
* account and transaction APIs.
14+
*
15+
* This API is strictly internal to the Surf Transaction module and must not
16+
* be used by external consumers.
17+
*/
818
@InternalTransactionApi
919
interface AccountService {
20+
21+
/**
22+
* Returns an account by its unique [accountId], or `null` if none exists.
23+
*
24+
* @param accountId the account identifier
25+
* @return the resolved account or `null`
26+
*/
1027
suspend fun getAccountByAccountId(accountId: UUID): Account?
28+
29+
/**
30+
* Returns an account by its [accountName], or `null` if none exists.
31+
*
32+
* @param accountName the name of the account
33+
* @return the resolved account or `null`
34+
*/
1135
suspend fun getAccountByName(accountName: String): Account?
36+
37+
/**
38+
* Creates a new account for the given owner.
39+
*
40+
* @param ownerUuid the UUID of the account owner
41+
* @param name the name of the new account
42+
*
43+
* @return the result of the account creation attempt
44+
*/
1245
suspend fun createAccount(ownerUuid: UUID, name: String): AccountCreationResult
1346

1447
companion object {
Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,55 @@
11
package dev.slne.surf.transaction.api.account.member
22

33
import dev.slne.surf.transaction.api.account.member.results.AccountMemberResult
4+
import org.jetbrains.annotations.ApiStatus
45
import java.util.*
5-
6+
/**
7+
* Defines member management operations for an account.
8+
*
9+
* Implementations of this interface allow accounts to manage additional members
10+
* who may have access to the account, depending on permission rules enforced
11+
* by the implementation.
12+
*/
13+
@ApiStatus.NonExtendable
614
interface AccountMemberOperations {
15+
/**
16+
* The set of UUIDs representing all members of the account.
17+
*
18+
* This does not necessarily include the account owner.
19+
*/
720
val members: Set<UUID>
821

22+
/**
23+
* Adds a new member to the account.
24+
*
25+
* @param executor the UUID of the entity performing the operation
26+
* @param target the UUID of the player to be added as a member
27+
*
28+
* @return the result of the member addition attempt
29+
*/
930
suspend fun addMember(
1031
executor: UUID,
1132
target: UUID
1233
): AccountMemberResult
1334

35+
/**
36+
* Removes a member from the account.
37+
*
38+
* @param executor the UUID of the entity performing the operation
39+
* @param target the UUID of the player to be removed from the account
40+
*
41+
* @return the result of the member removal attempt
42+
*/
1443
suspend fun removeMember(
1544
executor: UUID,
1645
target: UUID
1746
): AccountMemberResult
1847

48+
/**
49+
* Checks whether the given player is a member of the account.
50+
*
51+
* @param player the UUID of the player to check
52+
* @return `true` if the player is a member, otherwise `false`
53+
*/
1954
fun isMember(player: UUID): Boolean
2055
}
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
11
package dev.slne.surf.transaction.api.account.member.results
22

3+
/**
4+
* Represents the result of an account member modification operation.
5+
*
6+
* This result is returned when adding or removing members from an account.
7+
*/
38
enum class AccountMemberResult {
9+
10+
/**
11+
* The operation completed successfully.
12+
*/
413
SUCCESS,
14+
15+
/**
16+
* The operation did not change anything.
17+
*
18+
* This typically means the target was already in the desired state
19+
* (e.g. adding an existing member or removing a non-member).
20+
*/
521
NOTHING_CHANGED,
22+
23+
/**
24+
* The account on which the operation was attempted could not be found.
25+
*/
626
ACCOUNT_NOT_FOUND;
7-
}
27+
}

surf-transaction-api/src/main/kotlin/dev/slne/surf/transaction/api/account/result/AccountCreationResult.kt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,50 @@ package dev.slne.surf.transaction.api.account.result
22

33
import dev.slne.surf.transaction.api.account.Account
44

5+
/**
6+
* Represents the result of an account creation attempt.
7+
*
8+
* Account creation can either succeed with a newly created [Account]
9+
* or fail with a specific [FailureReason].
10+
*/
511
sealed interface AccountCreationResult {
612

13+
/**
14+
* Indicates that the account was created successfully.
15+
*
16+
* @param account the newly created account
17+
*/
718
data class Success(val account: Account) : AccountCreationResult
19+
20+
/**
21+
* Indicates that the account creation failed.
22+
*
23+
* @param reason the reason why account creation failed
24+
*/
825
data class Failed(val reason: FailureReason) : AccountCreationResult
926

27+
/**
28+
* Describes possible reasons why account creation may fail.
29+
*/
1030
enum class FailureReason {
31+
/**
32+
* An account with the given name already exists.
33+
*/
1134
NAME_ALREADY_EXISTS,
35+
36+
/**
37+
* The provided account name exceeds the maximum allowed length.
38+
*/
1239
NAME_TOO_LONG,
40+
41+
/**
42+
* The provided account name is shorter than the minimum required length.
43+
*/
1344
NAME_TOO_SHORT,
45+
46+
/**
47+
* The provided account name is a valid UUID and therefore not allowed.
48+
*/
1449
NAME_IS_UUID;
1550
}
1651
}
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
package dev.slne.surf.transaction.api.account.result
22

3+
/**
4+
* Represents the result of an account deletion attempt.
5+
*/
36
enum class AccountDeleteResult {
7+
8+
/**
9+
* The account was deleted successfully.
10+
*/
411
SUCCESS,
12+
13+
/**
14+
* The account could not be deleted because it is marked as the default account.
15+
*/
516
DEFAULT_ACCOUNT_CANNOT_BE_DELETED,
17+
18+
/**
19+
* The account to be deleted could not be found.
20+
*/
621
ACCOUNT_NOT_FOUND;
7-
}
22+
}

0 commit comments

Comments
 (0)