-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from tacobell1896/feat/add-game
Add game entity
- Loading branch information
Showing
12 changed files
with
407 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.EntityFrameworkCore; | ||
using SavePointAPI.Models; | ||
|
||
namespace SavePointAPI.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class SavePointGamesController : ControllerBase | ||
{ | ||
private readonly SavePointContext _context; | ||
|
||
public SavePointGamesController(SavePointContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
// GET: api/SavePointGames | ||
[HttpGet] | ||
public async Task<ActionResult<IEnumerable<SavePointGame>>> GetSavePointGames() | ||
{ | ||
// TODO: Return the list of notes associated with the game | ||
return await _context.SavePointGames.ToListAsync(); | ||
} | ||
|
||
// GET: api/SavePointGames/5 | ||
[HttpGet("{id}")] | ||
public async Task<ActionResult<SavePointGameDTO>> GetSavePointGame(int id) | ||
{ | ||
var savePointGame = await _context.SavePointGames.FindAsync(id); | ||
|
||
if (savePointGame == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
return SavePointGameToDTO(savePointGame); | ||
} | ||
|
||
// PUT: api/SavePointGames/5 | ||
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 | ||
[HttpPut("{id}")] | ||
public async Task<IActionResult> PutSavePointGame(int id, SavePointGameDTO savePointGameDTO) | ||
{ | ||
if (id != savePointGameDTO.SavePointGameId) | ||
{ | ||
return BadRequest(); | ||
} | ||
|
||
_context.Entry(savePointGameDTO).State = EntityState.Modified; | ||
|
||
try | ||
{ | ||
await _context.SaveChangesAsync(); | ||
} | ||
catch (DbUpdateConcurrencyException) | ||
{ | ||
if (!SavePointGameExists(id)) | ||
{ | ||
return NotFound(); | ||
} | ||
else | ||
{ | ||
throw; | ||
} | ||
} | ||
|
||
return NoContent(); | ||
} | ||
|
||
// POST: api/SavePointGames | ||
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754 | ||
[HttpPost] | ||
public async Task<ActionResult<SavePointGame>> PostSavePointGame(SavePointGameDTO savePointGame) | ||
{ | ||
var Game = new SavePointGame | ||
{ | ||
GameName = savePointGame.GameName, | ||
GameConsole = savePointGame.GameConsole, | ||
GameGenre = savePointGame.GameGenre, | ||
GameDeveloper = savePointGame.GameDeveloper, | ||
GamePublisher = savePointGame.GamePublisher, | ||
GameReleaseDate = savePointGame.GameReleaseDate, | ||
GameDescription = savePointGame.GameDescription, | ||
}; | ||
_context.SavePointGames.Add(Game); | ||
await _context.SaveChangesAsync(); | ||
|
||
return CreatedAtAction(nameof(PostSavePointGame), new { id = savePointGame.SavePointGameId }, savePointGame); | ||
} | ||
|
||
// DELETE: api/SavePointGames/5 | ||
[HttpDelete("{id}")] | ||
public async Task<IActionResult> DeleteSavePointGame(int id) | ||
{ | ||
var savePointGame = await _context.SavePointGames.FindAsync(id); | ||
if (savePointGame == null) | ||
{ | ||
return NotFound(); | ||
} | ||
|
||
_context.SavePointGames.Remove(savePointGame); | ||
await _context.SaveChangesAsync(); | ||
|
||
return NoContent(); | ||
} | ||
|
||
private bool SavePointGameExists(int id) | ||
{ | ||
return _context.SavePointGames.Any(e => e.SavePointGameId == id); | ||
} | ||
|
||
private SavePointGameDTO SavePointGameToDTO(SavePointGame savePointGame) => | ||
new SavePointGameDTO | ||
{ | ||
SavePointGameId = savePointGame.SavePointGameId, | ||
GameName = savePointGame.GameName, | ||
GameConsole = savePointGame.GameConsole, | ||
GameGenre = savePointGame.GameGenre, | ||
GameDeveloper = savePointGame.GameDeveloper, | ||
GamePublisher = savePointGame.GamePublisher, | ||
GameReleaseDate = savePointGame.GameReleaseDate, | ||
GameDescription = savePointGame.GameDescription, | ||
GameRating = savePointGame.GameRating, | ||
GameImage = savePointGame.GameImage | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace SavePointAPI.Models | ||
{ | ||
public class SavePointGame | ||
{ | ||
public int SavePointGameId { get; set; } | ||
public string? GameName { get; set; } | ||
public string? GameConsole { get; set; } | ||
public string? GameGenre { get; set; } | ||
public string? GameDeveloper { get; set; } | ||
public string? GamePublisher { get; set; } | ||
public string? GameReleaseDate { get; set; } | ||
public string? GameDescription { get; set; } | ||
public string? GameRating { get; set; } | ||
public string? GameImage { get; set; } | ||
public ICollection<SavePointNote>? SavePointNotes { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
namespace SavePointAPI.Models | ||
{ | ||
public class SavePointGameDTO | ||
{ | ||
public int SavePointGameId { get; set; } | ||
public string? GameName { get; set; } | ||
public string? GameConsole { get; set; } | ||
public string? GameGenre { get; set; } | ||
public string? GameDeveloper { get; set; } | ||
public string? GamePublisher { get; set; } | ||
public string? GameReleaseDate { get; set; } | ||
public string? GameDescription { get; set; } | ||
public string? GameRating { get; set; } | ||
public string? GameImage { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
{ | ||
"ConnectionStrings": { | ||
"DefaultConnection": "Host=localhost;Port=5432;Database=SavePoint;Username=postgres;Password=39^K5uQy4iPZStxGSg" | ||
}, | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.