From f5d6875551849eb55f3eecda8a2de6ae5fd7d3b0 Mon Sep 17 00:00:00 2001
From: vekaste <vekaste@stud.ntnu.no>
Date: Wed, 1 May 2024 14:38:49 +0200
Subject: [PATCH] feat: Updating API frontend

---
 src/api/models/AuthenticationResponse.ts      |  3 +
 src/api/models/ChallengeDTO.ts                | 14 ++-
 src/api/models/ChallengeTemplateDTO.ts        | 31 ++++++
 src/api/models/CreateGoalDTO.ts               |  2 +-
 ...cipantUserDTO.ts => FeedbackRequestDTO.ts} |  6 +-
 src/api/models/FeedbackResponseDTO.ts         | 11 +++
 src/api/models/GoalDTO.ts                     |  7 +-
 ...hallengeProgressDTO.ts => InventoryDTO.ts} |  7 +-
 src/api/models/ItemDTO.ts                     | 12 +++
 src/api/models/ParticipantDTO.ts              | 16 ----
 src/api/models/UserDTO.ts                     |  1 +
 src/api/services/GoalService.ts               | 67 +++++++++++--
 src/api/services/ItemService.ts               | 57 +++++++++++
 src/api/services/LeaderboardService.ts        | 12 +++
 src/api/services/UserService.ts               | 95 +++++++++++++++++++
 15 files changed, 301 insertions(+), 40 deletions(-)
 create mode 100644 src/api/models/ChallengeTemplateDTO.ts
 rename src/api/models/{ParticipantUserDTO.ts => FeedbackRequestDTO.ts} (62%)
 create mode 100644 src/api/models/FeedbackResponseDTO.ts
 rename src/api/models/{DailyChallengeProgressDTO.ts => InventoryDTO.ts} (61%)
 create mode 100644 src/api/models/ItemDTO.ts
 delete mode 100644 src/api/models/ParticipantDTO.ts
 create mode 100644 src/api/services/ItemService.ts

diff --git a/src/api/models/AuthenticationResponse.ts b/src/api/models/AuthenticationResponse.ts
index 47169ae..3cbef78 100644
--- a/src/api/models/AuthenticationResponse.ts
+++ b/src/api/models/AuthenticationResponse.ts
@@ -5,7 +5,10 @@
 export type AuthenticationResponse = {
     firstName?: string;
     lastName?: string;
+    userId?: number;
+    profileImage?: number;
     role?: string;
+    subscriptionLevel?: string;
     token?: string;
 };
 
diff --git a/src/api/models/ChallengeDTO.ts b/src/api/models/ChallengeDTO.ts
index f5bd38d..3ccf0f0 100644
--- a/src/api/models/ChallengeDTO.ts
+++ b/src/api/models/ChallengeDTO.ts
@@ -2,13 +2,17 @@
 /* istanbul ignore file */
 /* tslint:disable */
 /* eslint-disable */
-import type { DailyChallengeProgressDTO } from './DailyChallengeProgressDTO';
+import type { ChallengeTemplateDTO } from './ChallengeTemplateDTO';
+import type { ProgressDTO } from './ProgressDTO';
 export type ChallengeDTO = {
     id?: number;
-    potentialSavingAmount?: number;
+    amount?: number;
     points?: number;
-    days?: number;
-    createdAt?: string;
-    dailyChallengeProgressList?: Array<DailyChallengeProgressDTO>;
+    checkDays?: number;
+    totalDays?: number;
+    startDate?: string;
+    endDate?: string;
+    challengeTemplate?: ChallengeTemplateDTO;
+    progressList?: Array<ProgressDTO>;
 };
 
