重构项目结构,移除Assignment相关功能,优化Submission模块
Some checks failed
TechAct / explore-gitea-actions (push) Failing after 12s
Some checks failed
TechAct / explore-gitea-actions (push) Failing after 12s
This commit is contained in:
@@ -9,10 +9,11 @@ using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System.Text;
|
||||
using TechHelper.Features;
|
||||
using TechHelper.Services;
|
||||
using TechHelper.Server.Services;
|
||||
using TechHelper.Server.Repositories;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using TechHelper.Services.Beta;
|
||||
using TechHelper.Server.Context;
|
||||
using TechHelper.Server.Repository;
|
||||
|
||||
/// <summary>
|
||||
/// TechHelper 服务器应用程序的主入口点
|
||||
@@ -24,22 +25,28 @@ builder.Services.AddControllers();
|
||||
|
||||
// 2. 数据库服务 (DbContext)
|
||||
builder.Services.AddDbContext<ApplicationContext>(options =>
|
||||
options.UseMySql(
|
||||
options
|
||||
.UseLazyLoadingProxies()
|
||||
.UseMySql(
|
||||
builder.Configuration.GetConnectionString("XSDB"),
|
||||
ServerVersion.AutoDetect(builder.Configuration.GetConnectionString("XSDB"))
|
||||
)
|
||||
).AddUnitOfWork<ApplicationContext>()
|
||||
.AddCustomRepository<Assignment, AssignmentRepository>()
|
||||
.AddCustomRepository<AssignmentAttachment, AssignmentAttachmentRepository>()
|
||||
.AddCustomRepository<AssignmentQuestion, AssignmentQuestionRepository>()
|
||||
.AddCustomRepository<Exam, AssignmentRepository>()
|
||||
.AddCustomRepository<ExamAttachment, AssignmentAttachmentRepository>()
|
||||
.AddCustomRepository<ExamQuestion, ExamQuestionRepository>()
|
||||
.AddCustomRepository<Class, ClassRepository>()
|
||||
.AddCustomRepository<ClassStudent, ClassStudentRepository>()
|
||||
.AddCustomRepository<ClassTeacher, ClassTeacherRepository>()
|
||||
.AddCustomRepository<ClassUser, ClassUserRepository>()
|
||||
.AddCustomRepository<Question, QuestionRepository>()
|
||||
.AddCustomRepository<QuestionContext, QuestionContextRepository>()
|
||||
.AddCustomRepository<Submission, SubmissionRepository>()
|
||||
.AddCustomRepository<Subject, SubjectRepository>()
|
||||
.AddCustomRepository<ExamType, ExamTypeRepository>()
|
||||
.AddCustomRepository<QuestionType, QuestionTypeRepository>()
|
||||
.AddCustomRepository<User, UserRepository>()
|
||||
.AddCustomRepository<Global, GlobalRepository>();
|
||||
.AddCustomRepository<KeyPoint, KeyPointRepository>()
|
||||
.AddCustomRepository<Lesson, LessonRepository>()
|
||||
.AddCustomRepository<Textbook, TextbookRepository>();
|
||||
|
||||
|
||||
builder.Services.AddAutoMapper(typeof(AutoMapperProFile).Assembly);
|
||||
@@ -55,10 +62,11 @@ builder.Services.AddIdentity<User, IdentityRole<Guid>>(opt =>
|
||||
{
|
||||
opt.User.AllowedUserNameCharacters = "";
|
||||
opt.Lockout.AllowedForNewUsers = true;
|
||||
opt.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(2);
|
||||
opt.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(5);
|
||||
opt.Lockout.MaxFailedAccessAttempts = 3;
|
||||
})
|
||||
.AddEntityFrameworkStores<ApplicationContext>()
|
||||
.AddRoles<IdentityRole<Guid>>()
|
||||
.AddEntityFrameworkStores<ApplicationContext>()
|
||||
.AddDefaultTokenProviders();
|
||||
builder.Services.Configure<DataProtectionTokenProviderOptions>(Options =>
|
||||
{
|
||||
@@ -81,7 +89,7 @@ builder.Services.AddAuthentication(options =>
|
||||
ValidateAudience = true, // 验证受众
|
||||
ValidateLifetime = true, // 验证令牌有效期
|
||||
ValidateIssuerSigningKey = true, // 验证签名密钥
|
||||
|
||||
|
||||
ValidIssuer = jwtSettings["validIssuer"], // 合法的签发人
|
||||
ValidAudience = jwtSettings["validAudience"], // 合法的受众
|
||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtSettings["securityKey"])) // 签名密钥
|
||||
@@ -90,15 +98,23 @@ builder.Services.AddAuthentication(options =>
|
||||
|
||||
builder.Services.AddScoped<IAuthenticationService, AuthenticationService>();
|
||||
builder.Services.AddScoped<IEmailSender, QEmailSender>();
|
||||
builder.Services.AddTransient<IUserRegistrationService, UserRegistrationService>();
|
||||
builder.Services.AddScoped<IClassService, ClassService>();
|
||||
builder.Services.AddScoped<IExamService, ExamService>();
|
||||
builder.Services.AddScoped<IUserSerivces, UserServices>();
|
||||
builder.Services.AddScoped<ISubmissionServices, SubmissionServices>();
|
||||
builder.Services.AddScoped<IStudentSubmissionService, StudentSubmissionService>();
|
||||
builder.Services.AddScoped<IStudentSubmissionDetailService, StudentSubmissionDetailService>();
|
||||
builder.Services.AddScoped<IExamRepository, ExamRepository>();
|
||||
builder.Services.AddScoped<INoteService, NoteService>();
|
||||
builder.Services.AddScoped<ISubmissionService, SubmissionService>();
|
||||
builder.Services.AddScoped<ISubmissionDetailService, SubmissionDetailService>();
|
||||
builder.Services.AddScoped<IExamRepository, ExamRepository>();
|
||||
builder.Services.AddScoped<ISchoolService, SchoolService>();
|
||||
builder.Services.AddScoped<IGradeService, GradeService>();
|
||||
builder.Services.AddScoped<ISubjectService, SubjectService>();
|
||||
builder.Services.AddScoped<IExamTypeService, ExamTypeService>();
|
||||
builder.Services.AddScoped<IQuestionTypeService, QuestionTypeService>();
|
||||
builder.Services.AddScoped<IQuestionService, QuestionService>();
|
||||
builder.Services.AddScoped<IExamQuestionService, ExamQuestionService>();
|
||||
builder.Services.AddScoped<IKeyPointService, KeyPointService>();
|
||||
builder.Services.AddScoped<ILessonService, LessonService>();
|
||||
builder.Services.AddScoped<ITextbookService, TextbookService>();
|
||||
|
||||
|
||||
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
@@ -108,11 +124,11 @@ builder.Services.AddSwaggerGen(c =>
|
||||
|
||||
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
|
||||
{
|
||||
Name = "Authorization",
|
||||
Type = SecuritySchemeType.Http,
|
||||
Scheme = "bearer",
|
||||
BearerFormat = "JWT",
|
||||
In = ParameterLocation.Header,
|
||||
Name = "Authorization",
|
||||
Type = SecuritySchemeType.Http,
|
||||
Scheme = "bearer",
|
||||
BearerFormat = "JWT",
|
||||
In = ParameterLocation.Header,
|
||||
Description = "JWT Authorization header using the Bearer scheme. \r\n\r\n Enter 'Bearer' [space] and then your token in the text input below.\r\n\r\nExample: \"Bearer 12345abcdef\"",
|
||||
});
|
||||
|
||||
@@ -124,27 +140,28 @@ builder.Services.AddSwaggerGen(c =>
|
||||
Reference = new OpenApiReference
|
||||
{
|
||||
Type = ReferenceType.SecurityScheme,
|
||||
Id = "Bearer"
|
||||
}
|
||||
Id = "Bearer"
|
||||
}
|
||||
},
|
||||
new string[] {}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("AllowSpecificOrigin",
|
||||
builder => builder
|
||||
.WithOrigins("https://localhost:7047", "http://localhost:7047", "https://localhost:5001", "http://localhost:5001")
|
||||
.WithOrigins("https://localhost:7047", "http://localhost:7047", "https://localhost:5001", "http://localhost:5001")
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod()
|
||||
.AllowCredentials());
|
||||
.AllowCredentials());
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (/*app.Environment.IsDevelopment()*/true)
|
||||
{
|
||||
@@ -157,6 +174,21 @@ app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var services = scope.ServiceProvider;
|
||||
try
|
||||
{
|
||||
var roleManager = services.GetRequiredService<RoleManager<IdentityRole<Guid>>>();
|
||||
await DbInitializer.SeedRoles(roleManager);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
var logger = services.GetRequiredService<ILogger<Program>>();
|
||||
logger.LogError(ex, "An error occurred while seeding the database.");
|
||||
}
|
||||
}
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
|
||||
Reference in New Issue
Block a user