public ActionResult <Habit> UpdateHabit(Guid userID, Guid id, [FromBody] RequestData data) { using (var uw = new PostgresUnitOfWork(connString)) { if (IsUserIdValid(userID) != false) { Habit h = uw.HabitRepo.FindById(id); if (h == null || h.UserID != userID) { return(NotFound("habit not found")); } else { uw.HabitRepo.Update(h, data.Name, data.DaysOff); h = uw.HabitRepo.FindById(id); uw.Commit(); return(h); } } else { return(NotFound("user not found")); } } }
public ActionResult <Habit> Log(Guid userID, Guid id) { using (var uw = new PostgresUnitOfWork(connString)) { if (IsUserIdValid(userID) != false) { DateTime curentDate = DateTime.Now; Habit h = uw.HabitRepo.FindById(id); if (h == null || h.UserID != userID) { return(NotFound("habit not found")); } else { uw.HabitRepo.AddLog(h, curentDate); Habit newHabit = uw.HabitRepo.FindById(id); uw.Commit(); return(newHabit); } } else { return(NotFound("user not found")); } } }
public void ValidUser() { using (var uw = new PostgresUnitOfWork(connString)) { User u = uw.UserRepo.FindById(user_id); Assert.Equal(user_id, u.ID); } }
public void UserNotValid() { using (var uw = new PostgresUnitOfWork(connString)) { User u = uw.UserRepo.FindById(id); Assert.Null(u); } }
public void createNewDominatingBadge() { using (var uw = new PostgresUnitOfWork(connString)) { Badge b = new Badge("Dominating", "4+ streak"); uw.BadgeRepo.Create(b); uw.Commit(); Assert.Equal("Dominating", b.Name); } }
public void WinVertical() { using (var uw = new PostgresUnitOfWork(connString)) { User amir = User.NewUser("Amir"); User budi = User.NewUser("Budi"); uw.UserRepo.Create(amir); uw.UserRepo.Create(budi); Room room = new Room(2); uw.RoomRepo.Create(room); room.Join(amir); uw.RoomRepo.Join(room, amir); room.Join(budi); uw.RoomRepo.Join(room, budi); room.StartGame("tic-tac-toe", GameConfig.Default(), uw.UserRepo); uw.RoomRepo.ChangeGame(room, room.Game, GameConfig.Default()); Move move; move = new TicTacToeMove(amir.ID, 4); room.Move(move); uw.RoomRepo.AddMove(room, move); move = new TicTacToeMove(budi.ID, 3); room.Move(move); uw.RoomRepo.AddMove(room, move); move = new TicTacToeMove(amir.ID, 7); room.Move(move); uw.RoomRepo.AddMove(room, move); move = new TicTacToeMove(budi.ID, 0); room.Move(move); uw.RoomRepo.AddMove(room, move); move = new TicTacToeMove(amir.ID, 1); room.Move(move); uw.RoomRepo.AddMove(room, move); move = new TicTacToeMove(budi.ID, 3); Exception ex = Assert.Throws <Exception>(() => room.Move(move)); uw.RoomRepo.AddMove(room, move); Assert.Equal("game already ended", ex.Message); Assert.Equal(5, uw.UserRepo.FindById(amir.ID).Exp); Assert.Equal(2, uw.UserRepo.FindById(budi.ID).Exp); } }
private Boolean IsUserIdValid(Guid userID) { using (var uw = new PostgresUnitOfWork(connString)) { User u = uw.UserRepo.FindById(userID); if (u == null) { return(false); } return(true); } }
public void CreateRoom() { using (var uw = new PostgresUnitOfWork(connString)) { Room r = new Room(4); uw.RoomRepo.Create(r); uw.Rollback(); Room r2 = uw.RoomRepo.FindById(r.ID); Assert.Null(r2); } }
public void LogTest() { using (var uw = new PostgresUnitOfWork(connString)) { for (int i = 0; i < 1; i++) { DateTime curentDate = DateTime.Now.AddDays(i + 3); Habit h = uw.HabitRepo.FindById(id); uw.HabitRepo.AddLog(h, curentDate); } uw.Commit(); Badge[] badges = uw.BadgeRepo.GetAllBadgeByUserId(user_id); Assert.Equal("Dominating", badges[0].Name); } }
public ActionResult <IEnumerable <Badge> > All(Guid userID) { DotNetEnv.Env.Load(); PostgresUnitOfWork unit = new PostgresUnitOfWork(System.Environment.GetEnvironmentVariable("CONN_STR")); //mock only. replace with your solution return(new[] { new Badge { ID = Guid.NewGuid(), Name = "Dominating", Description = "4+ streak", CreatedAt = DateTime.Now.AddDays(-13), }, new Badge { ID = Guid.NewGuid(), Name = "Epic Comeback", Description = "10 streak after 10 days without logging", CreatedAt = DateTime.Now.AddDays(-7), } }); }
public ActionResult <Habit> Get(Guid userID, Guid id) { using (var uw = new PostgresUnitOfWork(connString)) { if (IsUserIdValid(userID) != false) { Habit h = uw.HabitRepo.FindById(id); if (h == null || h.UserID != userID) { return(NotFound("habit not found")); } else { return(h); } } else { return(NotFound("user not found")); } } }
public ActionResult <IEnumerable <Badge> > All(Guid userID) { using (var uw = new PostgresUnitOfWork(connString)) { if (IsUserIdValid(userID) != false) { Badge[] b = uw.BadgeRepo.GetAllBadgeByUserId(userID); Array.Resize(ref b, b.Length - 1); if (b == null) { return(NotFound("Badge not found")); } else { return(b); } } else { return(NotFound("user not found")); } } }
public ActionResult <IEnumerable <Habit> > All(Guid userID) { using (var uw = new PostgresUnitOfWork(connString)) { if (IsUserIdValid(userID) != false) { Habit[] h = uw.HabitRepo.GetAllHabitByUserId(userID); Array.Resize(ref h, h.Length - 1); if (h.Length <= 0) { return(NotFound("there is no habit")); } else { return(h); } } else { return(NotFound("user not found")); } } }
public ActionResult <Habit> AddNewHabit(Guid userID, [FromBody] RequestData data) { using (var uw = new PostgresUnitOfWork(connString)) { if (IsUserIdValid(userID) != false) { Habit h = new Habit(data.Name, data.DaysOff, userID); uw.HabitRepo.Create(h); uw.Commit(); if (h == null) { return(NotFound("habit not found")); } else { return(h); } } else { return(NotFound("user not found")); } } }
public AuthorizationController(PostgresUnitOfWork unitOfWork) { _unitOfWork = unitOfWork; }