react-version #1

Merged
memartel_loc merged 290 commits from react-version into main 2023-11-04 09:48:15 -04:00
5 changed files with 53 additions and 28 deletions
Showing only changes of commit 0ffa974bd3 - Show all commits

View File

@ -38,7 +38,7 @@ public class AddressController : Controller {
#endregion
#region API Methods
[EnableCors("_myAllowSpecificOrigins"), HttpGet(Name = "Addresses"), Route("ListAddresses")]
[EnableCors("_myAllowSpecificOrigins"), HttpGet]
public async Task<ActionResult<List<AddressModel>>> GetList(bool? all) {
IList<string> roles;
InventoryUser user;
@ -69,7 +69,7 @@ public class AddressController : Controller {
}
}
[EnableCors("_myAllowSpecificOrigins"), HttpGet(Name = "Address")]
[EnableCors("_myAllowSpecificOrigins"), HttpGet("{id}")]
public async Task<ActionResult<AddressModel>> Get(int id) {
IList<string> roles;
string userId;
@ -103,7 +103,7 @@ public class AddressController : Controller {
else return Unauthorized();
}
[EnableCors("_myAllowSpecificOrigins"), HttpPost(Name = "Address")]
[EnableCors("_myAllowSpecificOrigins"), HttpPost]
public async Task<ActionResult<AddressModel>> Post(AddressModel ad) {
try {
var user = await _userMan.GetUserAsync(_signInMan.Context.User);
@ -117,7 +117,7 @@ public class AddressController : Controller {
return ad;
}
[EnableCors("_myAllowSpecificOrigins"), HttpPatch(Name = "Address")]
[EnableCors("_myAllowSpecificOrigins"), HttpPatch]
public async Task<ActionResult<AddressModel>> Patch(AddressModel ad) {
IList<string> roles;
InventoryUser user;
@ -149,7 +149,7 @@ public class AddressController : Controller {
return ad;
}
[EnableCors("_myAllowSpecificOrigins"), HttpDelete(Name = "Address")]
[EnableCors("_myAllowSpecificOrigins"), HttpDelete]
public async Task<ActionResult<int>> Delete(int id) {
IList<string> roles;
AddressModel ad;

View File

@ -43,7 +43,7 @@ public class InvoiceController : Controller {
#endregion
#region API Methods
[HttpGet, Route("GetList"), Authorize(Roles = "Client, Administrateur")]
[HttpGet, Authorize(Roles = "Client, Administrateur")]
public async Task<ActionResult<List<InvoiceModel>>> Get(bool? all = false) {
IList<string> roles;
string id;
@ -67,7 +67,7 @@ public class InvoiceController : Controller {
}
}
[HttpGet, Route("Get"), Authorize(Roles = "Client, Administrateur")]
[HttpGet("{id}"), Authorize(Roles = "Client, Administrateur")]
public async Task<ActionResult<InvoiceModel>> Get(int id) {
IList<string> roles;
InvoiceModel inv;
@ -166,7 +166,7 @@ public class InvoiceController : Controller {
return Ok(inv);
}
[HttpPost, Route("CancelInvoice"), Authorize(Roles = "Client, Administrateur")]
[HttpPost("Cancel/{id}"), Authorize(Roles = "Client, Administrateur")]
public async Task<ActionResult<InvoiceModel>> Cancel(int id) {
InvoiceModel inv;
IList<string> roles;

View File

@ -13,6 +13,7 @@ using GrossesMitainesAPI.Services;
using System.Drawing;
using System.IO;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.AspNetCore.Routing;
#endregion
/// <summary>
@ -44,12 +45,12 @@ public class ProductController : ControllerBase {
#endregion
#region API Methods
[EnableCors("_myAllowSpecificOrigins"), Route("Quantity"), HttpGet(Name = "Product"), AllowAnonymous]
[EnableCors("_myAllowSpecificOrigins"), HttpGet("Quantity"), AllowAnonymous]
public ActionResult<uint> ProdCount(int id) {
return _context.Products.FirstOrDefault(x => x.Id == id).Quantity;
}
[EnableCors("_myAllowSpecificOrigins"), HttpGet(Name = "Product"), AllowAnonymous]
[EnableCors("_myAllowSpecificOrigins"), HttpGet(), AllowAnonymous]
public ActionResult<ProductViewModel> Get(int id) {
ProductModel prod;
try {
@ -63,7 +64,7 @@ public class ProductController : ControllerBase {
return new ProductViewModel(prod);
}
[EnableCors("_myAllowSpecificOrigins"), HttpPost(Name = "Product")]
[EnableCors("_myAllowSpecificOrigins"), HttpPost()]
public async Task<ActionResult<ProductModel>> Post([FromForm] ProductModel prod) {
if (prod.Price <= prod.PromoPrice)
prod.PromoPrice = prod.Price - 0.01M;
@ -82,7 +83,7 @@ public class ProductController : ControllerBase {
return prod;
}
[EnableCors("_myAllowSpecificOrigins"), HttpPatch(Name = "Product")]
[EnableCors("_myAllowSpecificOrigins"), HttpPatch()]
public async Task<ActionResult<ProductModel>> Patch([FromForm] ProductModel prod) {
string? oldImage = "";
try {
@ -106,7 +107,7 @@ public class ProductController : ControllerBase {
return prod;
}
[EnableCors("_myAllowSpecificOrigins"), HttpDelete(Name = "Product")]
[EnableCors("_myAllowSpecificOrigins"), HttpDelete()]
public ActionResult<int> Delete(int id) {
try {
var prod = _context.Products.Where(x => x.Id == id).First();

View File

@ -11,6 +11,7 @@
<PackageReference Include="Microsoft.AspNet.WebApi.Core" Version="5.2.9" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="2.2.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.10">
<PrivateAssets>all</PrivateAssets>

View File

@ -11,24 +11,47 @@ import Login from "../pages/Login";
import Logout from "../pages/Logout";
import Register from "../pages/Register";
import Formulaire from "../pages/Formulaire";
import { useState, useEffect } from "react";
import React from 'react';
const UserContext = React.createContext();
const App = () => {
const [user, setUser] = useState(null);
useEffect(() => {
async function FetchUser() {
const response = await fetch(`https://localhost:7292/api/WhoAmI`, { credentials: 'include'});
if (response.status === 200) {
setUser(await response.json());
}
else setUser({hasCookie: false})
console.log(user)
}
if (user === null) {
FetchUser();
}
});
return (
<BrowserRouter>
<Routes>
<Route path="/" element={<Layout />}>
<Route index element={<Home />} />
<Route path="morceaux" element={<Morceaux/>} />
<Route path="aboutUs" element={<AboutUs/>} />
<Route path="contactUs" element={<ContactUs/>}/>
<Route path="privacy" element={<Privacy/>}/>
<Route path="morceaux/:id" element={<MorceauDetail/>}/>
<Route path="inventaire" element={<Inventaire/>}/>
<Route path="login" element={<Login/>}/>
<Route path="logout" element={<Logout/>}/>
<Route path="register" element={<Register/>}/>
<Route path="formulaire" element={<Formulaire/>}/>
</Route>
</Routes>
<UserContext.Provider value={user}>
<Routes>
<Route path="/" element={<Layout />}>
<Route index element={<Home />} />
<Route path="morceaux" element={<Morceaux/>} />
<Route path="aboutUs" element={<AboutUs/>} />
<Route path="contactUs" element={<ContactUs/>}/>
<Route path="privacy" element={<Privacy/>}/>
<Route path="morceaux/:id" element={<MorceauDetail/>}/>
<Route path="inventaire" element={<Inventaire/>}/>
<Route path="login" element={<Login/>}/>
<Route path="logout" element={<Logout/>}/>
<Route path="register" element={<Register/>}/>
<Route path="formulaire" element={<Formulaire/>}/>
</Route>
</Routes>
</UserContext.Provider>
</BrowserRouter>
);
};