fix: добавил создание кредитных программ, починил по тупому cors и id на клиенте решил генерить
This commit is contained in:
@@ -54,7 +54,7 @@ public class CreditProgramAdapter : ICreditProgramAdapter
|
|||||||
{
|
{
|
||||||
_logger.LogError(ex, "StorageException");
|
_logger.LogError(ex, "StorageException");
|
||||||
return CreditProgramOperationResponse.InternalServerError(
|
return CreditProgramOperationResponse.InternalServerError(
|
||||||
$"Error while working with data storage:{ex.InnerException!.Message}"
|
$"Error while working with data storage:{ex.InnerException?.Message}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -86,7 +86,7 @@ public class CreditProgramAdapter : ICreditProgramAdapter
|
|||||||
{
|
{
|
||||||
_logger.LogError(ex, "StorageException");
|
_logger.LogError(ex, "StorageException");
|
||||||
return CreditProgramOperationResponse.InternalServerError(
|
return CreditProgramOperationResponse.InternalServerError(
|
||||||
$"Error while working with data storage: {ex.InnerException!.Message}"
|
$"Error while working with data storage: {ex.InnerException?.Message}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -122,7 +122,7 @@ public class CreditProgramAdapter : ICreditProgramAdapter
|
|||||||
{
|
{
|
||||||
_logger.LogError(ex, "StorageException");
|
_logger.LogError(ex, "StorageException");
|
||||||
return CreditProgramOperationResponse.BadRequest(
|
return CreditProgramOperationResponse.BadRequest(
|
||||||
$"Error while working with data storage: {ex.InnerException!.Message}"
|
$"Error while working with data storage: {ex.InnerException?.Message}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -164,7 +164,7 @@ public class CreditProgramAdapter : ICreditProgramAdapter
|
|||||||
{
|
{
|
||||||
_logger.LogError(ex, "StorageException");
|
_logger.LogError(ex, "StorageException");
|
||||||
return CreditProgramOperationResponse.BadRequest(
|
return CreditProgramOperationResponse.BadRequest(
|
||||||
$"Error while working with data storage: {ex.InnerException!.Message}"
|
$"Error while working with data storage: {ex.InnerException?.Message}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -195,7 +195,7 @@ public class CreditProgramAdapter : ICreditProgramAdapter
|
|||||||
{
|
{
|
||||||
_logger.LogError(ex, "StorageException");
|
_logger.LogError(ex, "StorageException");
|
||||||
return CreditProgramOperationResponse.InternalServerError(
|
return CreditProgramOperationResponse.InternalServerError(
|
||||||
$"Error while working with data storage:{ex.InnerException!.Message}"
|
$"Error while working with data storage:{ex.InnerException?.Message}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -226,7 +226,7 @@ public class CreditProgramAdapter : ICreditProgramAdapter
|
|||||||
{
|
{
|
||||||
_logger.LogError(ex, "StorageException");
|
_logger.LogError(ex, "StorageException");
|
||||||
return CreditProgramOperationResponse.InternalServerError(
|
return CreditProgramOperationResponse.InternalServerError(
|
||||||
$"Error while working with data storage:{ex.InnerException!.Message}"
|
$"Error while working with data storage:{ex.InnerException?.Message}"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ public class CreditProgramsController(ICreditProgramAdapter adapter) : Controlle
|
|||||||
/// <param name="model">модель от пользователя</param>
|
/// <param name="model">модель от пользователя</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
[AllowAnonymous]
|
||||||
public IActionResult Register([FromBody] CreditProgramBindingModel model)
|
public IActionResult Register([FromBody] CreditProgramBindingModel model)
|
||||||
{
|
{
|
||||||
return _adapter.RegisterCreditProgram(model).GetResponse(Request, Response);
|
return _adapter.RegisterCreditProgram(model).GetResponse(Request, Response);
|
||||||
|
|||||||
@@ -81,6 +81,15 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
builder.Services.AddCors(options =>
|
||||||
|
{
|
||||||
|
options.AddPolicy("AllowFrontend", policy =>
|
||||||
|
{
|
||||||
|
policy.WithOrigins("http://localhost:26312")
|
||||||
|
.AllowAnyMethod()
|
||||||
|
.AllowAnyHeader();
|
||||||
|
});
|
||||||
|
});
|
||||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||||
builder.Services.AddOpenApi();
|
builder.Services.AddOpenApi();
|
||||||
builder.Services.AddSingleton<IConfigurationDatabase, ConfigurationDatabase>();
|
builder.Services.AddSingleton<IConfigurationDatabase, ConfigurationDatabase>();
|
||||||
@@ -135,7 +144,7 @@ if (app.Environment.IsProduction())
|
|||||||
dbContext.Database.Migrate();
|
dbContext.Database.Migrate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
app.UseCors("AllowFrontend");
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
VITE_API_URL=https://localhost:7204/
|
VITE_API_URL=https://localhost:7204
|
||||||
@@ -3,7 +3,11 @@ import { ConfigManager } from '@/lib/config';
|
|||||||
const API_URL = ConfigManager.loadUrl();
|
const API_URL = ConfigManager.loadUrl();
|
||||||
|
|
||||||
export async function getData<T>(path: string): Promise<T[]> {
|
export async function getData<T>(path: string): Promise<T[]> {
|
||||||
const res = await fetch(`${API_URL}/${path}`);
|
const res = await fetch(`${API_URL}/${path}`, {
|
||||||
|
headers: {
|
||||||
|
mode: 'no-cors',
|
||||||
|
},
|
||||||
|
});
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
throw new Error(`Не получается загрузить ${path}: ${res.statusText}`);
|
throw new Error(`Не получается загрузить ${path}: ${res.statusText}`);
|
||||||
}
|
}
|
||||||
@@ -16,6 +20,7 @@ export async function postData<T>(path: string, data: T) {
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
mode: 'no-cors',
|
||||||
},
|
},
|
||||||
body: JSON.stringify(data),
|
body: JSON.stringify(data),
|
||||||
});
|
});
|
||||||
@@ -29,6 +34,7 @@ export async function putData<T>(path: string, data: T) {
|
|||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
mode: 'no-cors',
|
||||||
},
|
},
|
||||||
body: JSON.stringify(data),
|
body: JSON.stringify(data),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -25,19 +25,19 @@ import type {
|
|||||||
} from '@/types/types';
|
} from '@/types/types';
|
||||||
|
|
||||||
const storekeepers: { id: string; name: string }[] = [
|
const storekeepers: { id: string; name: string }[] = [
|
||||||
{ id: 'store1', name: 'Кладовщик 1' },
|
{ id: crypto.randomUUID(), name: 'Кладовщик 1' },
|
||||||
{ id: 'store2', name: 'Кладовщик 2' },
|
{ id: crypto.randomUUID(), name: 'Кладовщик 2' },
|
||||||
];
|
];
|
||||||
|
|
||||||
const periods: { id: string; name: string }[] = [
|
const periods: { id: string; name: string }[] = [
|
||||||
{ id: 'period1', name: 'Период 1' },
|
{ id: crypto.randomUUID(), name: 'Период 1' },
|
||||||
{ id: 'period2', name: 'Период 2' },
|
{ id: crypto.randomUUID(), name: 'Период 2' },
|
||||||
];
|
];
|
||||||
|
|
||||||
const currencies: CurrencyBindingModel[] = [
|
const currencies: CurrencyBindingModel[] = [
|
||||||
{ id: 'curr1', name: 'Доллар США', abbreviation: 'USD', cost: 1 },
|
{ id: crypto.randomUUID(), name: 'Доллар США', abbreviation: 'USD', cost: 1 },
|
||||||
{ id: 'curr2', name: 'Евро', abbreviation: 'EUR', cost: 1.2 },
|
{ id: crypto.randomUUID(), name: 'Евро', abbreviation: 'EUR', cost: 1.2 },
|
||||||
{ id: 'curr3', name: 'Рубль', abbreviation: 'RUB', cost: 0.01 },
|
{ id: crypto.randomUUID(), name: 'Рубль', abbreviation: 'RUB', cost: 0.01 },
|
||||||
];
|
];
|
||||||
|
|
||||||
const formSchema = z.object({
|
const formSchema = z.object({
|
||||||
@@ -77,8 +77,12 @@ export const CreditProgramForm = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const handleSubmit = (data: FormValues) => {
|
const handleSubmit = (data: FormValues) => {
|
||||||
const payload: CreditProgramBindingModel = {
|
const dataWithId = {
|
||||||
...data,
|
...data,
|
||||||
|
id: crypto.randomUUID(),
|
||||||
|
};
|
||||||
|
const payload: CreditProgramBindingModel = {
|
||||||
|
...dataWithId,
|
||||||
currencyCreditPrograms: data.currencyCreditPrograms.map((currencyId) => ({
|
currencyCreditPrograms: data.currencyCreditPrograms.map((currencyId) => ({
|
||||||
currencyId,
|
currencyId,
|
||||||
})),
|
})),
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ export const CreditPrograms = (): React.JSX.Element => {
|
|||||||
|
|
||||||
const handleAdd = (data: CreditProgramBindingModel) => {
|
const handleAdd = (data: CreditProgramBindingModel) => {
|
||||||
console.log(data);
|
console.log(data);
|
||||||
|
createCreditProgram(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user