Changeset 53765dd


Ignore:
Timestamp:
01/04/24 09:07:47 (11 months ago)
Author:
gjoko kostadinov <gjokokostadinov@…>
Branches:
master
Children:
e8999eb
Parents:
1413ee2
Message:

Fix bugs.

Location:
src/main
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/edu/gjoko/schedlr/config/AppSecurityConfig.java

    r1413ee2 r53765dd  
    6868                .antMatchers("/register_customer").permitAll()
    6969                .antMatchers("/register_business").permitAll()
    70                 .antMatchers("/api/nomenclatures/*").permitAll()
     70                .antMatchers("/api/nomenclature/*").permitAll()
    7171                .antMatchers("/api/user/me").permitAll()
    7272                .antMatchers("/api/business").permitAll()
  • src/main/java/edu/gjoko/schedlr/controllers/LoginController.java

    r1413ee2 r53765dd  
    2222    @PostMapping(path = "/login")
    2323    public String loginCustomer(@ModelAttribute Stakeholder customer, Model model) {
    24         return "redirect:homepage";
     24        return "redirect:login";
    2525    }
    2626}
  • src/main/java/edu/gjoko/schedlr/controllers/rest/NomenclatureApi.java

    r1413ee2 r53765dd  
    22
    33import edu.gjoko.schedlr.entity.BusinessType;
     4import edu.gjoko.schedlr.entity.ServiceType;
    45import edu.gjoko.schedlr.services.NomenclaturesService;
    56import lombok.AllArgsConstructor;
    67import org.springframework.web.bind.annotation.GetMapping;
     8import org.springframework.web.bind.annotation.PathVariable;
    79import org.springframework.web.bind.annotation.RequestMapping;
    810import org.springframework.web.bind.annotation.RestController;
    911
     12import javax.servlet.http.HttpServletRequest;
    1013import java.util.List;
    1114
    1215@RestController
    13 @RequestMapping("api/nomenclatures")
     16@RequestMapping("api/nomenclature")
    1417@AllArgsConstructor
    1518public class NomenclatureApi {
     
    2023        return nomenclaturesService.getBusinessTypes();
    2124    }
     25
     26    @GetMapping( "/serviceTypes/me")
     27    public List<ServiceType> getServiceTypesForBusinessType( HttpServletRequest request) {
     28        Long ownerId = (long) request.getSession(true).getAttribute("stakeholderId");
     29        return nomenclaturesService.findAppropriateBusinessTypesForBusinessByOwnerId(ownerId);
     30    }
    2231}
  • src/main/java/edu/gjoko/schedlr/entity/Service.java

    r1413ee2 r53765dd  
    5656    @Column(name = "service_status")
    5757    @Enumerated(EnumType.STRING)
    58     private ServiceStatus serviceStatus;
     58    private ServiceStatus serviceStatus = ServiceStatus.ACTIVE;
    5959
    6060    @Column(name = "created")
  • src/main/java/edu/gjoko/schedlr/repositories/ServiceTypeRepository.java

    r1413ee2 r53765dd  
    11package edu.gjoko.schedlr.repositories;
    22
    3 import edu.gjoko.schedlr.entity.BusinessType;
     3import edu.gjoko.schedlr.entity.Service;
    44import edu.gjoko.schedlr.entity.ServiceType;
    55import org.springframework.data.jpa.repository.JpaRepository;
    6 import org.springframework.data.jpa.repository.Modifying;
    76import org.springframework.data.jpa.repository.Query;
    87import org.springframework.stereotype.Repository;
    98
     9import java.util.List;
     10
    1011@Repository
    1112public interface ServiceTypeRepository extends JpaRepository<ServiceType, Long> {
     13
     14    List<ServiceType> findAllByBusinessType_Id(Long businessTypeId);
     15
     16    @Query(value = "select b.businessType.serviceTypes from Business as b " +
     17            " where b.owner.id = :ownerId")
     18    List<ServiceType> findAppropriateBusinessTypesForBusinessByOwnerId(Long ownerId);
    1219}
  • src/main/java/edu/gjoko/schedlr/services/NomenclaturesService.java

    r1413ee2 r53765dd  
    22
    33import edu.gjoko.schedlr.entity.BusinessType;
     4import edu.gjoko.schedlr.entity.ServiceType;
    45import edu.gjoko.schedlr.repositories.BusinessTypeRepository;
    56import edu.gjoko.schedlr.repositories.ServiceTypeRepository;
     
    2021        return businessTypeRepository.findAll();
    2122    }
     23
     24    public List<ServiceType> findAppropriateBusinessTypesForBusinessByOwnerId(Long ownerId) {
     25        return serviceTypeRepository.findAppropriateBusinessTypesForBusinessByOwnerId(ownerId);
     26    }
    2227}
  • src/main/resources/data.sql

    r1413ee2 r53765dd  
    1313       (nextval('hibernate_sequence'), current_timestamp, current_timestamp, 'waxing', 6),
    1414       (nextval('hibernate_sequence'), current_timestamp, current_timestamp, 'nail extensions', 2),
    15        (nextval('hibernate_sequence'), current_timestamp, current_timestamp, 'dress shortening', 1),
    16        (nextval('hibernate_sequence'), current_timestamp, current_timestamp, 'holes fixing', 1);
     15       (nextval('hibernate_sequence'), current_timestamp, current_timestamp, 'dress sewing', 1),
     16       (nextval('hibernate_sequence'), current_timestamp, current_timestamp, 'pants shortening', 1);
    1717
    1818insert into stakeholder (id, created, phone_number, email, first_name, last_name, modified, password, stakeholder_type, username)
  • src/main/resources/static/js/business_admin.js

    r1413ee2 r53765dd  
    11$(document).ready(function() {
    22    var business = {};
    3 
    4     getBusinessInfo().then(function (data) {
    5         business = data;
    6     });
     3    var serviceTypeList = {};
     4
     5    getServiceTypes().then(function (serviceTypes) {
     6        serviceTypeList = serviceTypes;
     7        getBusinessInfo(serviceTypes).then(function (data) {
     8            business = data;
     9        });
     10    });
     11
     12
    713
    814    getAppointments();
     
    7177
    7278        updateServices(servicesObj).then(function (response) {
    73             getBusinessInfo().then(function (data) {
     79            getBusinessInfo(serviceTypeList).then(function (data) {
    7480                business = data;
    7581            });
     
    7884        if (servicesForDelete.length > 0) {
    7985            deleteServices(servicesForDelete).then(function (response) {
    80                 getBusinessInfo().then(function (data) {
     86                getBusinessInfo(serviceTypeList).then(function (data) {
    8187                    business = data;
    8288                });
     
    101107
    102108        updateBusinessInfo(businesses).then(function() {
    103             getBusinessInfo().then(function (found) {
     109            getBusinessInfo(serviceTypeList).then(function (found) {
    104110                business = found;
    105111            });
     
    205211}
    206212
    207 function getBusinessInfo() {
     213function getServiceTypes() {
     214    return $.ajax({
     215        url: "http://localhost:8080/api/nomenclature/serviceTypes/me"
     216    }).then(function (serviceTypes) {
     217        return serviceTypes;
     218    });
     219}
     220
     221function getBusinessInfo(serviceTypeList) {
    208222    return $.ajax({
    209223        url: "http://localhost:8080/api/business/me"
     
    231245        var $el = $("#predefined_services_admin_panel");
    232246        $el.empty();
     247        const existingServiceTypeIds = business['services'].map(service => service['serviceType']['id']);
     248        const missingAddedServiceTypes = serviceTypeList.filter(serviceType => existingServiceTypeIds.indexOf(serviceType['id']) === -1);
     249        //console.log(missingAddedServiceTypes);
    233250
    234251        $.each(business['services'], function (index, obj) {
  • src/main/resources/static/js/customer_admin.js

    r1413ee2 r53765dd  
    11$(document).ready(function() {
    2 
    3     getCustomerInfo();
     2    var customer = {};
     3
     4    getCustomerInfo().then(function (customerData) {
     5        customer = customerData;
     6    });
    47
    58    getFutureAppointments();
     
    7073
    7174function getCustomerInfo() {
    72     $.ajax({
     75    return $.ajax({
    7376        url: "http://localhost:8080/api/customer/me"
    7477    }).success(function (customer) {
     
    8285        $('#email').val(customer['email']);
    8386        $('#username').val(customer['username']);
     87        return customer;
    8488    }).error(function (error) {
    8589        console.log(JSON.stringify(error));
  • src/main/resources/static/js/homepage.js

    r1413ee2 r53765dd  
    5959
    6060    $.ajax({
    61         url: "http://localhost:8080/api/nomenclatures/businessTypes"
     61        url: "http://localhost:8080/api/nomenclature/businessTypes"
    6262    }).then(function (data) {
    6363        businessTypes = data;
     
    338338    }).then(function (data) {
    339339        var $el = $("#reviewsModalBody");
    340         $('#reviews-ul').append($('<td class="form-outline mb-4"><button type="button" id="reviews-li" class="btn btn-primary btn-block" data-bs-toggle="modal" data-bs-target="#showReviewsModal">Checkout reviews</button></td>'));
     340        $('#reviews-ul').append($('<button type="button" id="reviews-li" class="btn btn-primary btn-block" data-bs-toggle="modal" data-bs-target="#showReviewsModal">Checkout reviews</button>'));
    341341        $el.empty();
    342342
  • src/main/resources/static/js/register_business.js

    r1413ee2 r53765dd  
    22    var enumerations = {};
    33    $.ajax({
    4         url: "http://localhost:8080/api/nomenclatures/businessTypes"
     4        url: "http://localhost:8080/api/nomenclature/businessTypes"
    55    }).then(function (data) {
    66        enumerations = data;
    77        var $el = $("#companyType");
    8         //$el.empty(); // remove old options
    98
    109        $.each(data, function (index, obj) {
     
    103102        });
    104103        businessObj['services'] = servicesObj;
    105         console.log(businessObj);
    106104        $.ajax({
    107105            url: "http://localhost:8080/api/business",
     
    113111                alert( "Well done! You have finished the registration process. " +
    114112                    "Please check periodically to see if the company has been approved." );
    115                 window.location.href = "/homepage";
     113                window.location.href = "/login";
    116114            },
    117115            error: function(err) {
Note: See TracChangeset for help on using the changeset viewer.