BokaMera.API.Host

<back to all web services

UpdateUser

Requires Authentication
The following routes are available for this service:
PUT/usersUpdate my informationUpdates the logged in users info both in customer profile and application admin profile if any exists. Users are only allowed to update their own info.
<?php namespace dtos;

use DateTime;
use Exception;
use DateInterval;
use JsonSerializable;
use ServiceStack\{IReturn,IReturnVoid,IGet,IPost,IPut,IDelete,IPatch,IMeta,IHasSessionId,IHasBearerToken,IHasVersion};
use ServiceStack\{ICrud,ICreateDb,IUpdateDb,IPatchDb,IDeleteDb,ISaveDb,AuditBase,QueryDb,QueryDb2,QueryData,QueryData2,QueryResponse};
use ServiceStack\{ResponseStatus,ResponseError,EmptyResponse,IdResponse,ArrayList,KeyValuePair2,StringResponse,StringsResponse,Tuple2,Tuple3,ByteArray};
use ServiceStack\{JsonConverters,Returns,TypeContext};


class UserProfileResponse implements JsonSerializable
{
    public function __construct(
        /** @var string */
        public string $Id='',
        /** @var string */
        public string $Firstname='',
        /** @var string */
        public string $Lastname='',
        /** @var string */
        public string $Phone='',
        /** @var string */
        public string $Email=''
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['Id'])) $this->Id = $o['Id'];
        if (isset($o['Firstname'])) $this->Firstname = $o['Firstname'];
        if (isset($o['Lastname'])) $this->Lastname = $o['Lastname'];
        if (isset($o['Phone'])) $this->Phone = $o['Phone'];
        if (isset($o['Email'])) $this->Email = $o['Email'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->Id)) $o['Id'] = $this->Id;
        if (isset($this->Firstname)) $o['Firstname'] = $this->Firstname;
        if (isset($this->Lastname)) $o['Lastname'] = $this->Lastname;
        if (isset($this->Phone)) $o['Phone'] = $this->Phone;
        if (isset($this->Email)) $o['Email'] = $this->Email;
        return empty($o) ? new class(){} : $o;
    }
}

class AdminProfile implements JsonSerializable
{
    public function __construct(
        /** @var string */
        public string $CompanyId='',
        /** @var string */
        public string $Id='',
        /** @var string|null */
        public ?string $Firstname=null,
        /** @var string|null */
        public ?string $Lastname=null,
        /** @var string|null */
        public ?string $Email=null,
        /** @var string|null */
        public ?string $WorkerId=null,
        /** @var string|null */
        public ?string $Phone=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['CompanyId'])) $this->CompanyId = $o['CompanyId'];
        if (isset($o['Id'])) $this->Id = $o['Id'];
        if (isset($o['Firstname'])) $this->Firstname = $o['Firstname'];
        if (isset($o['Lastname'])) $this->Lastname = $o['Lastname'];
        if (isset($o['Email'])) $this->Email = $o['Email'];
        if (isset($o['WorkerId'])) $this->WorkerId = $o['WorkerId'];
        if (isset($o['Phone'])) $this->Phone = $o['Phone'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->CompanyId)) $o['CompanyId'] = $this->CompanyId;
        if (isset($this->Id)) $o['Id'] = $this->Id;
        if (isset($this->Firstname)) $o['Firstname'] = $this->Firstname;
        if (isset($this->Lastname)) $o['Lastname'] = $this->Lastname;
        if (isset($this->Email)) $o['Email'] = $this->Email;
        if (isset($this->WorkerId)) $o['WorkerId'] = $this->WorkerId;
        if (isset($this->Phone)) $o['Phone'] = $this->Phone;
        return empty($o) ? new class(){} : $o;
    }
}

class UpdateUserResponse implements JsonSerializable
{
    public function __construct(
        /** @var Object|null */
        public ?Object $ResponseStatus=null,
        /** @description The user id for your profile. */
        // @ApiMember(Description="The user id for your profile.", IsRequired=true)
        /** @var string */
        public string $UserId='',

        /** @var UserProfileResponse|null */
        public ?UserProfileResponse $UserProfile=null,
        /** @var AdminProfile|null */
        public ?AdminProfile $AdminProfile=null,
        /** @var bool|null */
        public ?bool $IsSentConfirmationUpdateEmail=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['ResponseStatus'])) $this->ResponseStatus = JsonConverters::from('Object', $o['ResponseStatus']);
        if (isset($o['UserId'])) $this->UserId = $o['UserId'];
        if (isset($o['UserProfile'])) $this->UserProfile = JsonConverters::from('UserProfileResponse', $o['UserProfile']);
        if (isset($o['AdminProfile'])) $this->AdminProfile = JsonConverters::from('AdminProfile', $o['AdminProfile']);
        if (isset($o['IsSentConfirmationUpdateEmail'])) $this->IsSentConfirmationUpdateEmail = $o['IsSentConfirmationUpdateEmail'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->ResponseStatus)) $o['ResponseStatus'] = JsonConverters::to('Object', $this->ResponseStatus);
        if (isset($this->UserId)) $o['UserId'] = $this->UserId;
        if (isset($this->UserProfile)) $o['UserProfile'] = JsonConverters::to('UserProfileResponse', $this->UserProfile);
        if (isset($this->AdminProfile)) $o['AdminProfile'] = JsonConverters::to('AdminProfile', $this->AdminProfile);
        if (isset($this->IsSentConfirmationUpdateEmail)) $o['IsSentConfirmationUpdateEmail'] = $this->IsSentConfirmationUpdateEmail;
        return empty($o) ? new class(){} : $o;
    }
}

