Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverting api commits #250

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,43 @@
"check": "vue-tsc && pnpm run lint && pnpm run prettier && pnpm run stylelint"
},
"dependencies": {
"@profcomff/api-uilib": "2024.9.29",
"@profcomff/api-uilib": "2024.7.2-5.2",
"axios": "^1.7.2",
"markdown-it": "^14.1.0",
"openapi-fetch": "^0.12.2",
"pinia": "^2.2.2",
"pinia": "^2.1.7",
"query-string": "^9.1.0",
"ua-parser-js": "^1.0.39",
"vue": "^3.5.10",
"vue-router": "^4.4.5",
"ua-parser-js": "^1.0.38",
"vue": "^3.4.34",
"vue-router": "^4.4.0",
"workbox-window": "^7.1.0"
},
"devDependencies": {
"@types/markdown-it": "^14.1.2",
"@types/node": "^20.16.10",
"@types/node": "^20.14.12",
"@types/ua-parser-js": "^0.7.39",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"@vitejs/plugin-vue": "^5.1.4",
"@typescript-eslint/eslint-plugin": "^7.17.0",
"@typescript-eslint/parser": "^7.17.0",
"@vitejs/plugin-vue": "^5.1.0",
"@vue/eslint-config-typescript": "^12.0.0",
"eslint": "^8.57.1",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-vue": "^9.28.0",
"openapi-typescript": "^7.4.1",
"postcss": "^8.4.47",
"eslint-plugin-vue": "^9.27.0",
"postcss": "^8.4.40",
"postcss-html": "^1.7.0",
"postcss-preset-env": "^9.6.0",
"prettier": "^3.3.3",
"stylelint": "^16.9.0",
"stylelint": "^16.7.0",
"stylelint-config-recommended-vue": "^1.5.0",
"stylelint-config-standard": "^36.0.1",
"typescript": "5.3.3",
"vite": "^5.4.8",
"vite": "^5.3.5",
"vite-plugin-eslint": "^1.8.1",
"vite-plugin-pwa": "^0.19.8",
"vite-plugin-stylelint": "^5.3.1",
"vite-plugin-vuetify": "^2.0.4",
"vite-plugin-vuetify": "^2.0.3",
"vitest": "^1.6.0",
"vue-tsc": "^2.1.6",
"vuetify": "^3.7.2"
"vue-tsc": "^2.0.29",
"vuetify": "^3.6.13"
}
}
2,918 changes: 1,379 additions & 1,539 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { onMounted } from 'vue';
import { marketingApi } from './api/marketing';
import { useProfileStore } from './store/profile';
import { useTimetableStore } from './store/timetable';
import { navbarItems } from './constants/navbarItems';
Expand All @@ -8,7 +9,6 @@ import IrdomToastList from './components/IrdomToastList.vue';
import { useToolbar } from './store/toolbar';
import IrdomToolbar from './components/IrdomToolbar.vue';
import CalendarDropdown from './views/timetable/CalendarDropdown.vue';
import apiClient from '@/api/';

