diff --git a/general.capnp b/general.capnp index 01460cc..8819eef 100644 --- a/general.capnp +++ b/general.capnp @@ -33,3 +33,13 @@ struct Optional(T) { just @1 :T; } } + +struct Fallible(T, E) { + # Some operations can fail in several expected ways. + # In those cases returning an `Optional` doesn't transfer information about the way that the + # operation failed. `Fallible` contains this information in the generic `E` type. + union { + successful @0 :T; + failed @1 :E; + } +} diff --git a/usersystem.capnp b/usersystem.capnp index f5754c4..722065b 100644 --- a/usersystem.capnp +++ b/usersystem.capnp @@ -8,6 +8,8 @@ $CSharp.namespace("FabAccessAPI.Schema"); using General = import "general.capnp"; using User = import "user.capnp".User; +using Optional = General.Optional; +using Fallible = General.Fallible; struct UserSystem { @@ -16,11 +18,23 @@ struct UserSystem getUserSelf @0 ( ) -> User; } + search @2 :Search; + interface Search $CSharp.name("SearchInterface") { + getUserByName @0 (username: Text) -> Optional(User); + } + manage @1 :Manage; interface Manage $CSharp.name("ManageInterface") { getUserList @0 () -> ( user_list :List(User) ); - addUser @1 (username :Text, password: Text) -> User; + enum AddUserError { + alreadyExists @0; + # An user with that username already exists + usernameInvalid @1; + # The provided username is unusable, e.g. contains invalid characters, + # is too long or too short. + } + addUser @1 (username :Text, password: Text) -> Fallible(User, AddUserError); removeUser @2 (user: User); } }