passed all postman tests!
This commit is contained in:
@@ -45,7 +45,15 @@ namespace keepr.Controllers
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Account userInfo = await HttpContext.GetUserInfoAsync<Account>();
|
Account userInfo = await HttpContext.GetUserInfoAsync<Account>();
|
||||||
Vault vault = _vs.GetById(vaultId, userInfo.Id);
|
Vault vault;
|
||||||
|
if (userInfo == null)
|
||||||
|
{
|
||||||
|
vault = _vs.GetByIdAnon(vaultId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vault = _vs.GetById(vaultId, userInfo.Id);
|
||||||
|
}
|
||||||
return Ok(vault);
|
return Ok(vault);
|
||||||
}
|
}
|
||||||
catch (System.Exception e)
|
catch (System.Exception e)
|
||||||
@@ -60,8 +68,16 @@ namespace keepr.Controllers
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Account userInfo = await HttpContext.GetUserInfoAsync<Account>();
|
Account userInfo = await HttpContext.GetUserInfoAsync<Account>();
|
||||||
Vault vault = _vs.GetById(vaultId, userInfo.Id);
|
Vault vault;
|
||||||
List<Keep> keeps = _vks.GetVaultKeeps(vault.Id);
|
if (userInfo == null)
|
||||||
|
{
|
||||||
|
vault = _vs.GetByIdAnon(vaultId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vault = _vs.GetById(vaultId, userInfo.Id);
|
||||||
|
}
|
||||||
|
List<KeepVaultViewModel> keeps = _vks.GetVaultKeeps(vault.Id);
|
||||||
return Ok(keeps);
|
return Ok(keeps);
|
||||||
}
|
}
|
||||||
catch (System.Exception e)
|
catch (System.Exception e)
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ namespace keepr.Models
|
|||||||
// shares int - stretch goal
|
// shares int - stretch goal
|
||||||
}
|
}
|
||||||
|
|
||||||
// public class KeepVaultViewModel : Keep
|
public class KeepVaultViewModel : Keep
|
||||||
// {
|
{
|
||||||
// public int MyProperty { get; set; }
|
public int VaultKeepId { get; set; }
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
@@ -43,7 +43,8 @@ namespace keepr.Repositories
|
|||||||
(@CreatorId, @Name, @Description, @Img);
|
(@CreatorId, @Name, @Description, @Img);
|
||||||
SELECT LAST_INSERT_ID();
|
SELECT LAST_INSERT_ID();
|
||||||
";
|
";
|
||||||
keep.Id = _db.ExecuteScalar<int>(sql, keep);
|
int keepId = _db.ExecuteScalar<int>(sql, keep);
|
||||||
|
keep = GetById(keepId);
|
||||||
return keep;
|
return keep;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -68,12 +68,13 @@ namespace keepr.Repositories
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal List<Keep> GetVaultKeeps(int vaultId)
|
internal List<KeepVaultViewModel> GetVaultKeeps(int vaultId)
|
||||||
{
|
{
|
||||||
string sql = @"
|
string sql = @"
|
||||||
SELECT
|
SELECT
|
||||||
a.*,
|
a.*,
|
||||||
k.*
|
k.*,
|
||||||
|
vk.id
|
||||||
FROM keeps k
|
FROM keeps k
|
||||||
JOIN accounts a
|
JOIN accounts a
|
||||||
ON a.id = k.creatorId
|
ON a.id = k.creatorId
|
||||||
@@ -81,9 +82,10 @@ namespace keepr.Repositories
|
|||||||
ON vk.keepId = k.id
|
ON vk.keepId = k.id
|
||||||
WHERE vk.vaultId = @vaultId;
|
WHERE vk.vaultId = @vaultId;
|
||||||
";
|
";
|
||||||
return _db.Query<Profile, Keep, Keep>(sql, (prof, keep) =>
|
return _db.Query<Profile, KeepVaultViewModel, int, KeepVaultViewModel>(sql, (prof, keep, vkid) =>
|
||||||
{
|
{
|
||||||
keep.Creator = prof;
|
keep.Creator = prof;
|
||||||
|
keep.VaultKeepId = vkid;
|
||||||
return keep;
|
return keep;
|
||||||
}, new {vaultId}).ToList();
|
}, new {vaultId}).ToList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ namespace keepr.Repositories
|
|||||||
(@CreatorId, @Name, @Description, @IsPrivate);
|
(@CreatorId, @Name, @Description, @IsPrivate);
|
||||||
SELECT LAST_INSERT_ID();
|
SELECT LAST_INSERT_ID();
|
||||||
";
|
";
|
||||||
vaultData.Id = _db.ExecuteScalar<int>(sql, vaultData);
|
int vaultId = _db.ExecuteScalar<int>(sql, vaultData);
|
||||||
|
vaultData = GetById(vaultId);
|
||||||
return vaultData;
|
return vaultData;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -66,11 +67,13 @@ namespace keepr.Repositories
|
|||||||
ON v.creatorId = a.id
|
ON v.creatorId = a.id
|
||||||
WHERE v.id = @id;
|
WHERE v.id = @id;
|
||||||
";
|
";
|
||||||
return _db.Query<Profile, Vault, Vault>(sql, (prof, vaul) =>
|
Vault vault = _db.Query<Profile, Vault, Vault>(sql, (prof, vaul) =>
|
||||||
{
|
{
|
||||||
vaul.Creator = prof;
|
vaul.Creator = prof;
|
||||||
return vaul;
|
return vaul;
|
||||||
}, new {id}).FirstOrDefault();
|
}, new {id}).FirstOrDefault();
|
||||||
|
|
||||||
|
return vault;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal Vault Update(Vault update)
|
internal Vault Update(Vault update)
|
||||||
|
|||||||
@@ -38,8 +38,14 @@ namespace keepr.Services
|
|||||||
|
|
||||||
internal Keep GetById(int id)
|
internal Keep GetById(int id)
|
||||||
{
|
{
|
||||||
|
|
||||||
_repo.IncViews(id);
|
_repo.IncViews(id);
|
||||||
return _repo.GetById(id);
|
Keep keep = _repo.GetById(id);
|
||||||
|
if (keep == null)
|
||||||
|
{
|
||||||
|
throw new Exception("No keep for you!");
|
||||||
|
}
|
||||||
|
return keep;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal Keep CheckById(int id)
|
internal Keep CheckById(int id)
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ namespace keepr.Services
|
|||||||
return _repo.Remove(vaultKeep.Id);
|
return _repo.Remove(vaultKeep.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal List<Keep> GetVaultKeeps(int vaultId)
|
internal List<KeepVaultViewModel> GetVaultKeeps(int vaultId)
|
||||||
{
|
{
|
||||||
return _repo.GetVaultKeeps(vaultId);
|
return _repo.GetVaultKeeps(vaultId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,21 @@ namespace keepr.Services
|
|||||||
{
|
{
|
||||||
throw new Exception("No vault for you!");
|
throw new Exception("No vault for you!");
|
||||||
}
|
}
|
||||||
if (vault.CreatorId != userId && vault.IsPrivate == true)
|
if (vault.IsPrivate == true && vault.CreatorId != userId)
|
||||||
|
{
|
||||||
|
throw new Exception("No vault for you!");
|
||||||
|
}
|
||||||
|
return vault;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal Vault GetByIdAnon(int vaultId)
|
||||||
|
{
|
||||||
|
Vault vault = _repo.GetById(vaultId);
|
||||||
|
if (vault == null)
|
||||||
|
{
|
||||||
|
throw new Exception("No vault for you!");
|
||||||
|
}
|
||||||
|
if (vault.IsPrivate == true)
|
||||||
{
|
{
|
||||||
throw new Exception("No vault for you!");
|
throw new Exception("No vault for you!");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user