Skip to content

Commit

Permalink
Final update. Disappointed.com
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgrant committed Oct 18, 2018
1 parent 0c2e5dc commit 4a36e5e
Show file tree
Hide file tree
Showing 45 changed files with 305 additions and 199 deletions.
Binary file modified WebApi/.vs/WebApi/DesignTimeBuild/.dtbcache
Binary file not shown.
Binary file modified WebApi/.vs/WebApi/v15/.suo
Binary file not shown.
Binary file modified WebApi/.vs/WebApi/v15/Server/sqlite3/storage.ide
Binary file not shown.
Binary file modified WebApi/.vs/WebApi/v15/Server/sqlite3/storage.ide-shm
Binary file not shown.
Binary file modified WebApi/.vs/WebApi/v15/Server/sqlite3/storage.ide-wal
Binary file not shown.
8 changes: 4 additions & 4 deletions WebApi/WebApi.Tests/ExerciseTests.cs
Expand Up @@ -74,7 +74,7 @@ public void post_correct_easy_question()
newExercise.leftNumber = 2;
newExercise.rightNumber = 2;
newExercise.mathOperator = Enums.Operator.add;
newExercise.answer = "4";
newExercise.answer = 4;
newExercise.userId = Guid.NewGuid();

var mock = new Mock<IExerciseRepository>();
Expand All @@ -92,7 +92,7 @@ public void post_correct_easy_question_with_no_userId()
newExercise.leftNumber = 2;
newExercise.rightNumber = 2;
newExercise.mathOperator = Enums.Operator.add;
newExercise.answer = "4";
newExercise.answer = 4;
var mock = new Mock<IExerciseRepository>();
mock.Setup(m => m.Find(It.IsAny<int>())).Returns(newExercise);
_service = new ExerciseService(mock.Object);
Expand All @@ -107,7 +107,7 @@ public void post_incorrect_easy_question()
newExercise.leftNumber = 2;
newExercise.rightNumber = 2;
newExercise.mathOperator = Enums.Operator.add;
newExercise.answer = "5";
newExercise.answer = 5;
newExercise.userId = Guid.NewGuid();
var mock = new Mock<IExerciseRepository>();
mock.Setup(m => m.Find(It.IsAny<int>())).Returns(newExercise);
Expand All @@ -123,7 +123,7 @@ public void post_correct_answer_with_no_userId()
newExercise.leftNumber = 2;
newExercise.rightNumber = 2;
newExercise.mathOperator = Enums.Operator.add;
newExercise.answer = "5";
newExercise.answer = 5;
newExercise.userId = Guid.NewGuid();
var mock = new Mock<IExerciseRepository>();
mock.Setup(m => m.Find(It.IsAny<int>())).Returns(newExercise);
Expand Down
Binary file modified WebApi/WebApi.Tests/bin/Debug/netcoreapp2.0/WebApi.Tests.dll
Binary file not shown.
Binary file modified WebApi/WebApi.Tests/bin/Debug/netcoreapp2.0/WebApi.Tests.pdb
Binary file not shown.
Binary file modified WebApi/WebApi.Tests/bin/Debug/netcoreapp2.0/WebApi.dll
Binary file not shown.
Binary file modified WebApi/WebApi.Tests/bin/Debug/netcoreapp2.0/WebApi.pdb
Binary file not shown.
Binary file not shown.
Binary file modified WebApi/WebApi.Tests/obj/Debug/netcoreapp2.0/WebApi.Tests.dll
Binary file not shown.
Binary file modified WebApi/WebApi.Tests/obj/Debug/netcoreapp2.0/WebApi.Tests.pdb
Binary file not shown.
26 changes: 16 additions & 10 deletions WebApi/WebApi/Controllers/ExerciseController.cs
Expand Up @@ -9,7 +9,7 @@