const profileStore = useProfileStore();
const toolbar = useToolbar();
Expand All @@ -22,11 +22,9 @@ onMounted(async () => {
updateTokenScopes();
await updateMarketingId();
if (profileStore.marketingId) {
apiClient.POST('/marketing/v1/action', {
body: {
action: 'app loaded',
user_id: profileStore.marketingId,
},
marketingApi.writeAction({
action: 'app loaded',
user_id: profileStore.marketingId,
});
}
});
Expand Down
78 changes: 78 additions & 0 deletions src/api/BaseApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import axios, { AxiosResponse } from 'axios';
import queryString from 'query-string';
import { createClient } from '@profcomff/api-uilib';

const apiClient = createClient(import.meta.env.VITE_API_URL);
export default apiClient;

export interface DefaultResponse {
status: string;
message: string;
ru?: string;
}

export class BaseApi {
url: string;

constructor(path: string) {
this.url = import.meta.env.VITE_API_URL + path;
}

protected async get<Response, Params = never>(
path: string,
params?: Params,
headers: Record<string, string> = {}
): Promise<AxiosResponse<Response>> {
if (!headers.Authorization) {
headers.Authorization = localStorage.getItem('token') ?? '';
}

return axios.get<Response>(`${this.url}${path}`, {
params,
headers,
paramsSerializer: {
serialize: params => queryString.stringify(params, { arrayFormat: 'none' }),
},
});
}

protected async post<Response, Body = never>(
path: string,
body?: Body,
headers: Record<string, string> = {}
): Promise<AxiosResponse<Response>> {
if (!headers.Authorization) {
headers.Authorization = localStorage.getItem('token') ?? '';
}

return axios.post<Response, AxiosResponse<Response>, Body>(`${this.url}${path}`, body, {
headers,
});
}

protected async delete<Response, Params = never>(
path: string,
params?: Params,
headers: Record<string, string> = {}
): Promise<AxiosResponse<Response>> {
if (!headers.Authorization) {
headers.Authorization = localStorage.getItem('token') ?? '';
}

return axios.delete<Response>(`${this.url}${path}`, { params, headers });
}

protected async patch<Response, Body>(
path: string,
body: Body,
headers: Record<string, string> = {}
): Promise<AxiosResponse<Response>> {
if (!headers.Authorization) {
headers.Authorization = localStorage.getItem('token') ?? '';
}

return axios.patch<Response, AxiosResponse<Response>, Body>(`${this.url}${path}`, body, {
headers,
});
}
}
38 changes: 38 additions & 0 deletions src/api/EntityBaseApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { BaseApi } from './BaseApi';
import { ArrayResponse, Entity } from './models';

export interface GetAllParams {
limit?: number;
offset?: number;
}

export class EntityBaseApi<
E extends Entity,
GetAllP extends GetAllParams = never,
ModifyB = Omit<E, 'id'>,
GetP = never,
> extends BaseApi {
constructor(path: string) {
super(path);
}

public async getById(id: number, params?: GetP) {
return this.get<E, GetP>(`/${id}`, params);
}

public async getAll(params?: GetAllP) {
return this.get<ArrayResponse<E>, GetAllP>('/', params);
}

public async deleteById(id: number) {
return this.delete<string>(`/${id}`);
}

public async patchById(id: number, body: ModifyB) {
return this.patch<E, ModifyB>(`/${id}`, body);
}

public async create(body: ModifyB) {
return this.post<E, ModifyB>('', body);
}
}
74 changes: 74 additions & 0 deletions src/api/achievement/AchievementApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { BaseApi } from '../BaseApi';

interface AchievementCreate {
name: string;
description: string;
}
interface Reciever {
user_id: number;
}
export interface AchievementGet {
id: number;
name: string;
description: string;
picture: string | undefined;
owner_user_id: number;
recievers: Reciever[] | undefined;
}
interface AchievementEdit {
name?: string | null;
description?: string | null;
}
export interface UserAchievementsGet {
id: number;
achievement: AchievementGet[];
}

class AchievementApi extends BaseApi {
constructor() {
super('/achievement');
}

public async create(name: string, description: string, picture: File) {
const form = new FormData();
form.append('picture_file', picture);

return this.post<AchievementGet, AchievementCreate>('/achievement', { name, description }).then(
resp => this.patch<AchievementGet, FormData>(`/achievement/${resp.data.id}/picture`, form)
);
}

public async edit(id: number, edit: AchievementEdit) {
return this.patch<AchievementGet, AchievementEdit>(`/achievement/${id}`, edit);
}

public async getAll() {
return this.get<AchievementGet[]>('/achievement');
}

public async getOne(id: number) {
return this.get<AchievementGet>(`/achievement/${id}`);
}

public async getRecievers(id: number) {
return this.get<AchievementGet>(`/achievement/${id}/reciever`);
}

public async revoke(user_id: number, achievement_id: number) {
return this.delete<AchievementGet>(`/achievement/${achievement_id}/reciever/${user_id}`);
}

public async give(user_id: number, achievement_id: number) {
return this.post<AchievementGet>(`/achievement/${achievement_id}/reciever/${user_id}`);
}

public async getUser(id: number) {
return this.get<UserAchievementsGet>(`/user/${id}`);
}

public getPictureUrl(picture: string | undefined) {
return import.meta.env.VITE_API_URL + '/achievement/' + picture;
}
}

export const achievementApi = new AchievementApi();
2 changes: 2 additions & 0 deletions src/api/achievement/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { achievementApi } from './AchievementApi';
export type { AchievementGet, UserAchievementsGet } from './AchievementApi';
7 changes: 7 additions & 0 deletions src/api/auth/AuthBaseApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { BaseApi } from '../BaseApi';

export class AuthBaseApi extends BaseApi {
constructor(path = '') {
super(`/auth${path}`);
}
}
93 changes: 93 additions & 0 deletions src/api/auth/AuthEmailApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { DefaultResponse } from '../BaseApi';
import { AuthBaseApi } from './AuthBaseApi';
import { UNKNOWN_DEVICE } from './AuthOauth2BaseApi';

interface RegisterBody {
email: string;
password: string;
}

interface LoginBody {
email: string;
password: string;
scopes?: string[];
session_name?: string;
}

interface RequestResetEmailBody {
email: string;
}

interface ApproveEmailParams {
token: string;
}

interface RequestResetPasswordBody {
password: string;
new_password: string;
}

interface RequestResetForgottenPasswordBody {
email: string;
}

interface ResetPasswordParams {
new_password: string;
}

interface LoginResponse {
token: string;
expires: string;
id: number;
user_id: number;
session_scopes: string[];
}

class AuthEmailApi extends AuthBaseApi {
constructor() {
super('/email');
}

public async register(body: RegisterBody) {
return this.post<DefaultResponse, RegisterBody>('/registration', body);
}

public async login(body: LoginBody) {
if (!body.session_name) {
body.session_name = navigator.userAgent ?? UNKNOWN_DEVICE;
}

return this.post<LoginResponse, LoginBody>('/login', body);
}

public async approveEmail(params: ApproveEmailParams) {
return this.get<DefaultResponse, ApproveEmailParams>('/approve', params);
}

public async requestResetEmail(body: RequestResetEmailBody) {
return this.post<DefaultResponse, RequestResetEmailBody>('/reset/email/request', body);
}

public async resetEmail(params: ApproveEmailParams) {
return this.get<DefaultResponse, ApproveEmailParams>('/reset/email', params);
}

public async requestResetPassword(body: RequestResetPasswordBody) {
return this.post<DefaultResponse, RequestResetPasswordBody>('/reset/password/request', body);
}

public async requestResetForgottenPassword(body: RequestResetForgottenPasswordBody) {
return this.post<DefaultResponse, RequestResetForgottenPasswordBody>(
'/reset/password/restore',
body
);
}

public async resetPassword(body: ResetPasswordParams, token: string) {
return this.post<DefaultResponse, ResetPasswordParams>('/reset/password', body, {
'reset-token': token,
});
}
}

export const authEmailApi = new AuthEmailApi();
Loading
Loading