[FEAT]: add users list data
This commit is contained in:
parent
69ab5c0002
commit
143e3513da
@ -1,8 +1,8 @@
|
|||||||
import UsersModel from '../../common/data/model/usersModel';
|
import UsersModel from '../../common/data/model/usersModel';
|
||||||
import { GetUsersResponse } from '../data/response-object/protocols';
|
import { GetUsersResponse } from '../data/response-object/protocols';
|
||||||
|
|
||||||
export interface IgetusersInfra {
|
export interface IgetUsersInfra {
|
||||||
httpHandler: () => Promise<GetUsersResponse>;
|
httpHandler: () => Promise<GetUsersResponse>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type getusersReturnType = () => Promise<UsersModel>;
|
export type getUsersReturnType = () => Promise<UsersModel>;
|
||||||
|
5
src/business-logic/core/users/get-users/ports.ts
Normal file
5
src/business-logic/core/users/get-users/ports.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { getUsersReturnType, type IgetUsersInfra } from './infra/protocols';
|
||||||
|
|
||||||
|
export default IgetUsersInfra;
|
||||||
|
|
||||||
|
export type getUsersReturnPort = getUsersReturnType;
|
29
src/driven/adapters/get-users-adapter/getUsersAdapter.ts
Normal file
29
src/driven/adapters/get-users-adapter/getUsersAdapter.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import { apiUrls } from '~/driven/utils/configs/appConfig';
|
||||||
|
import { HttpOptionsType } from '~/driven/boundaries/http-boundary/protocols';
|
||||||
|
import { HTTPPovider } from '~/driven/boundaries/http-boundary/httpBoundary';
|
||||||
|
import { GetUsersResponse } from '~/business-logic/core/users/get-users/data/response-object/protocols';
|
||||||
|
import IGetUsersPort from '~/business-logic/core/users/get-users/ports';
|
||||||
|
import { getUsersAdapterReturnType } from './protocols';
|
||||||
|
|
||||||
|
const getUsersAdapter = (): IGetUsersPort & getUsersAdapterReturnType => {
|
||||||
|
// url of api
|
||||||
|
const url = apiUrls.core.getUsers;
|
||||||
|
// make the options of request
|
||||||
|
const options: HttpOptionsType = {
|
||||||
|
url,
|
||||||
|
method: 'GET',
|
||||||
|
};
|
||||||
|
// make the httpHandler
|
||||||
|
const httpProvider = new HTTPPovider();
|
||||||
|
|
||||||
|
const httpHandler = async () =>
|
||||||
|
httpProvider.request<GetUsersResponse>(options);
|
||||||
|
|
||||||
|
// return the method
|
||||||
|
return {
|
||||||
|
httpHandler,
|
||||||
|
url,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export default getUsersAdapter;
|
3
src/driven/adapters/get-users-adapter/protocols.ts
Normal file
3
src/driven/adapters/get-users-adapter/protocols.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export type getUsersAdapterReturnType = {
|
||||||
|
url: string;
|
||||||
|
};
|
@ -1,4 +1,8 @@
|
|||||||
import { errorHandlingStateTypes, UIErrorHandling } from './protocols/globalHelpersProtocols';
|
import StateManagementService from '~/driven/boundaries/state-management';
|
||||||
|
import {
|
||||||
|
errorHandlingStateTypes,
|
||||||
|
UIErrorHandling,
|
||||||
|
} from './protocols/globalHelpersProtocols';
|
||||||
|
|
||||||
export const UIErrorHandlingFactory = <DATA_RESPONSE>({
|
export const UIErrorHandlingFactory = <DATA_RESPONSE>({
|
||||||
state,
|
state,
|
||||||
@ -13,3 +17,14 @@ export const UIErrorHandlingFactory = <DATA_RESPONSE>({
|
|||||||
message,
|
message,
|
||||||
state,
|
state,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const prepareStateManagementForVM = <ReturnType>(
|
||||||
|
apiUrl: string,
|
||||||
|
model: () => Promise<ReturnType>
|
||||||
|
) => {
|
||||||
|
const stateManagement = StateManagementService.swr();
|
||||||
|
|
||||||
|
const useGetPlacesList = () => stateManagement.useGetQuery(apiUrl, model);
|
||||||
|
|
||||||
|
return useGetPlacesList;
|
||||||
|
};
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import getPlaces from '~/business-logic/core/places/get-places';
|
import getPlaces from '~/business-logic/core/places/get-places';
|
||||||
import getPlacesAdapter from '~/driven/adapters/get-places-adapter/getPlacesAdapter';
|
import getPlacesAdapter from '~/driven/adapters/get-places-adapter/getPlacesAdapter';
|
||||||
import StateManagementService from '~/driven/boundaries/state-management';
|
|
||||||
import PlacesModel from '~/business-logic/core/places/common/model/placesModel';
|
import PlacesModel from '~/business-logic/core/places/common/model/placesModel';
|
||||||
|
import { prepareStateManagementForVM } from '~/driven/utils/helpers/globalHelpers';
|
||||||
import PlacesListView from '../view/PlacesListView';
|
import PlacesListView from '../view/PlacesListView';
|
||||||
import usePlacesListVM from '../viewmodel/placesListVM';
|
import usePlacesListVM from '../viewmodel/placesListVM';
|
||||||
import placesListModel from '../model/placesListModel';
|
import placesListModel from '../model/placesListModel';
|
||||||
@ -14,23 +14,14 @@ const prepareTheLogicForModel = () => {
|
|||||||
return { getingPlacesLogic, url };
|
return { getingPlacesLogic, url };
|
||||||
};
|
};
|
||||||
|
|
||||||
const prepareStateManagementForVM = (
|
|
||||||
apiUrl: string,
|
|
||||||
placesModel: () => Promise<PlacesModel>
|
|
||||||
) => {
|
|
||||||
const stateManagement = StateManagementService.swr();
|
|
||||||
|
|
||||||
const useGetPlacesList = () =>
|
|
||||||
stateManagement.useGetQuery(apiUrl, placesModel);
|
|
||||||
|
|
||||||
return useGetPlacesList;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function PlacessList() {
|
export default function PlacessList() {
|
||||||
const { getingPlacesLogic, url } = prepareTheLogicForModel();
|
const { getingPlacesLogic, url } = prepareTheLogicForModel();
|
||||||
const placesModel = async () => await placesListModel(getingPlacesLogic);
|
const placesModel = async () => await placesListModel(getingPlacesLogic);
|
||||||
|
|
||||||
const useGetPlacesList = prepareStateManagementForVM(url, placesModel);
|
const useGetPlacesList = prepareStateManagementForVM<PlacesModel>(
|
||||||
|
url,
|
||||||
|
placesModel
|
||||||
|
);
|
||||||
const { selectedRowId, setSelectedRowId, placesData } = usePlacesListVM({
|
const { selectedRowId, setSelectedRowId, placesData } = usePlacesListVM({
|
||||||
useGetPlacesList,
|
useGetPlacesList,
|
||||||
});
|
});
|
||||||
|
@ -1,8 +1,34 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import getUsersAdapter from '~/driven/adapters/get-users-adapter/getUsersAdapter';
|
||||||
|
import getUsers from '~/business-logic/core/users/get-users';
|
||||||
|
import UsersModel from '~/business-logic/core/users/common/data/model/usersModel';
|
||||||
|
import { prepareStateManagementForVM } from '~/driven/utils/helpers/globalHelpers';
|
||||||
import useUsersListVM from '../viewmodel/usersListVM';
|
import useUsersListVM from '../viewmodel/usersListVM';
|
||||||
import UsersListView from '../view/UsersListView';
|
import UsersListView from '../view/UsersListView';
|
||||||
|
import usersListModel from '../model/usersListModel';
|
||||||
|
|
||||||
|
const prepareTheLogicForModel = () => {
|
||||||
|
const gettingUsersDrivenAdapter = getUsersAdapter();
|
||||||
|
const { url } = gettingUsersDrivenAdapter;
|
||||||
|
const getingusersLogic = getUsers(gettingUsersDrivenAdapter);
|
||||||
|
return { getingusersLogic, url };
|
||||||
|
};
|
||||||
|
|
||||||
export default function UsersList() {
|
export default function UsersList() {
|
||||||
const { selectedRowId, setSelectedRowId } = useUsersListVM();
|
const { getingusersLogic, url } = prepareTheLogicForModel();
|
||||||
return <UsersListView selectedRowId={selectedRowId} setSelectedRowId={setSelectedRowId} />;
|
const usersModel = async () => await usersListModel(getingusersLogic);
|
||||||
|
const useGetusersList = prepareStateManagementForVM<UsersModel>(
|
||||||
|
url,
|
||||||
|
usersModel
|
||||||
|
);
|
||||||
|
const { selectedRowId, setSelectedRowId, usersData } = useUsersListVM({
|
||||||
|
useGetusersList,
|
||||||
|
});
|
||||||
|
return (
|
||||||
|
<UsersListView
|
||||||
|
usersList={usersData}
|
||||||
|
selectedRowId={selectedRowId}
|
||||||
|
setSelectedRowId={setSelectedRowId}
|
||||||
|
/>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
import UsersModel from '~/business-logic/core/users/common/data/model/usersModel';
|
||||||
|
import { getUsersReturnPort } from '~/business-logic/core/users/get-users/ports';
|
||||||
|
|
||||||
|
export type getUsersModel = (
|
||||||
|
getUsers: getUsersReturnPort
|
||||||
|
) => Promise<UsersModel>;
|
@ -0,0 +1,10 @@
|
|||||||
|
import { getUsersModel } from './protocols';
|
||||||
|
|
||||||
|
const usersListModel: getUsersModel = async (getUsers) => {
|
||||||
|
// get the method for handling the logic
|
||||||
|
const users = await getUsers();
|
||||||
|
return users;
|
||||||
|
// handling the errors
|
||||||
|
};
|
||||||
|
|
||||||
|
export default usersListModel;
|
@ -4,8 +4,8 @@ import TableRow from '../../common/table-row';
|
|||||||
import { IUserListProps } from './protocols';
|
import { IUserListProps } from './protocols';
|
||||||
|
|
||||||
export default function UsersListView(props: IUserListProps) {
|
export default function UsersListView(props: IUserListProps) {
|
||||||
const { selectedRowId, setSelectedRowId } = props;
|
const { selectedRowId, setSelectedRowId, usersList } = props;
|
||||||
|
console.log(usersList.data);
|
||||||
const rows = () => {
|
const rows = () => {
|
||||||
const userdata = [
|
const userdata = [
|
||||||
{
|
{
|
||||||
@ -37,11 +37,11 @@ export default function UsersListView(props: IUserListProps) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<table className='table-auto rounded-md w-full text-sm'>
|
<table className="table-auto rounded-md w-full text-sm">
|
||||||
<thead className='text-txt-medium font-bold'>
|
<thead className="text-txt-medium font-bold">
|
||||||
<tr>
|
<tr>
|
||||||
<th className='py-3'>{staticMessages.global.fistname}</th>
|
<th className="py-3">{staticMessages.global.fistname}</th>
|
||||||
<th className='py-3'>{staticMessages.global.lastname}</th>
|
<th className="py-3">{staticMessages.global.lastname}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>{rows()}</tbody>
|
<tbody>{rows()}</tbody>
|
||||||
|
@ -1,4 +1,11 @@
|
|||||||
|
import UsersModel from '~/business-logic/core/users/common/data/model/usersModel';
|
||||||
|
|
||||||
export interface IUserListProps {
|
export interface IUserListProps {
|
||||||
selectedRowId: string;
|
selectedRowId: string;
|
||||||
setSelectedRowId: React.Dispatch<React.SetStateAction<string>>;
|
setSelectedRowId: React.Dispatch<React.SetStateAction<string>>;
|
||||||
|
usersList: {
|
||||||
|
data: UsersModel | undefined;
|
||||||
|
isLoading: boolean;
|
||||||
|
error?: string | undefined;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import UsersModel from '~/business-logic/core/users/common/data/model/usersModel';
|
||||||
|
|
||||||
export type userListReturnType = {
|
export type userListReturnType = {
|
||||||
selectedRowId: string;
|
selectedRowId: string;
|
||||||
setSelectedRowId: React.Dispatch<React.SetStateAction<string>>;
|
setSelectedRowId: React.Dispatch<React.SetStateAction<string>>;
|
||||||
|
usersData: {
|
||||||
|
data: UsersModel | undefined;
|
||||||
|
isLoading: boolean;
|
||||||
|
error?: string | undefined;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
@ -1,12 +1,23 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
import UsersModel from '~/business-logic/core/users/common/data/model/usersModel';
|
||||||
import { userListReturnType } from './protocols';
|
import { userListReturnType } from './protocols';
|
||||||
|
|
||||||
const useUsersListVM = (): userListReturnType => {
|
interface IUsersListVM {
|
||||||
|
useGetusersList: () => {
|
||||||
|
data: UsersModel | undefined;
|
||||||
|
isLoading: boolean;
|
||||||
|
error?: string | undefined;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const useUsersListVM = (dependencies: IUsersListVM): userListReturnType => {
|
||||||
|
const { useGetusersList } = dependencies;
|
||||||
const [selectedRowId, setSelectedRowId] = useState<string>('');
|
const [selectedRowId, setSelectedRowId] = useState<string>('');
|
||||||
|
const usersData = useGetusersList();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
selectedRowId,
|
selectedRowId,
|
||||||
setSelectedRowId,
|
setSelectedRowId,
|
||||||
|
usersData,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user