diff --git a/Back.csproj b/Back.csproj index 5d91557..f7dec04 100644 --- a/Back.csproj +++ b/Back.csproj @@ -8,6 +8,7 @@ + diff --git a/Program.cs b/Program.cs index 088a8cb..d9d6837 100644 --- a/Program.cs +++ b/Program.cs @@ -80,7 +80,7 @@ builder.Services.AddCors(option => option.AddPolicy("CorsPolicy", builder => { builder - .AllowAnyOrigin() + // .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials() diff --git a/Program/Common/Data/AppDbContext.cs b/Program/Common/Data/AppDbContext.cs index d8385aa..f3832c9 100644 --- a/Program/Common/Data/AppDbContext.cs +++ b/Program/Common/Data/AppDbContext.cs @@ -10,5 +10,17 @@ public class AppDbContext: DbContext { } - public DbSet Versions { get; set; } + //MARK: Program + public DbSet Version { get; set; } + public DbSet Academy { get; set; } + + //MARK: USER + public DbSet Login { get; set; } + public DbSet UserAcademy { get; set; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity() + .HasKey(ua => new { ua.uid, ua.bid }); + } } \ No newline at end of file diff --git a/Program/V1/Controllers/AppController.cs b/Program/V1/Controllers/AppController.cs index ad6d8e7..f202268 100644 --- a/Program/V1/Controllers/AppController.cs +++ b/Program/V1/Controllers/AppController.cs @@ -30,7 +30,7 @@ public class AppController : ControllerBase try { - var version = _dbContext.Versions.FirstOrDefault(v => v.os_type == (type == "I" ? "VO01" : "VO02")); + var version = _dbContext.Version.FirstOrDefault(v => v.os_type == (type == "I" ? "VO01" : "VO02")); if (version == null) { @@ -61,6 +61,7 @@ public class AppController : ControllerBase } catch (Exception ex) { + Console.WriteLine($"{ex.Message}\n{ex.StackTrace}"); return StatusCode(500, DefaultResponse.UnknownError); } } diff --git a/Program/V1/Controllers/UserController.cs b/Program/V1/Controllers/UserController.cs index cc44569..a0af8ad 100644 --- a/Program/V1/Controllers/UserController.cs +++ b/Program/V1/Controllers/UserController.cs @@ -1,9 +1,9 @@ -using System.Text; -using System.Text.Json; using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Authentication; +using System.Text.Json; +using AcaMate.Common.Data; +using AcaMate.Common.Models; +using AcaMate.V1.Models; -using AcaMate.V1.Services; namespace AcaMate.V1.Controllers; @@ -13,34 +13,65 @@ namespace AcaMate.V1.Controllers; [ApiExplorerSettings(GroupName = "사용자")] public class UserController: ControllerBase { - // private readonly UserController _userController; - - // private readonly UserService _userService; - // - // public UserController(UserService userService) - // { - // _userService = userService; - // } - - [HttpGet("snsLogin")] - public IActionResult SNSLogin() + private readonly AppDbContext _dbContext; + public UserController(AppDbContext dbContext) { - var response = new - { - status = new - { - code = "000", - message = "정상" - }, - data = new - { - uid = "AC0000" - } - }; + _dbContext = dbContext; + } - string jsonString = JsonSerializer.Serialize(response); + [HttpGet("login")] + [CustomOperation("SNS 로그인", "로그인 후 회원이 있는지 확인", "사용자")] + public IActionResult SNSLogin(string acctype,string sns_id) + { - return Ok(jsonString); + if (string.IsNullOrEmpty(acctype) && string.IsNullOrEmpty(sns_id)) + { + return BadRequest(DefaultResponse.InvalidInputError); + } + + try + { + var login = _dbContext.Login.FirstOrDefault(l => l.sns_type == acctype && l.sns_id == sns_id); + + string uid = ""; + List bids = new List(); + + if (login != null) + { + uid = login.uid; + var userAcademy = _dbContext.UserAcademy.Where(u => u.uid == uid).ToList(); + + foreach(User_Academy userData in userAcademy) + { + Console.WriteLine($"uid: {userData.uid} || bid: {userData.bid}"); + bids.Add(userData.bid); + } + } + else + { + return StatusCode(002, DefaultResponse.NotFoundError); + } + + var response = new APIResponseStatus + { + status = new Status() + { + code = "000", + message = "정상" + }, + data = new + { + uid = $"{uid}", + bid = bids + } + }; + + return Ok(response.JsonToString()); + } + catch (Exception ex) + { + return StatusCode(500, DefaultResponse.UnknownError); + } } } \ No newline at end of file diff --git a/Program/V1/Models/Academy.cs b/Program/V1/Models/Academy.cs new file mode 100644 index 0000000..947c2c7 --- /dev/null +++ b/Program/V1/Models/Academy.cs @@ -0,0 +1,18 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace AcaMate.V1.Models; + +[Table("academy")] +public class Academy +{ + [Key] + public string bid { get; set; } + public string business_name { get; set; } + public string business_ownder { get; set; } + public string business_number { get; set; } + public DateTime business_date { get; set; } + public string business_address { get; set; } + public string business_contact { get; set; } + public string uid { get; set; } +} \ No newline at end of file diff --git a/Program/V1/Models/Login.cs b/Program/V1/Models/Login.cs new file mode 100644 index 0000000..eed116d --- /dev/null +++ b/Program/V1/Models/Login.cs @@ -0,0 +1,30 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace AcaMate.V1.Models; + +[Table("login")] +public class Login +{ + [Key] + [MaxLength(100)] + public string sns_id {get; set;} + [MaxLength(70)] + public string uid {get; set;} + [MaxLength(4)] + public string sns_type {get; set;} + [MaxLength(255)] + public string sns_token {get; set;} + [MaxLength(100)] + public string sns_email {get; set;} +} + +[Table("user_academy")] +public class User_Academy +{ + [Key] + public string uid { get; set; } + public string bid { get; set; } + public DateTime register_date { get; set; } + public bool status { get; set; } +} \ No newline at end of file diff --git a/Program/V1/Repositories/UserRepository.cs b/Program/V1/Repositories/UserRepository.cs new file mode 100644 index 0000000..b47a88c --- /dev/null +++ b/Program/V1/Repositories/UserRepository.cs @@ -0,0 +1,28 @@ +using Microsoft.AspNetCore.Mvc; + +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using AcaMate.Common.Data; +using AcaMate.Common.Models; +using AcaMate.V1.Models; + +namespace AcaMate.V1.Repositories; + +public class UserRepository +{ + + private readonly AppDbContext _context; + + + public UserRepository(AppDbContext context) { + _context = context; + + } + + /* + public async Task> GetUserAcademyInfoBySnsIdAsync(string snsId) + { + + }*/ +} \ No newline at end of file diff --git a/Program/V1/Services/PushService.cs b/Program/V1/Services/PushService.cs index b227921..0e2fab0 100644 --- a/Program/V1/Services/PushService.cs +++ b/Program/V1/Services/PushService.cs @@ -14,6 +14,7 @@ public class ApnsPushService private readonly string _p12Path; private readonly string _p12PWPath; private readonly string _apnsTopic; + public ApnsPushService(string uri,string p12Path, string p12PWPath, string apnsTopic) { @@ -32,7 +33,7 @@ public class ApnsPushService Console.WriteLine($"File not found: {_p12PWPath}"); return new APIResult { - Success = false, + Success = false , Code = "003", Message = "서버 오류 : p12 PW 파일 확인 필요" }; @@ -68,7 +69,6 @@ public class ApnsPushService // 필수 헤더 추가 request.Headers.Add("apns-topic", _apnsTopic); request.Headers.Add("apns-push-type", "alert"); - Console.WriteLine($"Send -> Payload: {jsonPayload}"); diff --git a/Program/V1/Services/UserService.cs b/Program/V1/Services/UserService.cs index b406693..5d078bb 100644 --- a/Program/V1/Services/UserService.cs +++ b/Program/V1/Services/UserService.cs @@ -3,4 +3,5 @@ namespace AcaMate.V1.Services; public class UserService { // priva + } \ No newline at end of file diff --git a/README.md b/README.md index 55ea7fa..f977ff6 100644 --- a/README.md +++ b/README.md @@ -13,3 +13,4 @@ | 2 | Microsoft.EntityFrameworkCore | 8.0.10 | 데이터베이스 작업을 간편하게 수행하기 위해 사용 | | 3 | Pomelo.EntityFrameworkCore.MySql | 8.0.2 | MariaDB 연결 | | 4 |Microsoft.AspNetCore.Authentication.JwtBearer| 8.0.10 | | + | 5 |Dapper|2.1.35|SQL 직접 작성|