Ignore:
Timestamp:
07/10/22 10:27:45 (2 years ago)
Author:
Danilo <danilo.najkov@…>
Branches:
master
Children:
a26f6a1
Parents:
cc4db18
Message:

reviews full feature

Location:
resTools_backend/backend/Services
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • resTools_backend/backend/Services/RestaurantService.cs

    rcc4db18 r899b19d  
    3232        {
    3333            RestaurantResponse res = await _context.Restoraunts
     34                .Include(x => x.Menu)
     35                .Include(x => x.Reviews).ThenInclude(x => x.User)
    3436                .Select(x => new RestaurantResponse()
    3537                {
     
    4446                        Description = x.Description,
    4547                        Price = x.Price
    46                     }).ToList()
     48                    }).ToList(),
     49                    Reviews = x.Reviews.OrderByDescending(x => x.CreatedAt).Select(x => new ReviewResponse()
     50                    {
     51                        Id = x.Id,
     52                        Title = x.Title,
     53                        Description = x.Description,
     54                        Stars = x.Stars,
     55                        CreatedAt = x.CreatedAt,
     56                        Username = x.User == null ? "Anonymous" : x.User.Email
     57                    }).ToList(),
     58                    AverageReview = x.Reviews.Count>0 ? x.Reviews.Select(x => x.Stars).Average() : 0
    4759                })
    4860                .FirstOrDefaultAsync();
  • resTools_backend/backend/Services/UserService.cs

    rcc4db18 r899b19d  
    1515{
    1616    Task<AuthenticateResponse> Authenticate(AuthenticateRequest model);
    17     Task<AuthenticateResponse> Register(CreateUserRequest req);
     17    Task<AuthenticateResponse> Register(CreateUserRequest req, bool isFirst);
    1818    Task<User> GetById(int id);
    1919}
     
    4040        var token = generateJwtToken(user);
    4141
    42         return new AuthenticateResponse { Email = user.Email, Id = user.Id, Token = token};
     42        return new AuthenticateResponse { Email = user.Email, Id = user.Id, Token = token, IsAdmin = user.IsAdmin};
    4343    }
    4444
     
    4848    }
    4949
    50     public async Task<AuthenticateResponse> Register(CreateUserRequest req)
     50    public async Task<AuthenticateResponse> Register(CreateUserRequest req, bool isFirst)
    5151    {
    52         User user = new User() { Email = req.Email, Password = req.Password };
     52        User user = new User() { Email = req.Email, Password = req.Password, IsAdmin = isFirst };
    5353        await _context.Users.AddAsync(user);
    5454        await _context.SaveChangesAsync();
    5555        var token = generateJwtToken(user);
    56         return new AuthenticateResponse { Email = user.Email, Id = user.Id, Token = token };
     56        return new AuthenticateResponse { Email = user.Email, Id = user.Id, Token = token, IsAdmin = user.IsAdmin };
    5757    }
    5858
Note: See TracChangeset for help on using the changeset viewer.