Changeset 899b19d for resTools_backend/backend/Services
- Timestamp:
- 07/10/22 10:27:45 (2 years ago)
- Branches:
- master
- Children:
- a26f6a1
- Parents:
- cc4db18
- Location:
- resTools_backend/backend/Services
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
resTools_backend/backend/Services/RestaurantService.cs
rcc4db18 r899b19d 32 32 { 33 33 RestaurantResponse res = await _context.Restoraunts 34 .Include(x => x.Menu) 35 .Include(x => x.Reviews).ThenInclude(x => x.User) 34 36 .Select(x => new RestaurantResponse() 35 37 { … … 44 46 Description = x.Description, 45 47 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 47 59 }) 48 60 .FirstOrDefaultAsync(); -
resTools_backend/backend/Services/UserService.cs
rcc4db18 r899b19d 15 15 { 16 16 Task<AuthenticateResponse> Authenticate(AuthenticateRequest model); 17 Task<AuthenticateResponse> Register(CreateUserRequest req );17 Task<AuthenticateResponse> Register(CreateUserRequest req, bool isFirst); 18 18 Task<User> GetById(int id); 19 19 } … … 40 40 var token = generateJwtToken(user); 41 41 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}; 43 43 } 44 44 … … 48 48 } 49 49 50 public async Task<AuthenticateResponse> Register(CreateUserRequest req )50 public async Task<AuthenticateResponse> Register(CreateUserRequest req, bool isFirst) 51 51 { 52 User user = new User() { Email = req.Email, Password = req.Password };52 User user = new User() { Email = req.Email, Password = req.Password, IsAdmin = isFirst }; 53 53 await _context.Users.AddAsync(user); 54 54 await _context.SaveChangesAsync(); 55 55 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 }; 57 57 } 58 58
Note:
See TracChangeset
for help on using the changeset viewer.