Genesis Game Server Project Setup
This commit is contained in:
35
GameServer/Controllers/CharacterController.cs
Normal file
35
GameServer/Controllers/CharacterController.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using GameServer.Data; // DbContext가 있는 폴더
|
||||
using GameServer.Models; // Model이 있는 폴더
|
||||
|
||||
namespace GameServer.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("myGame")] // 접속 주소: /myGame
|
||||
public class CharacterController : ControllerBase
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
// DB 연결 도구(Context)를 가져옵니다.
|
||||
public CharacterController(AppDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// 플레이어블 캐릭터 목록
|
||||
[HttpGet("playableCharacters")]
|
||||
public async Task<IActionResult> GetPlayableCharacters()
|
||||
{
|
||||
List<CharacterModel> list = await _context.Characters
|
||||
.Where(x => x.CharacterType == "PLAYABLE")
|
||||
.ToListAsync();
|
||||
|
||||
return Ok(new ApiResponse<List<CharacterModel>>
|
||||
{
|
||||
Data = list,
|
||||
Count = list.Count
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
62
GameServer/Controllers/UserController.cs
Normal file
62
GameServer/Controllers/UserController.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using GameServer.Data; // DbContext가 있는 폴더
|
||||
using GameServer.Models; // Model이 있는 폴더
|
||||
|
||||
namespace GameServer.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("myGame")] // 접속 주소: /myGame
|
||||
public class UserController : ControllerBase
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
// DB 연결 도구(Context)를 가져옵니다.
|
||||
public UserController(AppDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// 모든 유저들의 캐릭터 목록
|
||||
[HttpGet("userCharacters")]
|
||||
public async Task<IActionResult> GetAllUserCharacters()
|
||||
{
|
||||
List<UserCharacterModel> list = await _context.UserCharacters.ToListAsync();
|
||||
|
||||
return Ok(new ApiResponse<List<UserCharacterModel>>
|
||||
{
|
||||
Data = list,
|
||||
Count = list.Count
|
||||
});
|
||||
}
|
||||
|
||||
// 특정 유저의 캐릭터 목록
|
||||
[HttpGet("userCharacters/{user_no}")]
|
||||
public async Task<IActionResult> GetUserCharacters(int user_no)
|
||||
{
|
||||
List<UserCharacterModel> list = await _context.UserCharacters
|
||||
.Where(x => x.UserNo == user_no)
|
||||
.ToListAsync();
|
||||
|
||||
return Ok(new ApiResponse<List<UserCharacterModel>>
|
||||
{
|
||||
Data = list,
|
||||
Count = list.Count
|
||||
});
|
||||
}
|
||||
|
||||
// 새 캐릭터 저장하기
|
||||
[HttpPost("create")]
|
||||
public async Task<IActionResult> CreatePlayer([FromBody] UserCharacterModel newUserCharacter)
|
||||
{
|
||||
_context.UserCharacters.Add(newUserCharacter);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Ok(new ApiResponse<UserCharacterModel>
|
||||
{
|
||||
Data = newUserCharacter,
|
||||
Message = "캐릭터 생성 완료!"
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
28
GameServer/Controllers/WeatherForecastController.cs
Normal file
28
GameServer/Controllers/WeatherForecastController.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace GameServer.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("myGame")]
|
||||
public class WeatherForecastController : ControllerBase
|
||||
{
|
||||
// 서버 메모리에 임시로 저장할 데이터 (나중에 DB로 바꿀 부분)
|
||||
private static int _tempData = 100;
|
||||
|
||||
// 데이터 로드
|
||||
[HttpGet("data")]
|
||||
public IActionResult GetCores()
|
||||
{
|
||||
// 유니티에게 JSON 형태로 데이터를 보냄
|
||||
return Ok(new { data = _tempData, message = "데이터 로드 성공!" });
|
||||
}
|
||||
|
||||
// 데이터 수정
|
||||
[HttpPost("add-data")]
|
||||
public IActionResult AddCore([FromBody] int value)
|
||||
{
|
||||
_tempData = value;
|
||||
return Ok(new { data = _tempData, message = $"{value}로 데이터 수정 완료!" });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user