forked from AcaMate/AcaMate_API
[✨] Class 관련 로직 추가
1. 컨트롤러, 서비스(인터페이스), 레포지토리(인터페이스) 추가 2. scoped 등록 3. 클래스 관련 모델 등록 4. ClassInfo API 등록
This commit is contained in:
parent
6ef2a32d24
commit
82d8afcfb7
|
@ -140,10 +140,16 @@ builder.Services.AddScoped<IUserRepository, UserRepository>();
|
|||
builder.Services.AddScoped<IAppService, AppService>();
|
||||
builder.Services.AddScoped<IAppRepository, AppRepository>();
|
||||
|
||||
builder.Services.AddScoped<IClassService, ClassService>();
|
||||
builder.Services.AddScoped<IClassRepository, ClassRepository>();
|
||||
|
||||
// builder.Services.AddScoped<IPushService, PushService>();
|
||||
builder.Services.AddScoped<IPushRepository, PushRepository>();
|
||||
builder.Services.AddScoped<SessionManager>();
|
||||
builder.Services.AddScoped<DedicateWeb>();
|
||||
|
||||
|
||||
|
||||
// builder.Services.AddScoped<UserService>(); //
|
||||
// builder.Services.AddScoped<UserController>();
|
||||
|
||||
|
|
|
@ -13,8 +13,10 @@ public class DedicateWeb(
|
|||
JwtTokenService _jwtTokenService,
|
||||
IAppService _appService)
|
||||
{
|
||||
|
||||
public async Task<(string code, string result)> GetAuthToken()
|
||||
{
|
||||
|
||||
var summary = "GetAuthToken";
|
||||
try
|
||||
{
|
||||
|
|
|
@ -34,6 +34,11 @@ namespace Back.Program.Common.Data
|
|||
public DbSet<PushCabinet> PushCabinet { get; set; }
|
||||
|
||||
|
||||
//MARK: CLASS
|
||||
public DbSet<Class_Info> Class_Info { get; set; }
|
||||
public DbSet<Class_Attendance> Class_Attendance { get; set; }
|
||||
public DbSet<Class_Map> Class_Map { get; set; }
|
||||
|
||||
//MARK: CHATTING
|
||||
// public DbSet<>
|
||||
|
||||
|
@ -55,6 +60,11 @@ namespace Back.Program.Common.Data
|
|||
.HasKey(p => new { p.bid, p.pid });
|
||||
|
||||
// modelBuilder.Entity<LogPush>().HasNoKey();
|
||||
|
||||
modelBuilder.Entity<Class_Attendance>()
|
||||
.HasKey(ca => new { ca.cid, ca.uid, ca.attendace_date});
|
||||
modelBuilder.Entity<Class_Map>()
|
||||
.HasKey(ca => new { ca.cid, ca.uid});
|
||||
}
|
||||
}
|
||||
}
|
31
Program/Controllers/V1/ClassController.cs
Normal file
31
Program/Controllers/V1/ClassController.cs
Normal file
|
@ -0,0 +1,31 @@
|
|||
using Back.Program.Common.Model;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Back.Program.Services.V1.Interfaces;
|
||||
using Back.Program.Repositories.V1.Interfaces;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
|
||||
namespace Back.Program.Controllers.V1;
|
||||
[ApiController]
|
||||
[Route("/api/v1/in/class")]
|
||||
[ApiExplorerSettings(GroupName = "수업 관리")]
|
||||
public class ClassController(
|
||||
ILogger<ClassController> logger,
|
||||
// SessionManager sessionManager,
|
||||
// DedicateWeb dedicateWeb,
|
||||
IRepositoryService repositoryService,
|
||||
IClassService classService)
|
||||
: ControllerBase
|
||||
{
|
||||
// [HttpGet("info")]
|
||||
[HttpGet]
|
||||
[CustomOperation("수업 정보 조회", "수업 정보 조회", "수업관리")]
|
||||
public async Task<IActionResult> GetClassInfo(string cid)
|
||||
{
|
||||
if (string.IsNullOrEmpty(cid)) return BadRequest(APIResponse.InvalidInputError());
|
||||
if (!ModelState.IsValid) return BadRequest(APIResponse.InvalidInputError());
|
||||
string summary = repositoryService.ReadSummary(typeof(ClassController), "GetClassInfo");
|
||||
var result = await classService.GetClassInfo(summary, cid);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
}
|
68
Program/Models/Entities/Class.cs
Normal file
68
Program/Models/Entities/Class.cs
Normal file
|
@ -0,0 +1,68 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Back.Program.Models.Entities;
|
||||
|
||||
[Table("class_info")]
|
||||
public class Class_Info
|
||||
{
|
||||
[Required(ErrorMessage = "필수 항목 누락")]
|
||||
[MaxLength(10)]
|
||||
public required string id { get; set; } // AMC + 4숫자 + 3대문자
|
||||
|
||||
[Required(ErrorMessage = "필수 항목 누락")]
|
||||
[MaxLength(100)]
|
||||
public required string name { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "필수 항목 누락")]
|
||||
[MaxLength(70)]
|
||||
public required string uid { get; set; } // 담당 선생님 구분 코드
|
||||
|
||||
[Required(ErrorMessage = "필수 항목 누락")]
|
||||
public required DateTime start_date { get; set; }
|
||||
|
||||
public DateTime? end_date { get; set; }
|
||||
|
||||
[Required(ErrorMessage = "필수 항목 누락")]
|
||||
public required byte day { get; set; } // 수업 요일 비트 (월요일부터 가장 좌측 비트)
|
||||
|
||||
[Required(ErrorMessage = "필수 항목 누락")]
|
||||
[MaxLength(4)]
|
||||
public required string start_time { get; set; } // 수업 시작 시간
|
||||
|
||||
[Required(ErrorMessage = "필수 항목 누락")]
|
||||
[MaxLength(4)]
|
||||
public required string end_time { get; set; } // 수업 종료 시간
|
||||
}
|
||||
|
||||
[Table("class_map")]
|
||||
public class Class_Map
|
||||
{
|
||||
[Key]
|
||||
[Required(ErrorMessage = "필수 항목 누락")]
|
||||
[MaxLength(10)]
|
||||
public required string cid { get; set; } // 강의 구분 코드
|
||||
|
||||
[Required(ErrorMessage = "필수 항목 누락")]
|
||||
[MaxLength(70)]
|
||||
public required string uid { get; set; } // 학생(유저) 구분 코드
|
||||
}
|
||||
|
||||
[Table("class_attendance")]
|
||||
public class Class_Attendance
|
||||
{
|
||||
[Key]
|
||||
[Required(ErrorMessage = "필수 항목 누락")]
|
||||
[MaxLength(10)]
|
||||
public required string cid { get; set; } // 강의 구분 코드
|
||||
|
||||
[Required(ErrorMessage = "필수 항목 누락")]
|
||||
[MaxLength(70)]
|
||||
public required string uid { get; set; } // 학생(유저) 구분 코드
|
||||
|
||||
[Required(ErrorMessage = "필수 항목 누락")]
|
||||
public required DateTime attendace_date { get; set; } // 출석 일자
|
||||
|
||||
[Required(ErrorMessage = "필수 항목 누락")]
|
||||
public required byte attendance_state { get; set; } // 출석 상태 (0=출석, 1=결석, 2=지각, 3=조퇴, 4=기타)
|
||||
}
|
25
Program/Repositories/V1/ClassRepository.cs
Normal file
25
Program/Repositories/V1/ClassRepository.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using Back.Program.Common.Data;
|
||||
using Back.Program.Models.Entities;
|
||||
using Back.Program.Repositories.V1.Interfaces;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Back.Program.Repositories.V1;
|
||||
|
||||
public class ClassRepository(AppDbContext context): IClassRepository
|
||||
{
|
||||
public async Task<Class_Info?> FindClassInfo(string cid)
|
||||
{
|
||||
return await context.Class_Info.FirstOrDefaultAsync(c => c.id == cid);
|
||||
}
|
||||
|
||||
//return _context.Login.FirstOrDefaultAsync(l => l.sns_type == accType && l.sns_id == snsId);
|
||||
public async Task<Class_Attendance?> FindClassAttendance(string cid, string uid)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<Class_Map?> FindClassMap(string cid)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
19
Program/Repositories/V1/Interfaces/IClassRepository.cs
Normal file
19
Program/Repositories/V1/Interfaces/IClassRepository.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using Back.Program.Models.Entities;
|
||||
|
||||
namespace Back.Program.Repositories.V1.Interfaces;
|
||||
|
||||
public interface IClassRepository
|
||||
{
|
||||
// 클래스 정보
|
||||
// Task<Class_Info> GetClassInfo(string cid);
|
||||
// //학생이 클래스에 참여했는지 여부
|
||||
// Task<List<string>> GetIncludeStudents(string cid);
|
||||
// // 학생이 클래스에서 했던 모든 출석
|
||||
// Task<List<(DateTime date, int state)>> GetAttendanceOfClass(string cid, string uid);
|
||||
// // 학생이 특정 날짜에 했던 출석
|
||||
// Task<List<(string cid, int state)>> GetAttendanceByDate(string uid, DateTime date);
|
||||
|
||||
Task<Class_Info?> FindClassInfo(string cid);
|
||||
Task<Class_Attendance?> FindClassAttendance(string cid, string uid);
|
||||
Task<Class_Map?> FindClassMap(string cid);
|
||||
}
|
21
Program/Services/V1/ClassService.cs
Normal file
21
Program/Services/V1/ClassService.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using Back.Program.Common.Model;
|
||||
using Back.Program.Repositories.V1;
|
||||
using Back.Program.Repositories.V1.Interfaces;
|
||||
using Back.Program.Services.V1.Interfaces;
|
||||
|
||||
namespace Back.Program.Services.V1;
|
||||
|
||||
public class ClassService(IClassRepository classRepository): IClassService
|
||||
{
|
||||
public async Task<APIResponseStatus<object>> GetClassInfo(string summary, string cid)
|
||||
{
|
||||
var data = await classRepository.FindClassInfo(cid);
|
||||
return APIResponse.Send<object>("000", "수업 정보 조회 성공", new
|
||||
{
|
||||
summary = summary,
|
||||
data = data
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
}
|
8
Program/Services/V1/Interfaces/IClassService.cs
Normal file
8
Program/Services/V1/Interfaces/IClassService.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
using Back.Program.Common.Model;
|
||||
|
||||
namespace Back.Program.Services.V1.Interfaces;
|
||||
|
||||
public interface IClassService
|
||||
{
|
||||
Task<APIResponseStatus<object>> GetClassInfo(string summary, string cid);
|
||||
}
|
Loading…
Reference in New Issue
Block a user