fix: добавил создание кредитных программ, починил по тупому cors и id на клиенте решил генерить

This commit is contained in:
2025-05-18 02:52:11 +04:00
parent 164def1e18
commit de879be266
7 changed files with 38 additions and 17 deletions

View File

@@ -54,7 +54,7 @@ public class CreditProgramAdapter : ICreditProgramAdapter
{
_logger.LogError(ex, "StorageException");
return CreditProgramOperationResponse.InternalServerError(
$"Error while working with data storage:{ex.InnerException!.Message}"
$"Error while working with data storage:{ex.InnerException?.Message}"
);
}
catch (Exception ex)
@@ -86,7 +86,7 @@ public class CreditProgramAdapter : ICreditProgramAdapter
{
_logger.LogError(ex, "StorageException");
return CreditProgramOperationResponse.InternalServerError(
$"Error while working with data storage: {ex.InnerException!.Message}"
$"Error while working with data storage: {ex.InnerException?.Message}"
);
}
catch (Exception ex)
@@ -122,7 +122,7 @@ public class CreditProgramAdapter : ICreditProgramAdapter
{
_logger.LogError(ex, "StorageException");
return CreditProgramOperationResponse.BadRequest(
$"Error while working with data storage: {ex.InnerException!.Message}"
$"Error while working with data storage: {ex.InnerException?.Message}"
);
}
catch (Exception ex)
@@ -164,7 +164,7 @@ public class CreditProgramAdapter : ICreditProgramAdapter
{
_logger.LogError(ex, "StorageException");
return CreditProgramOperationResponse.BadRequest(
$"Error while working with data storage: {ex.InnerException!.Message}"
$"Error while working with data storage: {ex.InnerException?.Message}"
);
}
catch (Exception ex)
@@ -195,7 +195,7 @@ public class CreditProgramAdapter : ICreditProgramAdapter
{
_logger.LogError(ex, "StorageException");
return CreditProgramOperationResponse.InternalServerError(
$"Error while working with data storage:{ex.InnerException!.Message}"
$"Error while working with data storage:{ex.InnerException?.Message}"
);
}
catch (Exception ex)
@@ -226,7 +226,7 @@ public class CreditProgramAdapter : ICreditProgramAdapter
{
_logger.LogError(ex, "StorageException");
return CreditProgramOperationResponse.InternalServerError(
$"Error while working with data storage:{ex.InnerException!.Message}"
$"Error while working with data storage:{ex.InnerException?.Message}"
);
}
catch (Exception ex)

View File

@@ -63,6 +63,7 @@ public class CreditProgramsController(ICreditProgramAdapter adapter) : Controlle
/// <param name="model">модель от пользователя</param>
/// <returns></returns>
[HttpPost]
[AllowAnonymous]
public IActionResult Register([FromBody] CreditProgramBindingModel model)
{
return _adapter.RegisterCreditProgram(model).GetResponse(Request, Response);

View File

@@ -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
builder.Services.AddOpenApi();
builder.Services.AddSingleton<IConfigurationDatabase, ConfigurationDatabase>();
@@ -135,7 +144,7 @@ if (app.Environment.IsProduction())
dbContext.Database.Migrate();
}
}
app.UseCors("AllowFrontend");
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();

View File

@@ -1 +1 @@
VITE_API_URL=https://localhost:7204/
VITE_API_URL=https://localhost:7204

View File

@@ -3,7 +3,11 @@ import { ConfigManager } from '@/lib/config';
const API_URL = ConfigManager.loadUrl();
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) {
throw new Error(`Не получается загрузить ${path}: ${res.statusText}`);
}
@@ -16,6 +20,7 @@ export async function postData<T>(path: string, data: T) {
method: 'POST',
headers: {
'Content-Type': 'application/json',
mode: 'no-cors',
},
body: JSON.stringify(data),
});
@@ -29,6 +34,7 @@ export async function putData<T>(path: string, data: T) {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
mode: 'no-cors',
},
body: JSON.stringify(data),
});

View File

@@ -25,19 +25,19 @@ import type {
} from '@/types/types';
const storekeepers: { id: string; name: string }[] = [
{ id: 'store1', name: 'Кладовщик 1' },
{ id: 'store2', name: 'Кладовщик 2' },
{ id: crypto.randomUUID(), name: 'Кладовщик 1' },
{ id: crypto.randomUUID(), name: 'Кладовщик 2' },
];
const periods: { id: string; name: string }[] = [
{ id: 'period1', name: 'Период 1' },
{ id: 'period2', name: 'Период 2' },
{ id: crypto.randomUUID(), name: 'Период 1' },
{ id: crypto.randomUUID(), name: 'Период 2' },
];
const currencies: CurrencyBindingModel[] = [
{ id: 'curr1', name: 'Доллар США', abbreviation: 'USD', cost: 1 },
{ id: 'curr2', name: 'Евро', abbreviation: 'EUR', cost: 1.2 },
{ id: 'curr3', name: 'Рубль', abbreviation: 'RUB', cost: 0.01 },
{ id: crypto.randomUUID(), name: 'Доллар США', abbreviation: 'USD', cost: 1 },
{ id: crypto.randomUUID(), name: 'Евро', abbreviation: 'EUR', cost: 1.2 },
{ id: crypto.randomUUID(), name: 'Рубль', abbreviation: 'RUB', cost: 0.01 },
];
const formSchema = z.object({
@@ -77,8 +77,12 @@ export const CreditProgramForm = ({
});
const handleSubmit = (data: FormValues) => {
const payload: CreditProgramBindingModel = {
const dataWithId = {
...data,
id: crypto.randomUUID(),
};
const payload: CreditProgramBindingModel = {
...dataWithId,
currencyCreditPrograms: data.currencyCreditPrograms.map((currencyId) => ({
currencyId,
})),

View File

@@ -20,6 +20,7 @@ export const CreditPrograms = (): React.JSX.Element => {
const handleAdd = (data: CreditProgramBindingModel) => {
console.log(data);
createCreditProgram(data);
};
return (