diff --git a/src/api/models/ChallengeTemplateDTO.ts b/src/api/models/ChallengeTemplateDTO.ts
new file mode 100644
index 0000000..323e64d
--- /dev/null
+++ b/src/api/models/ChallengeTemplateDTO.ts
@@ -0,0 +1,31 @@
+/* generated using openapi-typescript-codegen -- do not edit */
+/* istanbul ignore file */
+/* tslint:disable */
+/* eslint-disable */
+export type ChallengeTemplateDTO = {
+    id?: number;
+    text?: string;
+    amount?: number;
+    type?: ChallengeTemplateDTO.type;
+};
+export namespace ChallengeTemplateDTO {
+    export enum type {
+        NO_COFFEE = 'NO_COFFEE',
+        NO_CAR = 'NO_CAR',
+        SHORTER_SHOWER = 'SHORTER_SHOWER',
+        SPEND_LESS_ON_FOOD = 'SPEND_LESS_ON_FOOD',
+        BUY_USED_CLOTHES = 'BUY_USED_CLOTHES',
+        LESS_SHOPPING = 'LESS_SHOPPING',
+        DROP_SUBSCRIPTION = 'DROP_SUBSCRIPTION',
+        SELL_SOMETHING = 'SELL_SOMETHING',
+        BUY_USED = 'BUY_USED',
+        EAT_PACKED_LUNCH = 'EAT_PACKED_LUNCH',
+        STOP_SHOPPING = 'STOP_SHOPPING',
+        ZERO_SPENDING = 'ZERO_SPENDING',
+        RENT_YOUR_STUFF = 'RENT_YOUR_STUFF',
+        MEATLESS = 'MEATLESS',
+        SCREEN_TIME_LIMIT = 'SCREEN_TIME_LIMIT',
+        UNPLUGGED_ENTERTAINMENT = 'UNPLUGGED_ENTERTAINMENT',
+    }
+}
+
diff --git a/src/api/models/CreateGoalDTO.ts b/src/api/models/CreateGoalDTO.ts
index 61eb045..2e6e535 100644
--- a/src/api/models/CreateGoalDTO.ts
+++ b/src/api/models/CreateGoalDTO.ts
@@ -3,7 +3,7 @@
 /* tslint:disable */
 /* eslint-disable */
 export type CreateGoalDTO = {
-    goalName?: string;
+    name?: string;
     description?: string;
     targetAmount?: number;
     targetDate?: string;
diff --git a/src/api/models/ParticipantUserDTO.ts b/src/api/models/FeedbackRequestDTO.ts
similarity index 62%
rename from src/api/models/ParticipantUserDTO.ts
rename to src/api/models/FeedbackRequestDTO.ts
index 5499c09..174e9ef 100644
--- a/src/api/models/ParticipantUserDTO.ts
+++ b/src/api/models/FeedbackRequestDTO.ts
@@ -2,8 +2,8 @@
 /* istanbul ignore file */
 /* tslint:disable */
 /* eslint-disable */
-export type ParticipantUserDTO = {
-    firstName?: string;
-    lastName?: string;
+export type FeedbackRequestDTO = {
+    email?: string;
+    message?: string;
 };
 
diff --git a/src/api/models/FeedbackResponseDTO.ts b/src/api/models/FeedbackResponseDTO.ts
new file mode 100644
index 0000000..7b24900
--- /dev/null
+++ b/src/api/models/FeedbackResponseDTO.ts
@@ -0,0 +1,11 @@
+/* generated using openapi-typescript-codegen -- do not edit */
+/* istanbul ignore file */
+/* tslint:disable */
+/* eslint-disable */
+export type FeedbackResponseDTO = {
+    id?: string;
+    email?: string;
+    message?: string;
+    createdAt?: string;
+};
+
diff --git a/src/api/models/GoalDTO.ts b/src/api/models/GoalDTO.ts
index 004eb49..c24e9ab 100644
--- a/src/api/models/GoalDTO.ts
+++ b/src/api/models/GoalDTO.ts
@@ -3,16 +3,15 @@
 /* tslint:disable */
 /* eslint-disable */
 import type { ChallengeDTO } from './ChallengeDTO';
-import type { ParticipantDTO } from './ParticipantDTO';
+import type { UserDTO } from './UserDTO';
 export type GoalDTO = {
     id?: number;
-    goalName?: string;
+    name?: string;
     description?: string;
     targetAmount?: number;
     targetDate?: string;
-    completedAt?: string;
     createdAt?: string;
     challenges?: Array<ChallengeDTO>;
-    participants?: Array<ParticipantDTO>;
+    user?: UserDTO;
 };
 
diff --git a/src/api/models/DailyChallengeProgressDTO.ts b/src/api/models/InventoryDTO.ts
similarity index 61%
rename from src/api/models/DailyChallengeProgressDTO.ts
rename to src/api/models/InventoryDTO.ts
index c7bda73..826a6b6 100644
--- a/src/api/models/DailyChallengeProgressDTO.ts
+++ b/src/api/models/InventoryDTO.ts
@@ -2,9 +2,10 @@
 /* istanbul ignore file */
 /* tslint:disable */
 /* eslint-disable */
-export type DailyChallengeProgressDTO = {
+export type InventoryDTO = {
     id?: number;
-    challengeDay?: number;
-    completedAt?: string;
+    itemName?: string;
+    imageId?: number;
+    boughtAt?: string;
 };
 
diff --git a/src/api/models/ItemDTO.ts b/src/api/models/ItemDTO.ts
new file mode 100644
index 0000000..b2c65c3
--- /dev/null
+++ b/src/api/models/ItemDTO.ts
@@ -0,0 +1,12 @@
+/* generated using openapi-typescript-codegen -- do not edit */
+/* istanbul ignore file */
+/* tslint:disable */
+/* eslint-disable */
+export type ItemDTO = {
+    id?: number;
+    itemName?: string;
+    price?: number;
+    imageId?: number;
+    alreadyBought?: boolean;
+};
+
diff --git a/src/api/models/ParticipantDTO.ts b/src/api/models/ParticipantDTO.ts
deleted file mode 100644
index 0615b50..0000000
--- a/src/api/models/ParticipantDTO.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-/* generated using openapi-typescript-codegen -- do not edit */
-/* istanbul ignore file */
-/* tslint:disable */
-/* eslint-disable */
-import type { ParticipantUserDTO } from './ParticipantUserDTO';
-export type ParticipantDTO = {
-    role?: ParticipantDTO.role;
-    user?: ParticipantUserDTO;
-};
-export namespace ParticipantDTO {
-    export enum role {
-        CREATOR = 'CREATOR',
-        CONTRIBUTOR = 'CONTRIBUTOR',
-    }
-}
-
diff --git a/src/api/models/UserDTO.ts b/src/api/models/UserDTO.ts
index aee3ea0..2020ee7 100644
--- a/src/api/models/UserDTO.ts
+++ b/src/api/models/UserDTO.ts
@@ -10,5 +10,6 @@ export type UserDTO = {
     email?: string;
     createdAt?: string;
     role?: string;
+    subscriptionLevel?: string;
 };
 
diff --git a/src/api/services/GoalService.ts b/src/api/services/GoalService.ts
index 28ae857..b3bfa72 100644
--- a/src/api/services/GoalService.ts
+++ b/src/api/services/GoalService.ts
@@ -4,12 +4,27 @@
 /* eslint-disable */
 import type { CreateGoalDTO } from '../models/CreateGoalDTO';
 import type { GoalDTO } from '../models/GoalDTO';
+import type { MarkChallengeDTO } from '../models/MarkChallengeDTO';
 import type { CancelablePromise } from '../core/CancelablePromise';
 import { OpenAPI } from '../core/OpenAPI';
 import { request as __request } from '../core/request';
 export class GoalService {
     /**
-     * @returns GoalDTO OK
+     * Get goals
+     * Get the goals of the authenticated user
+     * @returns GoalDTO Successfully retrieved the goals
+     * @throws ApiError
+     */
+    public static getGoals(): CancelablePromise<Array<GoalDTO>> {
+        return __request(OpenAPI, {
+            method: 'GET',
+            url: '/api/goals',
+        });
+    }
+    /**
+     * Create a goal
+     * Create a new goal
+     * @returns GoalDTO Successfully created a goal
      * @throws ApiError
      */
     public static createGoal({
@@ -19,29 +34,65 @@ export class GoalService {
     }): CancelablePromise<GoalDTO> {
         return __request(OpenAPI, {
             method: 'POST',
-            url: '/api/goal/createGoal',
+            url: '/api/goals',
             body: requestBody,
             mediaType: 'application/json',
         });
     }
     /**
-     * @returns GoalDTO OK
+     * Update a challenge
+     * Update a challenge day as completed
+     * @returns any Successfully updated the challenge
      * @throws ApiError
      */
-    public static getGoals(): CancelablePromise<Array<GoalDTO>> {
+    public static updateChallenge({
+        requestBody,
+    }: {
+        requestBody: MarkChallengeDTO,
+    }): CancelablePromise<any> {
         return __request(OpenAPI, {
-            method: 'GET',
-            url: '/api/goal/getGoals',
+            method: 'POST',
+            url: '/api/goals/update-challenge',
+            body: requestBody,
+            mediaType: 'application/json',
+            errors: {
+                401: `Day is already completed or day outside of range`,
+            },
+        });
+    }
+    /**
+     * Update challenge saving amount
+     * Update the challenge saving amount
+     * @returns any Successfully updated the challenge
+     * @throws ApiError
+     */
+    public static updateChallengeAmount({
+        requestBody,
+    }: {
+        requestBody: MarkChallengeDTO,
+    }): CancelablePromise<any> {
+        return __request(OpenAPI, {
+            method: 'POST',
+            url: '/api/goals/update-challenge-amount',
+            body: requestBody,
+            mediaType: 'application/json',
         });
     }
     /**
      * @returns GoalDTO OK
      * @throws ApiError
      */
-    public static getGoal(): CancelablePromise<GoalDTO> {
+    public static getGoal({
+        id,
+    }: {
+        id: number,
+    }): CancelablePromise<GoalDTO> {
         return __request(OpenAPI, {
             method: 'GET',
-            url: '/api/goal/getGoal',
+            url: '/api/goals/{id}',
+            query: {
+                'id': id,
+            },
         });
     }
 }
diff --git a/src/api/services/ItemService.ts b/src/api/services/ItemService.ts
new file mode 100644
index 0000000..ae2a3a8
--- /dev/null
+++ b/src/api/services/ItemService.ts
@@ -0,0 +1,57 @@
+/* generated using openapi-typescript-codegen -- do not edit */
+/* istanbul ignore file */
+/* tslint:disable */
+/* eslint-disable */
+import type { InventoryDTO } from '../models/InventoryDTO';
+import type { ItemDTO } from '../models/ItemDTO';
+import type { CancelablePromise } from '../core/CancelablePromise';
+import { OpenAPI } from '../core/OpenAPI';
+import { request as __request } from '../core/request';
+export class ItemService {
+    /**
+     * Purchase an item
+     * Performs a purchase of the item by the user. Points will be deducted from the user.
+     * @returns any Item purchased and added to inventory successfully
+     * @throws ApiError
+     */
+    public static buyItem({
+        itemId,
+    }: {
+        itemId: number,
+    }): CancelablePromise<any> {
+        return __request(OpenAPI, {
+            method: 'POST',
+            url: '/api/item/{itemId}',
+            path: {
+                'itemId': itemId,
+            },
+            errors: {
+                403: `Insufficient points to purchase the item`,
+            },
+        });
+    }
+    /**
+     * Get available store items
+     * Retrieves all items available in the store and a flag indicating whether the user has purchased each item.
+     * @returns ItemDTO List of store items fetched successfully
+     * @throws ApiError
+     */
+    public static getStore(): CancelablePromise<Array<ItemDTO>> {
+        return __request(OpenAPI, {
+            method: 'GET',
+            url: '/api/item/store',
+        });
+    }
+    /**
+     * Get user inventory items
+     * Retrieves a list of all items currently in the inventory of the user.
+     * @returns InventoryDTO List of inventory items fetched successfully
+     * @throws ApiError
+     */
+    public static getInventory(): CancelablePromise<Array<InventoryDTO>> {
+        return __request(OpenAPI, {
+            method: 'GET',
+            url: '/api/item/inventory',
+        });
+    }
+}
diff --git a/src/api/services/LeaderboardService.ts b/src/api/services/LeaderboardService.ts
index f77a3cc..8a38209 100644
--- a/src/api/services/LeaderboardService.ts
+++ b/src/api/services/LeaderboardService.ts
@@ -30,6 +30,18 @@ export class LeaderboardService {
             },
         });
     }
+    /**
+     * Get sum of total points globally
+     * Get the sum of the total points of all users globally
+     * @returns number Successfully retrieved total points
+     * @throws ApiError
+     */
+    public static getTotalPoints(): CancelablePromise<number> {
+        return __request(OpenAPI, {
+            method: 'GET',
+            url: '/api/leaderboard/total-points',
+        });
+    }
     /**
      * @returns LeaderboardDTO OK
      * @throws ApiError
diff --git a/src/api/services/UserService.ts b/src/api/services/UserService.ts
index e7b8004..593418a 100644
--- a/src/api/services/UserService.ts
+++ b/src/api/services/UserService.ts
@@ -8,6 +8,8 @@ import type { BudgetRequestDTO } from '../models/BudgetRequestDTO';
 import type { BudgetResponseDTO } from '../models/BudgetResponseDTO';
 import type { ExpenseRequestDTO } from '../models/ExpenseRequestDTO';
 import type { ExpenseResponseDTO } from '../models/ExpenseResponseDTO';
+import type { FeedbackRequestDTO } from '../models/FeedbackRequestDTO';
+import type { FeedbackResponseDTO } from '../models/FeedbackResponseDTO';
 import type { PasswordResetDTO } from '../models/PasswordResetDTO';
 import type { PasswordUpdateDTO } from '../models/PasswordUpdateDTO';
 import type { ProfileDTO } from '../models/ProfileDTO';
@@ -17,6 +19,43 @@ import type { CancelablePromise } from '../core/CancelablePromise';
 import { OpenAPI } from '../core/OpenAPI';
 import { request as __request } from '../core/request';
 export class UserService {
+    /**
+     * Update User Subscription Level
+     * Updates the subscription level of the current user
+     * @returns any Subscription level updated successfully
+     * @throws ApiError
+     */
+    public static updateSubscriptionLevel({
+        subscriptionLevel,
+    }: {
+        subscriptionLevel: string,
+    }): CancelablePromise<Record<string, any>> {
+        return __request(OpenAPI, {
+            method: 'PUT',
+            url: '/api/users/subscription/{subscriptionLevel}',
+            path: {
+                'subscriptionLevel': subscriptionLevel,
+            },
+        });
+    }
+    /**
+     * Send feedback
+     * Send feedback from an email.
+     * @returns any Success
+     * @throws ApiError
+     */
+    public static sendFeedback({
+        requestBody,
+    }: {
+        requestBody: FeedbackRequestDTO,
+    }): CancelablePromise<any> {
+        return __request(OpenAPI, {
+            method: 'POST',
+            url: '/api/users/send-feedback',
+            body: requestBody,
+            mediaType: 'application/json',
+        });
+    }
     /**
      * Initiate a password reset
      * Send a password reset mail to the user with the specified email
@@ -199,6 +238,50 @@ export class UserService {
             },
         });
     }
+    /**
+     * Search for users by name and filter
+     * Returns a list of users whose names contain the specified search term and match the filter.
+     * @returns UserDTO Successfully retrieved list of users
+     * @throws ApiError
+     */
+    public static getUsersByNameAndFilter({
+        searchTerm,
+        filter,
+    }: {
+        searchTerm: string,
+        filter: string,
+    }): CancelablePromise<Array<UserDTO>> {
+        return __request(OpenAPI, {
+            method: 'GET',
+            url: '/api/users/search/{searchTerm}/{filter}',
+            path: {
+                'searchTerm': searchTerm,
+                'filter': filter,
+            },
+        });
+    }
+    /**
+     * Get X amount of random users
+     * Get X amount of random users that fit the filter
+     * @returns UserDTO Successfully retrieved list of users
+     * @throws ApiError
+     */
+    public static getRandomUsers({
+        amount,
+        filter,
+    }: {
+        amount: number,
+        filter: string,
+    }): CancelablePromise<Array<UserDTO>> {
+        return __request(OpenAPI, {
+            method: 'GET',
+            url: '/api/users/search/random/{amount}/{filter}',
+            path: {
+                'amount': amount,
+                'filter': filter,
+            },
+        });
+    }
     /**
      * Get the authenticated user
      * Get all user information for the authenticated user
@@ -211,6 +294,18 @@ export class UserService {
             url: '/api/users/me',
         });
     }
+    /**
+     * Send feedback
+     * Send feedback from a user.
+     * @returns FeedbackResponseDTO Success
+     * @throws ApiError
+     */
+    public static getFeedback(): CancelablePromise<Array<FeedbackResponseDTO>> {
+        return __request(OpenAPI, {
+            method: 'GET',
+            url: '/api/users/get-feedback',
+        });
+    }
     /**
      * Get the list of budgets
      * Get all budgets related to the authenticated user
-- 
GitLab