Initial import from local backup (Documents-Playground/pakerpale)
This commit is contained in:
107
Controllers/UserController.cs
Normal file
107
Controllers/UserController.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
using Auth.api.Models;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using Auth.api.Internal;
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
using Auth.api.Services;
|
||||
|
||||
using Auth.api.Repositories;
|
||||
|
||||
|
||||
|
||||
namespace Auth.api.Controllers
|
||||
{
|
||||
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class UserController : ControllerBase
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private UserContext _context;
|
||||
private PostContext _postContext;
|
||||
|
||||
private IUserService _userService;
|
||||
|
||||
public UserController(ILogger<UserController> logger, UserContext context, IUserService userService, PostContext postContext)
|
||||
{
|
||||
_logger = logger;
|
||||
_context = context;
|
||||
_userService = userService;
|
||||
_postContext = postContext;
|
||||
|
||||
if ( _postContext.Posts.Count() == 0 )
|
||||
{
|
||||
// 테스트용
|
||||
// Create a new Student if collection is empty,
|
||||
// which means you can't delete all Student.
|
||||
// _postContext.Posts.Add(new Auth.api.Entities.Post { postID=1, postTitle = "ORM", postImage="Entity" });
|
||||
// _postContext.SaveChanges();
|
||||
}
|
||||
}
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost("authenticate")]
|
||||
public IActionResult Authenticate([FromBody]Auth.api.Entities.User userParam)
|
||||
{
|
||||
var user = _userService.Authenticate(userParam.Username, userParam.Password);
|
||||
|
||||
if (user == null)
|
||||
return BadRequest(new { message = "Username or password is incorrect" });
|
||||
|
||||
return Ok(user);
|
||||
}
|
||||
|
||||
// GET api/values/5
|
||||
[HttpGet("posts/{id}")]
|
||||
public ActionResult<Auth.api.Entities.Post> Get(string id)
|
||||
{
|
||||
return Ok(_postContext.Posts.Find(20027));
|
||||
}
|
||||
|
||||
// GET api/values
|
||||
[HttpGet]
|
||||
public ActionResult<List<User>> Get()
|
||||
{
|
||||
return Ok(_context.GetAllUsers());
|
||||
}
|
||||
|
||||
// GET api/values/5
|
||||
[HttpGet("{id}")]
|
||||
public ActionResult<string> Get(int id)
|
||||
{
|
||||
return Ok(_context.GetAllUsers());
|
||||
}
|
||||
|
||||
// POST api/values
|
||||
[HttpPost]
|
||||
public void Post([FromBody] string value)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// PUT api/values/5
|
||||
[HttpPut("{id}")]
|
||||
public void Put(int id, [FromBody] string value)
|
||||
{
|
||||
}
|
||||
|
||||
// DELETE api/values/5
|
||||
[HttpDelete("{id}")]
|
||||
public void Delete(int id)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user