namespace WebApi.Controllers
{
[Route("api/[controller]")]
[Route("api/exercise")]
public class ExerciseController : Controller
{
ILoggerFactory _loggerFactory;
Expand All @@ -28,15 +28,14 @@ public ExerciseController(ILoggerFactory loggerFactory, IUnitOfWork unitOfWork,
}

// GET api/exercise
[HttpGet]
public IActionResult GetExercise(string userId, Difficulty difficulty = Difficulty.simple)
[HttpGet("{id?}")]
public IActionResult GetExercise(string id = null)
{
try
{
var _currentExercise = _service.createExercise(userId, difficulty);
_unitOfWork.SaveChanges();
var newScore = _scoreService.IncrementScore(_currentExercise.userId.ToString());
var _currentExercise = _service.createExercise(id);
_unitOfWork.SaveChanges();
var newScore = _scoreService.GetByUserId(_currentExercise.userId.ToString());
var response = new ExerciseScoreModel()
{
exerciseId = _currentExercise.exerciseId,
Expand All @@ -45,8 +44,8 @@ public IActionResult GetExercise(string userId, Difficulty difficulty = Difficul
mathOperator = _currentExercise.mathOperator,
answer = _currentExercise.answer,
userId = _currentExercise.userId,
level = newScore.level,
highScore = newScore.highScore,
level = newScore !=null ? newScore.level : 1,
highScore = newScore != null ? newScore.highScore : 0
};
return Ok(response);
}
Expand Down Expand Up @@ -75,8 +74,15 @@ public IActionResult PostAnswer([FromBody]Exercise exercise)
_unitOfWork.SaveChanges();
var response = new ExerciseScoreModel()
{
exercise = savedExercise,
score = newScore
exerciseId = savedExercise.exerciseId,
leftNumber = savedExercise.leftNumber,
rightNumber = savedExercise.rightNumber,
mathOperator = savedExercise.mathOperator,
answer = savedExercise.answer,
userId = savedExercise.userId,
correctAnswerGiven = savedExercise.correctAnswerGiven,
level = newScore.level,
highScore = newScore.highScore
};
return Ok(response);
}
Expand Down

This file was deleted.

31 changes: 0 additions & 31 deletions WebApi/WebApi/Migrations/20181017150311_AddedScoreTable.cs

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -16,20 +16,36 @@ protected override void Up(MigrationBuilder migrationBuilder)
leftNumber = table.Column<int>(nullable: false),
rightNumber = table.Column<int>(nullable: false),
mathOperator = table.Column<int>(nullable: false),
answer = table.Column<string>(nullable: true),
answer = table.Column<double>(nullable: true),
correctAnswerGiven = table.Column<bool>(nullable: false),
userId = table.Column<Guid>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Exercise", x => x.exerciseId);
});

migrationBuilder.CreateTable(
name: "Score",
columns: table => new
{
userId = table.Column<Guid>(nullable: false),
level = table.Column<int>(nullable: false),
highScore = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Score", x => x.userId);
});
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Exercise");

migrationBuilder.DropTable(
name: "Score");
}
}
}
16 changes: 15 additions & 1 deletion WebApi/WebApi/Migrations/ExerciseContextModelSnapshot.cs
Expand Up @@ -21,7 +21,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<int>("exerciseId")
.ValueGeneratedOnAdd();
b.Property<string>("answer");
b.Property<double?>("answer");
b.Property<bool>("correctAnswerGiven");
Expand All @@ -37,6 +37,20 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("Exercise");
});

modelBuilder.Entity("WebApi.Model.Score", b =>
{
b.Property<Guid>("userId")
.ValueGeneratedOnAdd();
b.Property<int>("highScore");
b.Property<int>("level");
b.HasKey("userId");
b.ToTable("Score");
});
#pragma warning restore 612, 618
}
}
Expand Down
2 changes: 1 addition & 1 deletion WebApi/WebApi/Models/Exercise.cs
Expand Up @@ -11,7 +11,7 @@ public class Exercise
public int leftNumber { get; set; }
public int rightNumber { get; set; }
public Operator mathOperator { get; set; }
public string answer { get; set; }
public double? answer { get; set; }
public bool correctAnswerGiven { get;set; }
public Guid userId { get; set; }
}
Expand Down
2 changes: 1 addition & 1 deletion WebApi/WebApi/Models/ViewModels/ExerciseScoreModel.cs
Expand Up @@ -9,7 +9,7 @@ public class ExerciseScoreModel
public int leftNumber { get; set; }
public int rightNumber { get; set; }
public Operator mathOperator { get; set; }
public string answer { get; set; }
public double? answer { get; set; }
public bool correctAnswerGiven { get; set; }
public Guid userId { get; set; }
public int level { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion WebApi/WebApi/Properties/launchSettings.json
Expand Up @@ -11,7 +11,7 @@
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/exercise",
"launchUrl": "api/exercise/",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
10 changes: 9 additions & 1 deletion WebApi/WebApi/Repository/ExerciseRepository.cs
Expand Up @@ -30,6 +30,14 @@ public Exercise Find(int id)
return _repository.Find(id);
}

public IList<Exercise> FindByUserId(Guid userId)
{
return _repository
.Queryable()
.Where(u => u.userId.Equals(userId.ToString()))
.ToList();
}

public IEnumerable<Exercise> GetAll()
{
return _repository.GetAll();
Expand All @@ -42,7 +50,7 @@ public IList<Exercise> GetUnansweredMatch(Exercise exercise)
.Where(u => u.leftNumber == exercise.leftNumber
&& u.mathOperator == exercise.mathOperator
&& u.rightNumber == exercise.rightNumber
&& string.IsNullOrEmpty(u.answer)
&& u.answer == null
&& u.correctAnswerGiven == false)
.ToList();
}
Expand Down
1 change: 1 addition & 0 deletions WebApi/WebApi/Repository/IExerciseRepository.cs
Expand Up @@ -9,5 +9,6 @@ namespace WebApi.Repository
public interface IExerciseRepository : IRepository<Exercise>
{
IList<Exercise> GetUnansweredMatch(Exercise exercise);
IList<Exercise> FindByUserId(Guid userId);
}
}

0 comments on commit 4a36e5e

Please sign in to comment.