Code Monkey home page Code Monkey logo

Comments (8)

iammukeshm avatar iammukeshm commented on May 8, 2024

This was already fixed in the new release. Which version of the nuget package are you using?

from dotnet-webapi-starter-kit.

ghaith100994 avatar ghaith100994 commented on May 8, 2024

rc-3

from dotnet-webapi-starter-kit.

ghaith100994 avatar ghaith100994 commented on May 8, 2024
public async Task<TDto> GetByIdAsync<T, TDto>(Guid entityId, BaseSpecification<T> specification, CancellationToken cancellationToken = default)
        where T : BaseEntity
        where TDto : IDto
        {
            string cacheKey = CacheKeys.GetCacheKey<T>(entityId);
            byte[] cachedData = !string.IsNullOrWhiteSpace(cacheKey) ? await _cache.GetAsync(cacheKey, cancellationToken) : null;
            if (cachedData != null)
            {
                await _cache.RefreshAsync(cacheKey, cancellationToken);
                var entity = _serializer.Deserialize<TDto>(Encoding.Default.GetString(cachedData));
                return entity;
            }
            else
            {
                IQueryable<T> query = _dbContext.Set<T>();
                if (specification != null)
                    query = query.Specify(specification).Where(a => a.Id == entityId);
                var entity = await query.FirstOrDefaultAsync(cancellationToken: cancellationToken);
                var dto = entity.Adapt<TDto>();
                if (dto != null)
                {
                    if ((specification?.Includes?.Count == 0) || specification == null)
                    {
                        var options = new DistributedCacheEntryOptions();
                        byte[] serializedData = Encoding.Default.GetBytes(_serializer.Serialize(dto));
                        await _cache.SetAsync(cacheKey, serializedData, options, cancellationToken);
                    }

                    return dto;
                }

                throw new EntityNotFoundException(string.Format(_localizer["entity.notfound"], typeof(T).Name, entityId));
            }
        }

here when specification is null no filtering is done

from dotnet-webapi-starter-kit.

iammukeshm avatar iammukeshm commented on May 8, 2024

Please check RC 4 . This bug was fixed. Do let me know if you face any additional issues related to this. Thanks

https://www.nuget.org/packages/FullStackHero.WebAPI.Boilerplate/0.0.4-rc

from dotnet-webapi-starter-kit.

ghaith100994 avatar ghaith100994 commented on May 8, 2024

the bug still exit in the RC 4
I think you have fixed it for this function
public async Task<T> GetByIdAsync<T>(Guid entityId, BaseSpecification<T> specification = null, CancellationToken cancellationToken = default)
not the other one
public async Task<TDto> GetByIdAsync<T, TDto>(Guid entityId, BaseSpecification<T> specification, CancellationToken cancellationToken = default)

the answer
if (specification != null)
query = query.Specify(specification).Where(a => a.Id == entityId);
else
query = query.Where(a => a.Id == entityId);

from dotnet-webapi-starter-kit.

iammukeshm avatar iammukeshm commented on May 8, 2024

Thanks for pointing it out. Could you test it now? I have added the changes.

from dotnet-webapi-starter-kit.

iammukeshm avatar iammukeshm commented on May 8, 2024

Please pull the latest code from the repository and try.

from dotnet-webapi-starter-kit.

ghaith100994 avatar ghaith100994 commented on May 8, 2024

Thanks It's Work

from dotnet-webapi-starter-kit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.