forked from AcaMate/AcaMate_API
77 lines
2.1 KiB
C#
77 lines
2.1 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using System.Text.Json;
|
|
using AcaMate.Common.Data;
|
|
using AcaMate.Common.Models;
|
|
using AcaMate.V1.Models;
|
|
|
|
|
|
namespace AcaMate.V1.Controllers;
|
|
|
|
|
|
[ApiController]
|
|
[Route("/api/v1/in/user")]
|
|
[ApiExplorerSettings(GroupName = "사용자")]
|
|
public class UserController: ControllerBase
|
|
{
|
|
private readonly AppDbContext _dbContext;
|
|
public UserController(AppDbContext dbContext)
|
|
{
|
|
_dbContext = dbContext;
|
|
}
|
|
|
|
[HttpGet("login")]
|
|
[CustomOperation("SNS 로그인", "로그인 후 회원이 있는지 확인", "사용자")]
|
|
public IActionResult SNSLogin(string acctype,string sns_id)
|
|
{
|
|
|
|
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<string> bids = new List<string>();
|
|
|
|
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<dynamic>
|
|
{
|
|
status = new Status()
|
|
{
|
|
code = "000",
|
|
message = "정상"
|
|
},
|
|
data = new
|
|
{
|
|
uid = $"{uid}",
|
|
bid = bids
|
|
}
|
|
};
|
|
|
|
return Ok(response.JsonToString());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return StatusCode(500, DefaultResponse.UnknownError);
|
|
}
|
|
}
|
|
|
|
} |