feat: frontend
This commit is contained in:
136
ordr-ui/app/client/controllers/ItemController.ts
Normal file
136
ordr-ui/app/client/controllers/ItemController.ts
Normal file
@@ -0,0 +1,136 @@
|
||||
import axios from 'axios'
|
||||
|
||||
import {CreateItemQuery} from '../queries/CreateItemQuery'
|
||||
import {ItemPriceResponse} from '../response/ItemPriceResponse'
|
||||
import {OrderItemPriceResponse} from '../response/OrderItemPriceResponse'
|
||||
import {SetItemPriceQuery} from '../queries/SetItemPriceQuery'
|
||||
import {GetCurrentPriceQuery} from '../queries/GetCurrentPriceQuery'
|
||||
import {AddItemToOrderQuery} from '../queries/AddItemToOrderQuery'
|
||||
import {GetOrderItemsQuery} from '../queries/GetOrderItemsQuery'
|
||||
import {SetItemMadeRequest} from '../request/SetItemMadeRequest'
|
||||
import {OrderFilledResponse} from '../response/OrderFilledResponse'
|
||||
import {SetItemQuantityRequest} from '../request/SetItemQuantityRequest'
|
||||
import {DeleteOrderItemRequest} from '../request/DeleteOrderItemRequest'
|
||||
import { ItemHistoryResponse } from '../response/ItemHistoryResponse'
|
||||
|
||||
export const CreateItem = async (query: CreateItemQuery): Promise<ItemPriceResponse> => {
|
||||
const queryParams = new URLSearchParams({
|
||||
item_name: query.item_name,
|
||||
in_season: query.in_season,
|
||||
item_price: query.item_price
|
||||
})
|
||||
|
||||
const res = await axios.post(process.env.API_URL + `/item/create?${queryParams.toString()}`)
|
||||
if (res.data.Location) {
|
||||
window.location.href = res.data.Location
|
||||
}
|
||||
|
||||
return res.data
|
||||
}
|
||||
|
||||
export const SetItemPrice = async (query: SetItemPriceQuery) => {
|
||||
const queryParams = new URLSearchParams({
|
||||
item_id: query.item_id,
|
||||
item_price: query.item_price
|
||||
})
|
||||
|
||||
const res = await axios.put(process.env.NEXT_PUBLIC_API_URL + `/item/price?${queryParams.toString()}`, {}, {withCredentials: true})
|
||||
if (res.data.Location) {
|
||||
window.location.href = res.data.Location
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const GetCurrentPrice = async (query: GetCurrentPriceQuery): Promise<ItemPriceResponse> => {
|
||||
const queryParams = new URLSearchParams({
|
||||
item_id: query.item_id
|
||||
})
|
||||
|
||||
const res = await axios.get(process.env.API_URL + `/item/price?${queryParams.toString()}`)
|
||||
if (res.data.Location) {
|
||||
window.location.href = res.data.Location
|
||||
}
|
||||
return res.data
|
||||
}
|
||||
|
||||
export const AddItemToOrder = async (query: AddItemToOrderQuery): Promise<OrderItemPriceResponse> => {
|
||||
const queryParams = new URLSearchParams({
|
||||
item_id: query.item_id,
|
||||
order_id: query.order_id,
|
||||
quantity: query.quantity
|
||||
})
|
||||
|
||||
console.log(process.env.NEXT_PUBLIC_API_URL + `/order/item?${queryParams.toString()}`)
|
||||
const res = await axios.put(process.env.NEXT_PUBLIC_API_URL + `/order/item?${queryParams.toString()}`, {}, {withCredentials: true})
|
||||
if (res.data?.Location) {
|
||||
window.location.href = res.data.Location
|
||||
}
|
||||
|
||||
return res.data
|
||||
}
|
||||
|
||||
export const GetOrderItems = async (query: GetOrderItemsQuery): Promise<OrderItemPriceResponse[]> => {
|
||||
const queryParams = new URLSearchParams({
|
||||
order_id: query.order_id
|
||||
})
|
||||
|
||||
const res = await axios.get(process.env.NEXT_PUBLIC_API_URL + `/order/items?${queryParams.toString()}`, {withCredentials: true})
|
||||
if (res.data?.Location) {
|
||||
window.location.href = res.data.Location
|
||||
}
|
||||
|
||||
return res.data || []
|
||||
}
|
||||
|
||||
export const SetItemMade = async (request: SetItemMadeRequest): Promise<OrderFilledResponse> => {
|
||||
const res = await axios.put(process.env.NEXT_PUBLIC_API_URL + '/item/made', request, {withCredentials: true})
|
||||
if (res.data?.Location) {
|
||||
window.location.href = res.data.Location
|
||||
}
|
||||
|
||||
return res.data
|
||||
}
|
||||
|
||||
export const SetItemQuantity = async (request: SetItemQuantityRequest): Promise<OrderFilledResponse> => {
|
||||
const res = await axios.put(process.env.NEXT_PUBLIC_API_URL + `/item/quantity`, request, {withCredentials: true})
|
||||
if (res.data.Location) {
|
||||
window.location.href = res.data.Location
|
||||
}
|
||||
|
||||
return res.data
|
||||
}
|
||||
|
||||
export const DeleteOrderItem = async (request: DeleteOrderItemRequest) => {
|
||||
const res = await axios.delete(process.env.API_URL + `/order/item?order_id=${request.order_id}&item_id=${request.item_id}`)
|
||||
if (res.data.Location) {
|
||||
window.location.href = res.data.Location
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const DeleteItem = async (itemId: number) => {
|
||||
const queryParams = new URLSearchParams({
|
||||
item_id: itemId.toString()
|
||||
})
|
||||
|
||||
const res = await axios.delete(process.env.API_URL + `/item?${queryParams.toString()}`)
|
||||
if (res.data.Location) {
|
||||
window.location.href = res.data.Location
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const GetItems = async (): Promise<ItemPriceResponse[]> => {
|
||||
const res = await axios.get(process.env.NEXT_PUBLIC_API_URL + `/items`, {withCredentials: true})
|
||||
|
||||
if (res.data.Location) {
|
||||
window.location.href = res.data.Location
|
||||
}
|
||||
return res.data
|
||||
}
|
||||
|
||||
export const GetItemHistory = async (itemId: number): Promise<ItemHistoryResponse[]> => {
|
||||
const res = await axios.get(process.env.NEXT_PUBLIC_API_URL + `/item/history?item_id=${itemId.toString()}`, {withCredentials: true})
|
||||
|
||||
return res.data
|
||||
}
|
||||
56
ordr-ui/app/client/controllers/OrderController.ts
Normal file
56
ordr-ui/app/client/controllers/OrderController.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import axios from 'axios'
|
||||
|
||||
import {OrderResponse} from '../response/OrderResponse'
|
||||
import {OrderTableQuery} from '../request/GetOrderTableRequest'
|
||||
|
||||
axios.interceptors.response.use(response => {
|
||||
return response;
|
||||
}, async error => {
|
||||
if (error.response.status === 401) {
|
||||
const resp = await axios.get(process.env.NEXT_PUBLIC_API_URL + "/auth/login", {withCredentials: true})
|
||||
window.location.href = resp.data.Location
|
||||
}
|
||||
return error
|
||||
})
|
||||
export const CreateOrder = async (orderer: string, dateDue: string): Promise<OrderResponse> => {
|
||||
const queryParams = new URLSearchParams({
|
||||
orderer: orderer,
|
||||
date_due: dateDue,
|
||||
date_placed: new Date().toISOString()
|
||||
})
|
||||
const res = await axios.post(process.env.NEXT_PUBLIC_API_URL + `/order/create?${queryParams.toString()}`, {}, {withCredentials: true})
|
||||
return res.data as OrderResponse
|
||||
}
|
||||
|
||||
export const GetOrderById = async (orderId: number): Promise<OrderResponse> => {
|
||||
const queryParams = new URLSearchParams({
|
||||
order_id: orderId.toString()
|
||||
})
|
||||
const res = await axios.get(process.env.API_URL + `/order?${queryParams.toString()}`)
|
||||
return res.data as OrderResponse
|
||||
}
|
||||
|
||||
export const GetOrderTable = async (page: number, filter: number, searchParams: OrderTableQuery): Promise<OrderResponse[]> => {
|
||||
const queryParams = new URLSearchParams({
|
||||
page: page.toString(),
|
||||
filter: filter.toString()
|
||||
})
|
||||
|
||||
console.log(page)
|
||||
console.log(filter)
|
||||
console.log(searchParams)
|
||||
console.log(queryParams.toString())
|
||||
const res = await axios.put(process.env.NEXT_PUBLIC_API_URL + `/order/table?${queryParams.toString()}`, searchParams, {withCredentials: true})
|
||||
if(res.data?.Location) {
|
||||
window.location.href = res.data.Location
|
||||
}
|
||||
return res.data || []
|
||||
}
|
||||
|
||||
export const DeleteOrder = async (orderId: number) => {
|
||||
const queryParams = new URLSearchParams({
|
||||
order_id: orderId.toString()
|
||||
})
|
||||
|
||||
await axios.delete(process.env.API_URL + `/order?${queryParams}`)
|
||||
}
|
||||
81
ordr-ui/app/client/controllers/UserController.ts
Normal file
81
ordr-ui/app/client/controllers/UserController.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import axios, { HttpStatusCode } from 'axios'
|
||||
import { UserResponse } from '../response/UserResponse'
|
||||
import { UserTable } from '../queries/UserTableQuery'
|
||||
import { LoginRedirectResponse } from '../response'
|
||||
|
||||
// import { cookies } from 'next/headers'
|
||||
|
||||
export const GetCurrentUser = async (): Promise<UserResponse | undefined> => {
|
||||
console.log(process.env.NEXT_PUBLIC_API_URL + "/user/current")
|
||||
const res = await axios.get(process.env.NEXT_PUBLIC_API_URL + "/user/current", {
|
||||
maxRedirects: 0,
|
||||
validateStatus: (status) => {
|
||||
return status >= 200 && status < 400
|
||||
}});
|
||||
if(res.data.Location) {
|
||||
window.location.href = res.data.Location
|
||||
}
|
||||
return res.data;
|
||||
};
|
||||
|
||||
export const GetUserTable = async (page: number): Promise<UserResponse[]> => {
|
||||
const res = await axios.put(process.env.NEXT_PUBLIC_API_URL + `/users?page=${page.toString()}`, {
|
||||
name: "",
|
||||
jobPosition: ""
|
||||
}, {
|
||||
withCredentials: true
|
||||
});
|
||||
if (res.data.Location)
|
||||
window.location.href = res.data.Location
|
||||
return res.data || []
|
||||
}
|
||||
|
||||
export const SetUserName = async (userName: string) => {
|
||||
const queryParams = new URLSearchParams({
|
||||
user_name: userName
|
||||
});
|
||||
await axios.put(process.env.NEXT_PUBLIC_API_URL + `/user/name?${queryParams.toString()}`)
|
||||
}
|
||||
|
||||
export const PromoteUser = async (userId: number) => {
|
||||
const queryParams = new URLSearchParams({
|
||||
user_id: userId.toString()
|
||||
});
|
||||
await axios.put(process.env.NEXT_PUBLIC_API_URL + `/user/promote?${queryParams.toString()}`, {}, {withCredentials: true});
|
||||
}
|
||||
|
||||
export const DemoteUser = async (userId: number) => {
|
||||
const queryParams = new URLSearchParams({
|
||||
user_id: userId.toString()
|
||||
})
|
||||
await axios.put(process.env.NEXT_PUBLIC_API_URL + `/user/demote?${queryParams.toString()}`, {}, {withCredentials: true})
|
||||
}
|
||||
|
||||
export const DeactivateUser = async (userId: number) => {
|
||||
const queryParams = new URLSearchParams({
|
||||
user_id: userId.toString()
|
||||
})
|
||||
await axios.delete(process.env.NEXT_PUBLIC_API_URL + `/user/deactivate?${queryParams.toString()}`, {withCredentials: true})
|
||||
}
|
||||
|
||||
export const ActivateUser = async (userId: number) => {
|
||||
const queryParams = new URLSearchParams({
|
||||
user_id: userId.toString()
|
||||
})
|
||||
await axios.put(process.env.NEXT_PUBLIC_API_URL + `/user/activate?${queryParams.toString()}`, {}, {withCredentials: true})
|
||||
}
|
||||
|
||||
export const CreatePosition = async (positionName: string) => {
|
||||
const queryParams = new URLSearchParams({
|
||||
position_name: positionName
|
||||
})
|
||||
await axios.post(process.env.NEXT_PUBLIC_API_URL + `/position/create?` + queryParams.toString())
|
||||
}
|
||||
|
||||
export const SetUserPosition = async (userId: number, positionName: string) => {
|
||||
const queryParams = new URLSearchParams({
|
||||
user_id: userId.toString(),
|
||||
position: positionName
|
||||
})
|
||||
await axios.put(process.env.NEXT_PUBLIC_API_URL + `/user/position?${queryParams.toString}`)
|
||||
}
|
||||
3
ordr-ui/app/client/controllers/index.ts
Normal file
3
ordr-ui/app/client/controllers/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from './ItemController'
|
||||
export * from './OrderController'
|
||||
export * from './UserController'
|
||||
Reference in New Issue
Block a user