Skip to content

Commit

Permalink
Merge pull request #24 from PasinduPrabhashitha/orders-crud
Browse files Browse the repository at this point in the history
fix✨: Roll back to object id
  • Loading branch information
pasindu-pr authored Apr 8, 2023
2 parents 9d66ddf + a7bd16b commit a738cc9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
7 changes: 3 additions & 4 deletions src/services/Florage.Shared/Contracts/IRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ namespace Florage.Shared.Contracts
public interface IRepository<T> where T : class
{
Task CreateAsync(T entity);
Task DeleteAsync(string attribute, string value);
Task DeleteAsync(string id);
Task<IReadOnlyCollection<T>> GetAllAsync();
Task<IReadOnlyCollection<T>> GetAllAsync(Expression<Func<T, bool>> filter);
Task<T> FilterAsync(Expression<Func<T, bool>> filter);
Task<T> GetByIdAsync(string id);
Task<T> GetOneAsync(string attribute, string value);
Task UpdateAsync(string attribute, string value, T entity);
Task<T> GetByIdAsync(string id);
Task UpdateAsync(string id, T entity);
}
}
17 changes: 6 additions & 11 deletions src/services/Florage.Shared/Repositories/GenericRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public async Task CreateAsync(T entity)
await dbCollection.InsertOneAsync(entity);
}

public async Task DeleteAsync(string attribute, string value)
public async Task DeleteAsync(string id)
{
await dbCollection.DeleteOneAsync(filterBuilder.Eq(attribute, value));
}
await dbCollection.DeleteOneAsync(filterBuilder.Eq("Id", id));
}

public async Task<T> FilterAsync(Expression<Func<T, bool>> filter)
{
Expand All @@ -42,17 +42,12 @@ public async Task<IReadOnlyCollection<T>> GetAllAsync(Expression<Func<T, bool>>
public async Task<T> GetByIdAsync(string id)
{
return await dbCollection.Find(filterBuilder.Eq("Id", id)).FirstOrDefaultAsync();
}
}

public async Task<T> GetOneAsync(string attribute, string value)
public async Task UpdateAsync(string id, T entity)
{
return await dbCollection.Find(filterBuilder.Eq(attribute, value)).FirstOrDefaultAsync();
await dbCollection.ReplaceOneAsync(filterBuilder.Eq("Id", id), entity);
}

public async Task UpdateAsync(string attribute, string value,T entity)
{
await dbCollection.ReplaceOneAsync(filterBuilder.Eq(attribute, value), entity);
}

}
}

0 comments on commit a738cc9

Please sign in to comment.