Changeset b67dfd3


Ignore:
Timestamp:
05/06/25 00:44:02 (11 days ago)
Author:
Aleksandar Panovski <apano77@…>
Branches:
main
Children:
e48199a
Parents:
142c0f8
Message:

Normalization needed to continue, till here done

Files:
10 deleted
29 edited

Legend:

Unmodified
Added
Removed
  • my-react-app/src/App.js

    r142c0f8 rb67dfd3  
    11import {BrowserRouter as Router, Navigate, Route, Routes, useNavigate} from 'react-router-dom';
    22
    3 import Customers from './components/Customers';
    43import Layout from "./components/Layout";
    54import React, {useContext, useEffect, useState} from 'react';
    6 import CustomerFormContainer from "./components/CustomerFormContainer";
    7 import CustomerDetails from "./components/CustomerDetails";
    85import ErrorPage from "./components/ErrorPage";
    96import Restaurants from "./components/Restaurants";
     
    4138                <Routes>
    4239                    <Route path="/" element={<Home />} />
    43                     <Route path="/customers" element={<ProtectedRoute isAuthenticated={isAuthenticated} element={<Customers />} />} />
    44                     <Route path="/customers/add" element={<ProtectedRoute isAuthenticated={isAuthenticated} element={<CustomerFormContainer />} />} />
    45                     <Route path="/customers/:id" element={<ProtectedRoute isAuthenticated={isAuthenticated} element={<CustomerDetails />} />} />
    46                     <Route path="/customers/edit/:id" element={<ProtectedRoute isAuthenticated={isAuthenticated} element={<CustomerFormContainer />} />} />
    4740                    <Route path="/restaurants" element={<ProtectedRoute isAuthenticated={isAuthenticated} element={<Restaurants />} />} />
    4841                    <Route path="/restaurants/:id" element={<ProtectedRoute isAuthenticated={isAuthenticated} element={<RestaurantDetails />} />} />
  • my-react-app/src/components/MenuList.js

    r142c0f8 rb67dfd3  
    1515            const exists = prevItems.find(i => i.id === item.id);
    1616            if (exists) {
    17                 return prevItems.filter(i => i.id !== item.id); // remove
     17                return prevItems.filter(i => i.id !== item.id);
    1818            } else {
    19                 return [...prevItems, item]; // add
     19                return [...prevItems, item];
    2020            }
    2121        });
  • my-react-app/src/components/ReservationConfirmation.js

    r142c0f8 rb67dfd3  
    2727                const tableResponse = await axios.get(`http://localhost:8081/api/tables/${tableNumber}`);
    2828                setTable(tableResponse.data);
    29 
     29                console.log(tableResponse.data)
    3030                const restaurantResponse = await axios.get(`http://localhost:8081/api/restaurants/${restaurantId}`);
    3131                setRestaurant(restaurantResponse.data);
     
    6363            paymentStatus: 'Pending',
    6464            preOrderedItems: preOrderedItems.map(item => ({
    65                 name: item.itemName,
     65                preorderedItemName: item.itemName,
    6666                quantity: item.quantity,
    6767                price: item.price
    6868            }))
    6969        };
    70         console.log(payload)
    7170
    7271
    7372        try {
    74             console.log(payload)
    7573            const response = await axios.post('http://localhost:8081/api/reservations', payload, {
    7674                headers: {
  • my-react-app/src/components/Reservations.js

    r142c0f8 rb67dfd3  
    101101                                                {reservation.preOrderedItems.map((item, index) => (
    102102                                                    <li key={index} className="list-group-item d-flex justify-content-between align-items-center">
    103                                                         <span><strong>{item.name}</strong> × {item.quantity}</span>
     103                                                        <span><strong>{item?.preorderedItemName}</strong> × {item.quantity}</span>
    104104                                                        <span className="badge bg-success rounded-pill">${(item.price * item.quantity).toFixed(2)}</span>
    105105                                                    </li>
  • my-react-app/src/components/RestaurantDetails.js

    r142c0f8 rb67dfd3  
    112112    };
    113113
     114    console.log(preOrderedItems)
    114115
    115116    const roundToNext15Minutes = (date) => {
  • my-react-app/src/index.js

    r142c0f8 rb67dfd3  
    55import { CuisineProvider } from './components/CuisineContext';
    66import {RestaurantProvider} from "./components/RestaurantContext";
    7 import {CustomerProvider} from "./components/CustomerContext";
    87
    98const root = ReactDOM.createRoot(document.getElementById('root'));
     
    1211        <CuisineProvider>
    1312            <RestaurantProvider>
    14                 <CustomerProvider>
    1513                    <App />
    16                 </CustomerProvider>
    1714            </RestaurantProvider>
    1815        </CuisineProvider>
  • src/main/java/com/example/rezevirajmasa/demo/config/ModelMapperConfig.java

    r142c0f8 rb67dfd3  
    1717        ModelMapper modelMapper = new ModelMapper();
    1818
    19         // Map Restaurant to RestaurantDTO
    2019        modelMapper.typeMap(Restaurant.class, RestaurantDTO.class).addMappings(mapper -> {
    2120            mapper.map(Restaurant::getTablesList, RestaurantDTO::setTablesList);
    2221        });
    2322
    24         // Map TableEntity to TableDTO
    2523        modelMapper.typeMap(TableEntity.class, TableDTO.class).addMappings(mapper -> {
    2624            mapper.map(TableEntity::getReservations, TableDTO::setReservations);
    2725        });
    2826
    29         // Map Reservation to ReservationDTO
    30         modelMapper.typeMap(Reservation.class, ReservationDTO.class);
     27        modelMapper.typeMap(Reservation.class, ReservationDTO.class).addMappings(mapper -> {
     28            mapper.map(Reservation::getReservationStatus, ReservationDTO::setReservationStatus);
     29            mapper.map(Reservation::getPaymentStatus, ReservationDTO::setPaymentStatus);
     30        });
    3131
    3232        return modelMapper;
  • src/main/java/com/example/rezevirajmasa/demo/dto/ReservationDTO.java

    r142c0f8 rb67dfd3  
    1818    private Long restaurantId;
    1919    private int partySize;
    20     private String status;
     20    private String reservationStatus;
    2121    private String specialRequests;
    2222    private String paymentStatus;
     
    2626    }
    2727
    28     public ReservationDTO(Long reservationID, String userEmail, BigDecimal rating, Long tableNumber, LocalDateTime reservationDateTime, LocalDateTime checkInTime, Long restaurantId, int partySize, String status, String specialRequests, String paymentStatus, List<PreorderedItem> preOrderedItems) {
     28    public ReservationDTO(Long reservationID, String userEmail, BigDecimal rating, Long tableNumber,
     29                          LocalDateTime reservationDateTime, LocalDateTime checkInTime, Long restaurantId,
     30                          int partySize, String reservationStatus, String specialRequests,
     31                          String paymentStatus, List<PreorderedItem> preOrderedItems) {
    2932        this.reservationID = reservationID;
    3033        this.userEmail = userEmail;
     
    3336        this.reservationDateTime = reservationDateTime;
    3437        this.checkInTime = checkInTime;
    35         this.reservationID = restaurantId;
     38        this.restaurantId = restaurantId;
    3639        this.partySize = partySize;
    37         this.status = status;
     40        this.reservationStatus = reservationStatus;
    3841        this.specialRequests = specialRequests;
    3942        this.paymentStatus = paymentStatus;
     
    5053        this.restaurantId = reservation.getRestaurant().getRestaurantId();
    5154        this.partySize = reservation.getPartySize();
    52         this.status = reservation.getStatus();
     55        this.reservationStatus = reservation.getReservationStatus();
    5356        this.specialRequests = reservation.getSpecialRequests();
    5457        this.paymentStatus = reservation.getPaymentStatus();
     
    121124
    122125    public String getStatus() {
    123         return status;
     126        return reservationStatus;
    124127    }
    125128
    126     public void setStatus(String status) {
    127         this.status = status;
     129    public void setReservationStatus(String reservationStatus) {
     130        this.reservationStatus = reservationStatus;
    128131    }
    129132
  • src/main/java/com/example/rezevirajmasa/demo/dto/TableDTO.java

    r142c0f8 rb67dfd3  
    2323    }
    2424
    25     // Getters and setters
    2625    public Long getId() {
    2726        return id;
  • src/main/java/com/example/rezevirajmasa/demo/mappers/UserMapperImpl.java

    r142c0f8 rb67dfd3  
    1919
    2020        UserDto userDto = new UserDto();
    21         userDto.setId(user.getId());
     21        userDto.setId(user.getUserId());
    2222        userDto.setFirstName(user.getFirstName());
    2323        userDto.setLastName(user.getLastName());
     
    3737        user.setFirstName(userDto.getFirstName());
    3838        user.setLastName(userDto.getLastName());
    39         user.setPassword(Arrays.toString(userDto.getPassword())); // Assuming password is a char[] or string array.
     39        user.setPassword(Arrays.toString(userDto.getPassword()));
    4040
    4141        return user;
     
    5353        signUpDto.setLastName(userDto.getLastName());
    5454
    55         // Since SignUpDto has password field, you may set it if needed.
    56         // Assuming a default value or handling empty password as required.
    57         signUpDto.setPassword(new char[0]); // Empty password for now or assign actual value if required.
     55        signUpDto.setPassword(new char[0]);
    5856
    5957        return signUpDto;
     
    7371        user.setAddress(userDto.getAddress());
    7472        user.setEmail(userDto.getEmail());
    75         user.setId(userDto.getId());
     73        user.setUserId(userDto.getId());
    7674
    7775        return user;
  • src/main/java/com/example/rezevirajmasa/demo/model/Menu.java

    r142c0f8 rb67dfd3  
    2626    private String itemName;
    2727
    28     @Column(name = "category", length = 50)
    29     private String category;
     28    @Column(name = "menuCategory", length = 50)
     29    private String menuCategory;
    3030
    3131    @Column(name = "price", precision = 8, scale = 2)
     
    4545        this.restaurant = restaurant;
    4646        this.itemName = itemName;
    47         this.category = category;
     47        this.menuCategory = category;
    4848        this.price = price;
    4949        this.description = description;
  • src/main/java/com/example/rezevirajmasa/demo/model/MenuTag.java

    r142c0f8 rb67dfd3  
    1111    @Id
    1212    @GeneratedValue(strategy = GenerationType.IDENTITY)
    13     private Long id;
     13    private Long menuTagId;
    1414
    1515    @ManyToOne(fetch = FetchType.LAZY)
  • src/main/java/com/example/rezevirajmasa/demo/model/PreorderedItem.java

    r142c0f8 rb67dfd3  
    2020    @Id
    2121    @GeneratedValue(strategy = GenerationType.IDENTITY)
    22     private Long id;
     22    private Long preorderedItemId;
    2323
    24     private String name;
     24    private String preorderedItemName;
    2525
    2626    private Integer quantity;
  • src/main/java/com/example/rezevirajmasa/demo/model/Reservation.java

    r142c0f8 rb67dfd3  
    4848
    4949    @Column(name = "Status", length = 20, nullable = false)
    50     private String status;
     50    private String reservationStatus;
    5151
    5252    @Column(name = "CheckInTime")
     
    5757    private LocalDateTime checkOutTime;
    5858
    59 //    @ElementCollection
    60 //    @CollectionTable(name = "reservation_preordered_items", joinColumns = @JoinColumn(name = "reservation_id"))
    61 //    @Column(name = "item")
    62 //    private List<String> preOrderedItems = new ArrayList<>();
    63     @OneToMany(mappedBy = "reservation", cascade = CascadeType.ALL, orphanRemoval = true)
     59    @OneToMany(mappedBy = "reservation", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
    6460    private List<PreorderedItem> preOrderedItems = new ArrayList<>();
    6561
     
    7369    @PrePersist
    7470    private void prePersist() {
    75         if (status == null) {
    76             status = "Pending";
     71        if (reservationStatus == null) {
     72            reservationStatus = "Pending";
    7773        }
    7874        if (paymentStatus == null) {
     
    8884        this.partySize = partySize;
    8985        this.specialRequests = specialRequests;
    90         this.status = status;
     86        this.reservationStatus = status;
    9187        this.checkInTime = checkInTime;
    9288        this.checkOutTime = checkOutTime;
     
    105101                ", partySize=" + partySize +
    106102                ", specialRequests='" + specialRequests + '\'' +
    107                 ", status='" + status + '\'' +
     103                ", status='" + reservationStatus + '\'' +
    108104                ", checkInTime=" + checkInTime +
    109105                ", checkOutTime=" + checkOutTime +
  • src/main/java/com/example/rezevirajmasa/demo/model/Restaurant.java

    r142c0f8 rb67dfd3  
    146146        @Id
    147147        @GeneratedValue(strategy = GenerationType.IDENTITY)
    148         private Long id;
     148        private Long reservationHistoryId;
    149149
    150150        @ManyToOne
     
    170170
    171171        @Column(name = "status")
    172         private String status;
     172        private String reservationStatus;
    173173
    174174        @Column(name = "cancellation_reason")
     
    185185            this.partySize = partySize;
    186186            this.specialRequests = specialRequests;
    187             this.status = status;
     187            this.reservationStatus = status;
    188188            this.cancellationReason = cancellationReason;
    189189            this.checkInDate = checkInDate;
     
    194194
    195195        public Long getId() {
    196             return id;
     196            return reservationHistoryId;
    197197        }
    198198
    199199        public void setId(Long id) {
    200             this.id = id;
     200            this.reservationHistoryId = id;
    201201        }
    202202
     
    242242
    243243        public String getStatus() {
    244             return status;
     244            return reservationStatus;
    245245        }
    246246
    247247        public void setStatus(String status) {
    248             this.status = status;
     248            this.reservationStatus = status;
    249249        }
    250250
     
    276276        public String toString() {
    277277            return "ReservationHistory{" +
    278                     "id=" + id +
     278                    "id=" + reservationHistoryId +
    279279                    ", user=" + user +
    280280                    ", table=" + table +
     
    283283                    ", partySize=" + partySize +
    284284                    ", specialRequests='" + specialRequests + '\'' +
    285                     ", status='" + status + '\'' +
     285                    ", status='" + reservationStatus + '\'' +
    286286                    ", cancellationReason='" + cancellationReason + '\'' +
    287287                    ", checkInDate=" + checkInDate +
  • src/main/java/com/example/rezevirajmasa/demo/model/TableEntity.java

    r142c0f8 rb67dfd3  
    3636    private int capacity;
    3737
    38     @Column(name = "Location")
    39     private String location;
     38    @Column(name = "tableLocation")
     39    private String tableLocation;
    4040
    4141    @Column(name = "IsSmokingArea")
     
    9595        this.restaurant = restaurant;
    9696        this.capacity = capacity;
    97         this.location = location;
     97        this.tableLocation = location;
    9898        this.isSmokingArea = isSmokingArea;
    9999        this.description = description;
  • src/main/java/com/example/rezevirajmasa/demo/model/User.java

    r142c0f8 rb67dfd3  
    2121    @Id
    2222    @GeneratedValue(strategy = GenerationType.IDENTITY)
    23     private Long id;
     23    private Long userId;
    2424
    2525    @Column(name = "first_name")
  • src/main/java/com/example/rezevirajmasa/demo/repository/ReservationHistoryRepository.java

    r142c0f8 rb67dfd3  
    11package com.example.rezevirajmasa.demo.repository;
    22
    3 import com.example.rezevirajmasa.demo.model.Customer;
    4 import com.example.rezevirajmasa.demo.model.Reservation;
    53import com.example.rezevirajmasa.demo.model.Restaurant;
    64import com.example.rezevirajmasa.demo.model.User;
    7 import org.springframework.cglib.core.Local;
    85import org.springframework.data.jpa.repository.JpaRepository;
    96
     
    1310public interface ReservationHistoryRepository extends JpaRepository<Restaurant.ReservationHistory, Long> {
    1411    List<Restaurant.ReservationHistory> findALlByUser(User user);
    15     List<Restaurant.ReservationHistory> findByCheckInDateBeforeAndStatus(LocalDateTime currentTime, String scheduled);
    1612    List<Restaurant.ReservationHistory> findAllByCheckInDateBefore(LocalDateTime currentTime);
    1713}
  • src/main/java/com/example/rezevirajmasa/demo/service/ReservationHistoryService.java

    r142c0f8 rb67dfd3  
    11package com.example.rezevirajmasa.demo.service;
    22
    3 import com.example.rezevirajmasa.demo.model.Customer;
    43import com.example.rezevirajmasa.demo.model.Reservation;
    54import com.example.rezevirajmasa.demo.model.Restaurant;
  • src/main/java/com/example/rezevirajmasa/demo/service/impl/ReservationHistoryServiceImpl.java

    r142c0f8 rb67dfd3  
    11package com.example.rezevirajmasa.demo.service.impl;
    22
    3 import com.example.rezevirajmasa.demo.model.Customer;
    43import com.example.rezevirajmasa.demo.model.Reservation;
    54import com.example.rezevirajmasa.demo.model.Restaurant;
  • src/main/java/com/example/rezevirajmasa/demo/service/impl/ReservationImpl.java

    r142c0f8 rb67dfd3  
    22
    33import com.example.rezevirajmasa.demo.dto.ReservationDTO;
    4 import com.example.rezevirajmasa.demo.dto.RestaurantDTO;
    5 import com.example.rezevirajmasa.demo.dto.UserDto;
    64import com.example.rezevirajmasa.demo.mappers.UserMapper;
    75import com.example.rezevirajmasa.demo.model.*;
    86import com.example.rezevirajmasa.demo.model.exceptions.InvalidReservationException;
    97import com.example.rezevirajmasa.demo.model.exceptions.InvalidReservationIdException;
    10 import com.example.rezevirajmasa.demo.repository.CustomerRepository;
    118import com.example.rezevirajmasa.demo.repository.ReservationRepository;
    12 import com.example.rezevirajmasa.demo.repository.RestaurantRepository;
    139import com.example.rezevirajmasa.demo.repository.TableRepository;
    1410import com.example.rezevirajmasa.demo.service.ReservationHistoryService;
    1511import com.example.rezevirajmasa.demo.service.ReservationService;
    16 import com.example.rezevirajmasa.demo.service.RestaurantService;
    1712import com.example.rezevirajmasa.demo.service.UserService;
    1813import org.springframework.beans.factory.annotation.Autowired;
    19 import org.springframework.cglib.core.Local;
    20 import org.springframework.security.core.Authentication;
    21 import org.springframework.security.core.annotation.AuthenticationPrincipal;
    22 import org.springframework.security.core.context.SecurityContextHolder;
    23 import org.springframework.security.core.userdetails.UserDetails;
    2414import org.springframework.stereotype.Service;
    25 import org.springframework.web.bind.annotation.RequestBody;
    26 
    27 import javax.swing.text.html.Option;
    28 import java.math.BigDecimal;
     15
    2916import java.time.LocalDateTime;
    30 import java.time.LocalTime;
    31 import java.time.format.DateTimeFormatter;
    3217import java.util.ArrayList;
    3318import java.util.List;
     
    9176            reservation.setSpecialRequests(reservationDTO.getSpecialRequests());
    9277            reservation.setPartySize(reservationDTO.getPartySize());
    93             reservation.setStatus(reservationDTO.getStatus() != null ? reservationDTO.getStatus() : "Pending");
     78            reservation.setReservationStatus(reservationDTO.getStatus() != null ? reservationDTO.getStatus() : "Pending");
    9479            reservation.setPaymentStatus(reservationDTO.getPaymentStatus() != null ? reservationDTO.getPaymentStatus() : "Unpaid");
    9580            reservation.setUser(user);
     
    9984            for (PreorderedItem dtoItem : reservationDTO.getPreOrderedItems()) {
    10085                PreorderedItem item = new PreorderedItem();
    101                 item.setName(dtoItem.getName());
     86                item.setPreorderedItemName(dtoItem.getPreorderedItemName());
    10287                item.setQuantity(dtoItem.getQuantity());
    10388                item.setPrice(dtoItem.getPrice());
     
    144129        existingReservation.setPartySize(reservationDTO.getPartySize());
    145130        existingReservation.setSpecialRequests(reservationDTO.getSpecialRequests());
    146         existingReservation.setStatus(reservationDTO.getStatus() != null ? reservationDTO.getStatus() : existingReservation.getStatus());
     131        existingReservation.setReservationStatus(reservationDTO.getStatus() != null ? reservationDTO.getStatus() : existingReservation.getReservationStatus());
    147132        existingReservation.setPaymentStatus(reservationDTO.getPaymentStatus() != null ? reservationDTO.getPaymentStatus() : existingReservation.getPaymentStatus());
    148133
  • src/main/java/com/example/rezevirajmasa/demo/service/impl/RestaurantServiceImpl.java

    r142c0f8 rb67dfd3  
    104104                TableEntity table = new TableEntity();
    105105                table.setCapacity(tableCapacities.get(i));
    106                 table.setLocation(tableLocations.get(i));
     106                table.setTableLocation(tableLocations.get(i));
    107107                table.setSmokingArea(tableSmokingAreas.get(i).equalsIgnoreCase("on"));
    108108                table.setDescription(tableDescriptions.get(i));
  • src/main/java/com/example/rezevirajmasa/demo/service/impl/TableServiceImpl.java

    r142c0f8 rb67dfd3  
    7676            TableEntity table = new TableEntity();
    7777            table.setCapacity(tableCapacities.get(i));
    78             table.setLocation(tableLocations.get(i));
     78            table.setTableLocation(tableLocations.get(i));
    7979            table.setSmokingArea(Boolean.valueOf(tableSmokingAreas.get(i)));
    8080            table.setDescription(tableDescriptions.get(i));
  • src/main/java/com/example/rezevirajmasa/demo/service/impl/UserServiceImpl.java

    r142c0f8 rb67dfd3  
    1616import org.openqa.selenium.InvalidArgumentException;
    1717import org.springframework.http.HttpStatus;
     18import org.springframework.security.core.userdetails.UserDetails;
     19import org.springframework.security.core.userdetails.UserDetailsService;
     20import org.springframework.security.core.userdetails.UsernameNotFoundException;
    1821import org.springframework.security.crypto.password.PasswordEncoder;
    1922import org.springframework.stereotype.Service;
     
    2528@RequiredArgsConstructor
    2629@Service
    27 public class UserServiceImpl implements UserService {
     30public class UserServiceImpl implements UserService, UserDetailsService {
    2831    private final UserRepository userRepository;
    2932    private final UserMapperImpl userMapper;
     
    7881        return userRepository.findById(userId).orElseThrow(()->new InvalidArgumentException("Invalid user Id"));
    7982    }
     83
     84    @Override
     85    public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {
     86        User user = userRepository.findByEmail(email)
     87                .orElseThrow(()-> new UsernameNotFoundException("User not found"));
     88        return org.springframework.security.core.userdetails.User
     89                .withUsername(user.getEmail())
     90                .password(user.getPassword())
     91                .authorities(user.getRole().name()) // adjust if needed
     92                .build();
     93    }
    8094}
  • src/main/java/com/example/rezevirajmasa/demo/web/controller/ReservationHistoryController.java

    r142c0f8 rb67dfd3  
    44import com.example.rezevirajmasa.demo.dto.UserDto;
    55import com.example.rezevirajmasa.demo.mappers.UserMapper;
    6 import com.example.rezevirajmasa.demo.model.Customer;
    76import com.example.rezevirajmasa.demo.model.Restaurant;
    8 import com.example.rezevirajmasa.demo.model.Role;
    97import com.example.rezevirajmasa.demo.model.User;
    10 import com.example.rezevirajmasa.demo.service.CustomerService;
    118import com.example.rezevirajmasa.demo.service.ReservationHistoryService;
    129import com.example.rezevirajmasa.demo.service.UserService;
  • src/main/java/com/example/rezevirajmasa/demo/web/rest/AuthController.java

    r142c0f8 rb67dfd3  
    55import com.example.rezevirajmasa.demo.dto.SignUpDto;
    66import com.example.rezevirajmasa.demo.dto.UserDto;
    7 import com.example.rezevirajmasa.demo.model.Customer;
    8 import com.example.rezevirajmasa.demo.service.CustomerService;
    97import com.example.rezevirajmasa.demo.service.UserService;
    108import lombok.RequiredArgsConstructor;
    11 import org.apache.coyote.Response;
    12 import org.springframework.beans.factory.annotation.Autowired;
    13 import org.springframework.http.HttpStatus;
    149import org.springframework.http.ResponseEntity;
    15 import org.springframework.security.authentication.AuthenticationManager;
    16 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
    17 import org.springframework.security.core.Authentication;
    18 import org.springframework.security.crypto.password.PasswordEncoder;
    19 import org.springframework.web.bind.annotation.CrossOrigin;
    2010import org.springframework.web.bind.annotation.PostMapping;
    2111import org.springframework.web.bind.annotation.RequestBody;
  • src/main/java/com/example/rezevirajmasa/demo/web/rest/testController.java

    r142c0f8 rb67dfd3  
    3232public class testController {
    3333    private final RestaurantService restaurantService;
    34     private final CustomerService customerService;
    3534    private final UserService userService;
    3635    private final ReservationService reservationService;
     
    4039    private final UserMapper userMapper;
    4140    private final TokenService tokenService;
    42     public testController(RestaurantService restaurantService, CustomerService customerService, UserService userService, ReservationService reservationService, ReservationHistoryService reservationHistoryService, TableService tableService, MenuService menuService, UserMapper userMapper, TokenService tokenService) {
     41    public testController(RestaurantService restaurantService, UserService userService, ReservationService reservationService, ReservationHistoryService reservationHistoryService, TableService tableService, MenuService menuService, UserMapper userMapper, TokenService tokenService) {
    4342        this.restaurantService = restaurantService;
    44         this.customerService = customerService;
    4543        this.userService = userService;
    4644        this.reservationService = reservationService;
     
    115113    }
    116114
    117 //    Customer CALLS
    118 
    119     @GetMapping("/api/customers")
    120     public ResponseEntity<List<CustomerDTO>> getAllCustomers() {
    121         List<Customer> customers = customerService.listAll();
    122         List<CustomerDTO> dtos = new ArrayList<>();
    123         for(Customer customer : customers) {
    124             CustomerDTO dto = customerService.mapCustomerToDTO(customer);
    125             dtos.add(dto);
    126         }
    127         return new ResponseEntity<List<CustomerDTO>>(dtos, HttpStatus.OK);
    128     }
    129 
    130     @GetMapping("/api/customers/{id}")
    131     public ResponseEntity<Customer> getCustomerById(@PathVariable Long id) {
    132         return new ResponseEntity<Customer>(customerService.findById(id), HttpStatus.OK);
    133     }
    134     @PutMapping("/api/customers/edit/{id}")
    135     public ResponseEntity<Customer> editCustomerById(@PathVariable Long id, @RequestBody Customer customer) {
    136         return new ResponseEntity<Customer>(
    137                 customerService.updateCustomer(id, customer.getFirstName(), customer.getLastName(), customer.getEmail(), customer.getPassword(), customer.getPhone(), customer.getAddress(), customer.getMembershipLevel()),
    138                 HttpStatus.OK
    139         );
    140     }
    141 
    142     @PostMapping("/api/customers")
    143     public ResponseEntity<Customer> saveCustomer(@RequestBody Customer customer) {
    144         // Ensure that the role is set to ROLE_USER by default
    145         customer.setRole(Role.ROLE_USER);
    146         return new ResponseEntity<Customer>(
    147                 customerService.registration(customer),
    148                 HttpStatus.OK
    149         );
    150     }
    151 
    152     @DeleteMapping("/api/customers/delete/{customerId}")
    153     public ResponseEntity<Response> deleteCustomer(@PathVariable Long customerId) {
    154         boolean deleted = customerService.deleteById(customerId);
    155         if(deleted) {
    156             return ResponseEntity.ok().build();
    157         } else {
    158             return ResponseEntity.notFound().build();
    159         }
    160     }
    161 
    162115//    Reservation Calls
    163116
  • src/test/java/com/example/rezevirajmasa/demo/CustomerRepositoryTests.java

    r142c0f8 rb67dfd3  
    11package com.example.rezevirajmasa.demo;
    22
    3 import com.example.rezevirajmasa.demo.model.Customer;
    43import com.example.rezevirajmasa.demo.model.MembershipLevel;
    54import com.example.rezevirajmasa.demo.model.exceptions.InvalidCustomerIdException;
    6 import com.example.rezevirajmasa.demo.repository.CustomerRepository;
    75
    86import org.assertj.core.api.Assertions;
  • src/test/java/com/example/rezevirajmasa/demo/TableRepositoryTests.java

    r142c0f8 rb67dfd3  
    2222        tableEntity.setDescription("Romantic spot");
    2323        tableEntity.setSmokingArea(true);
    24         tableEntity.setLocation("Big blue");
     24        tableEntity.setTableLocation("Big blue");
    2525
    2626        TableEntity savedTable = tableRepository.save(tableEntity);
Note: See TracChangeset for help on using the changeset viewer.