class UpdateCustomerProfile implements JsonSerializable
{
    public function __construct(
        /** @var string */
        public string $Firstname='',
        /** @var string */
        public string $Lastname='',
        /** @var string */
        public string $Phone='',
        /** @var string */
        public string $Email=''
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['Firstname'])) $this->Firstname = $o['Firstname'];
        if (isset($o['Lastname'])) $this->Lastname = $o['Lastname'];
        if (isset($o['Phone'])) $this->Phone = $o['Phone'];
        if (isset($o['Email'])) $this->Email = $o['Email'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->Firstname)) $o['Firstname'] = $this->Firstname;
        if (isset($this->Lastname)) $o['Lastname'] = $this->Lastname;
        if (isset($this->Phone)) $o['Phone'] = $this->Phone;
        if (isset($this->Email)) $o['Email'] = $this->Email;
        return empty($o) ? new class(){} : $o;
    }
}

class UpdateAdminProfile implements JsonSerializable
{
    public function __construct(
        /** @var string */
        public string $Firstname='',
        /** @var string */
        public string $Lastname='',
        /** @var string */
        public string $Phone='',
        /** @var string */
        public string $Email=''
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['Firstname'])) $this->Firstname = $o['Firstname'];
        if (isset($o['Lastname'])) $this->Lastname = $o['Lastname'];
        if (isset($o['Phone'])) $this->Phone = $o['Phone'];
        if (isset($o['Email'])) $this->Email = $o['Email'];
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->Firstname)) $o['Firstname'] = $this->Firstname;
        if (isset($this->Lastname)) $o['Lastname'] = $this->Lastname;
        if (isset($this->Phone)) $o['Phone'] = $this->Phone;
        if (isset($this->Email)) $o['Email'] = $this->Email;
        return empty($o) ? new class(){} : $o;
    }
}

enum KeyCloakRealm : int
{
    case BookMore = 1;
    case BookMoreAdmin = 2;
    case SuperAdmin = 3;
}

// @ApiResponse(Description="Returned if there is a validation error on the input parameters", StatusCode=400)
// @ApiResponse(Description="Returned if the current user is not allowed to perform the action", StatusCode=401)
// @ValidateRequest(Validator="IsAuthenticated")
class UpdateUser implements JsonSerializable
{
    public function __construct(
        /** @description The user id for your profile. */
        // @ApiMember(Description="The user id for your profile.")
        /** @var string|null */
        public ?string $UserId=null,

        /** @var string */
        public string $NewEmail='',
        /** @var UpdateCustomerProfile|null */
        public ?UpdateCustomerProfile $UserProfile=null,
        /** @var UpdateAdminProfile|null */
        public ?UpdateAdminProfile $AdminProfile=null,
        /** @description The user realm for identity server.  BookMore = 1, BookMoreAdmin = 2  */
        // @ApiMember(Description="The user realm for identity server.  BookMore = 1, BookMoreAdmin = 2 ", IsRequired=true)
        /** @var KeyCloakRealm|null */
        public ?KeyCloakRealm $Realm=null
    ) {
    }

    /** @throws Exception */
    public function fromMap($o): void {
        if (isset($o['UserId'])) $this->UserId = $o['UserId'];
        if (isset($o['NewEmail'])) $this->NewEmail = $o['NewEmail'];
        if (isset($o['UserProfile'])) $this->UserProfile = JsonConverters::from('UpdateCustomerProfile', $o['UserProfile']);
        if (isset($o['AdminProfile'])) $this->AdminProfile = JsonConverters::from('UpdateAdminProfile', $o['AdminProfile']);
        if (isset($o['Realm'])) $this->Realm = JsonConverters::from('KeyCloakRealm', $o['Realm']);
    }
    
    /** @throws Exception */
    public function jsonSerialize(): mixed
    {
        $o = [];
        if (isset($this->UserId)) $o['UserId'] = $this->UserId;
        if (isset($this->NewEmail)) $o['NewEmail'] = $this->NewEmail;
        if (isset($this->UserProfile)) $o['UserProfile'] = JsonConverters::to('UpdateCustomerProfile', $this->UserProfile);
        if (isset($this->AdminProfile)) $o['AdminProfile'] = JsonConverters::to('UpdateAdminProfile', $this->AdminProfile);
        if (isset($this->Realm)) $o['Realm'] = JsonConverters::to('KeyCloakRealm', $this->Realm);
        return empty($o) ? new class(){} : $o;
    }
}

PHP UpdateUser DTOs

To override the Content-type in your clients, use the HTTP Accept Header, append the .json suffix or ?format=json

To embed the response in a jsonp callback, append ?callback=myCallback

HTTP + JSON

The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.

PUT /users HTTP/1.1 
Host: api.bokamera.se 
Accept: application/json
Content-Type: application/json
Content-Length: length

{"UserId":"00000000-0000-0000-0000-000000000000","NewEmail":"String","UserProfile":{"Firstname":"String","Lastname":"String","Phone":"String","Email":"String"},"AdminProfile":{"Firstname":"String","Lastname":"String","Phone":"String","Email":"String"},"Realm":"BookMore"}
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: length

{"ResponseStatus":{},"UserId":"00000000-0000-0000-0000-000000000000","UserProfile":{"Firstname":"String","Lastname":"String","Phone":"String","Email":"String"},"AdminProfile":{"Firstname":"String","Lastname":"String","Email":"String","WorkerId":"String","Phone":"String"},"IsSentConfirmationUpdateEmail":false}