Skip to content

Commit

Permalink
Added backend methods to avatar stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Lizardguard committed Jan 8, 2025
1 parent cdead4e commit 5614dc8
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
24 changes: 24 additions & 0 deletions src/Components/Core/Adapters/BackendAdapter/BackendAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { LogLevelTypes } from "../../Domain/Types/LogLevelTypes";
import AdaptivityElementQuestionSubmissionTO from "../../Application/DataTransferObjects/AdaptivityElement/AdaptivityElementQuestionSubmissionTO";
import AdaptivityElementQuestionResponse from "./Types/AdaptivityElementQuestionResponse";
import AdaptivtyElementStatusResponse from "./Types/AdaptivityElementStatusResponse";
import AvatarConfigTO from "../../Application/DataTransferObjects/AvatarConfigTO";

@injectable()
export default class BackendAdapter implements IBackendPort {
Expand Down Expand Up @@ -226,4 +227,27 @@ export default class BackendAdapter implements IBackendPort {
);
return response.data;
}

async getAvatarConfig(userToken: string): Promise<string> {
const response = await axios.get<string>("/Player/Avatar", {
headers: {
token: userToken,
},
});

return response.data;
}

async updateAvatarConfig(
userToken: string,
avatarConfig: AvatarConfigTO,
): Promise<boolean> {
const response = await axios.post<boolean>("/Player/Avatar", avatarConfig, {
headers: {
token: userToken,
},
});

return response.data;
}
}
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { XAPIEvent } from "../../UseCases/ScoreH5PLearningElement/IScoreH5PLearn
import AdaptivityElementQuestionSubmissionTO from "../../DataTransferObjects/AdaptivityElement/AdaptivityElementQuestionSubmissionTO";
import AdaptivityElementQuestionResponse from "src/Components/Core/Adapters/BackendAdapter/Types/AdaptivityElementQuestionResponse";
import AdaptivtyElementStatusResponse from "../../../Adapters/BackendAdapter/Types/AdaptivityElementStatusResponse";
import AvatarConfigTO from "../../DataTransferObjects/AvatarConfigTO";

export type GetWorldDataParams = {
userToken: string;
Expand Down Expand Up @@ -77,4 +78,11 @@ export default interface IBackendPort {
elementID,
worldID,
}: ElementDataParams): Promise<AdaptivtyElementStatusResponse>;

getAvatarConfig(userToken: string): Promise<string>;

updateAvatarConfig(
userToken: string,
avatarConfig: AvatarConfigTO,
): Promise<boolean>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ export default class LoadAvatarConfigUseCase
// TODO: actually load avatar config from backend
if (!userDataEntities[0].avatar) {
userDataEntities[0].avatar = new AvatarEntity();
// let avatarConfig = await this.backend.loadAvatarConfigAsync();
let avatarConfig = await this.backend.getAvatarConfig(
userDataEntities[0].userToken,
);

console.log(avatarConfig);
}

this.avatarPort.onAvatarConfigLoaded(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type ILoggerPort from "../../Ports/Interfaces/ILoggerPort";
import { LogLevelTypes } from "src/Components/Core/Domain/Types/LogLevelTypes";
import USECASE_TYPES from "~DependencyInjection/UseCases/USECASE_TYPES";
import type ILoadAvatarConfigUseCase from "../LoadAvatarConfig/ILoadAvatarConfigUseCase";
import type IBackendPort from "../../Ports/Interfaces/IBackendPort";

@injectable()
export default class UpdateAvatarConfigUseCase
Expand All @@ -24,6 +25,8 @@ export default class UpdateAvatarConfigUseCase
private logger: ILoggerPort,
@inject(USECASE_TYPES.ILoadAvatarConfigUseCase)
private loadAvatarUseCase: ILoadAvatarConfigUseCase,
@inject(CORE_TYPES.IBackendAdapter)
private backend: IBackendPort,
) {}

async executeAsync(newAvatarConfig: Partial<AvatarConfigTO>): Promise<void> {
Expand Down Expand Up @@ -58,6 +61,12 @@ export default class UpdateAvatarConfigUseCase
newAvatarConfig,
);

//TODO: Post new (complete) avatar config to backend
this.backend.updateAvatarConfig(
userDataEntities[0].userToken,
userDataEntities[0].avatar,
);

this.logger.log(
LogLevelTypes.TRACE,
`UpdateAvatarConfigUseCase: Avatar config updated. ${JSON.stringify(difference)}`,
Expand Down

0 comments on commit 5614dc8

Please sign in to comment.