- Timestamp:
- 03/13/23 00:58:07 (20 months ago)
- Branches:
- master
- Children:
- 9050790
- Parents:
- 2b0a4db
- Location:
- src/main
- Files:
-
- 7 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/edu/gjoko/schedlr/config/AppFilter.java
r2b0a4db r46fd0c7 4 4 import org.springframework.security.core.context.SecurityContextImpl; 5 5 import org.springframework.security.core.userdetails.UserDetails; 6 import org.springframework.util.StringUtils; 6 7 import org.springframework.web.filter.GenericFilterBean; 7 8 … … 23 24 HttpSession session = httpServletRequest.getSession(false); 24 25 26 if(httpServletRequest.getRequestURI().endsWith(".js") || httpServletRequest.getRequestURI().endsWith(".css")) { 27 filterChain.doFilter(servletRequest, servletResponse); 28 return; 29 } 25 30 if(session != null) { 26 31 Map<String, String> roleTargetUrlMap = new HashMap<>(); 27 roleTargetUrlMap.put("ADMIN", "/ date");28 roleTargetUrlMap.put("CUSTOMER", "/ number");29 roleTargetUrlMap.put("BUSINESS_OWNER", " ");32 roleTargetUrlMap.put("ADMIN", "/admin"); 33 roleTargetUrlMap.put("CUSTOMER", "/homepage"); 34 roleTargetUrlMap.put("BUSINESS_OWNER", "/business_homepage"); 30 35 SecurityContextImpl sci = (SecurityContextImpl) session.getAttribute("SPRING_SECURITY_CONTEXT"); 31 36 if(sci != null) { … … 34 39 for (final GrantedAuthority grantedAuthority : authorities) { 35 40 String authorityName = grantedAuthority.getAuthority(); 36 if("DATE".equalsIgnoreCase(authorityName)) { 37 servletRequest.getRequestDispatcher("date").forward(servletRequest, servletResponse); 38 return; 39 } else if("GUESS_NUMBER".equalsIgnoreCase(authorityName)) { 40 try { 41 servletRequest.getRequestDispatcher("number").forward(servletRequest, servletResponse); 42 } catch (Exception e) { 43 e.printStackTrace(); 44 } 45 41 String page = ""; 42 switch (authorityName) { 43 case "ADMIN": 44 page = "/admin"; 45 break; 46 case "CUSTOMER": 47 case "BUSINESS_OWNER": 48 page = "/homepage"; 49 break; 50 default: 51 break; 52 } 53 if(page != null && !page.trim().isEmpty()) { 54 servletRequest.getRequestDispatcher(page).forward(servletRequest, servletResponse); 46 55 return; 47 56 } -
src/main/java/edu/gjoko/schedlr/config/AppSecurityConfig.java
r2b0a4db r46fd0c7 60 60 .antMatchers("/register_business").permitAll() 61 61 .antMatchers("/api/nomenclatures/*").permitAll() 62 .antMatchers("/api/business").permitAll() 62 63 .antMatchers("/homepage").permitAll() 63 64 .antMatchers("/css/**").permitAll() -
src/main/java/edu/gjoko/schedlr/config/MvcConfig.java
r2b0a4db r46fd0c7 2 2 3 3 import org.springframework.context.annotation.Configuration; 4 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 4 5 import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; 5 6 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; … … 14 15 registry.addViewController("/register_business").setViewName("register_business"); 15 16 registry.addViewController("/homepage").setViewName("homepage"); 17 registry.addViewController("/admin").setViewName("admin"); 16 18 } 17 19 18 20 @Override 21 public void addResourceHandlers(ResourceHandlerRegistry registry) { 22 registry.addResourceHandler("/resources/**") 23 .addResourceLocations("/resources/"); 24 } 19 25 } -
src/main/java/edu/gjoko/schedlr/controllers/HomePageController.java
r2b0a4db r46fd0c7 11 11 public class HomePageController { 12 12 13 @GetMapping( name= "/homepage")13 @GetMapping(path = "/homepage") 14 14 public String getHomePageTemplate(Model model, Principal principal) { 15 15 System.out.println(principal); … … 17 17 } 18 18 19 @PostMapping( name= "/homepage")19 @PostMapping(path = "/homepage") 20 20 public String postHomePageTemplate(Model model) { 21 21 return "homepage"; -
src/main/java/edu/gjoko/schedlr/controllers/RegisterController.java
r2b0a4db r46fd0c7 20 20 } 21 21 22 @GetMapping( value="/register_customer")22 @GetMapping(path ="/register_customer") 23 23 public String getCustomerRegisterPage(Model model) { 24 24 model.addAttribute("stakeholder", new Stakeholder()); … … 26 26 } 27 27 28 @PostMapping( value= "/register_customer")28 @PostMapping(path = "/register_customer") 29 29 public String registerCustomer(@ModelAttribute Stakeholder customer, Model model) { 30 30 Stakeholder user = stakeholderService.saveStakeholder(customer); … … 32 32 } 33 33 34 @GetMapping( value= "/register_business")34 @GetMapping(path = "/register_business") 35 35 public String getBusinessRegisterPage(Model model) { 36 36 return "register_business"; … … 39 39 @PostMapping(value = "/register_business") 40 40 public String registerBusiness(Model model) { 41 return "re gister_business";41 return "redirect:login"; 42 42 } 43 43 } -
src/main/java/edu/gjoko/schedlr/entity/Appointment.java
r2b0a4db r46fd0c7 5 5 import lombok.NoArgsConstructor; 6 6 import lombok.Setter; 7 import org.springframework.data.annotation.LastModifiedDate; 8 import org.springframework.data.jpa.domain.support.AuditingEntityListener; 7 9 8 10 import javax.persistence.*; … … 10 12 11 13 @Entity 14 @EntityListeners(AuditingEntityListener.class) 12 15 @Table(name = "appointment") 13 16 @Getter … … 31 34 32 35 @Column(name = "created") 36 @LastModifiedDate 33 37 private LocalDateTime created; 34 38 35 39 @Column(name = "modified") 40 @LastModifiedDate 36 41 private LocalDateTime modified; 37 42 } -
src/main/java/edu/gjoko/schedlr/entity/Business.java
r2b0a4db r46fd0c7 2 2 3 3 import com.fasterxml.jackson.annotation.JsonManagedReference; 4 import com.fasterxml.jackson.annotation.JsonProperty; 4 5 import lombok.AllArgsConstructor; 5 6 import lombok.Getter; 6 7 import lombok.NoArgsConstructor; 7 8 import lombok.Setter; 9 import org.springframework.data.annotation.CreatedDate; 10 import org.springframework.data.annotation.LastModifiedDate; 11 import org.springframework.data.jpa.domain.support.AuditingEntityListener; 8 12 9 13 import javax.persistence.*; … … 12 16 13 17 @Entity 18 @EntityListeners(AuditingEntityListener.class) 14 19 @Table(name = "business") 15 20 @Getter … … 23 28 private Long id; 24 29 25 @Column(name = " name")26 private String name;30 @Column(name = "company_name") 31 private String companyName; 27 32 28 33 @OneToOne 29 34 @JoinColumn(name = "business_type_id", referencedColumnName = "id") 35 @JsonProperty("businessType") 30 36 private BusinessType businessType; 31 37 32 @Column(name = "opening_time") 33 private LocalDateTime openingTime; 34 35 @Column(name = "closing_time") 36 private LocalDateTime closingTime; 37 38 @ManyToOne 38 @ManyToOne(cascade = CascadeType.PERSIST) 39 39 @JoinColumn(name = "owner_id", referencedColumnName = "id", nullable = false) 40 @JsonProperty("owner") 40 41 private Stakeholder owner; 41 42 42 @OneToMany(mappedBy = "business" )43 @OneToMany(mappedBy = "business", cascade = CascadeType.PERSIST) 43 44 @JsonManagedReference 44 45 private List<Service> services; 45 46 47 @Column(name = "business_status") 48 @Enumerated(EnumType.STRING) 49 private BusinessStatus businessStatus; 50 46 51 @Column(name = "created") 52 @CreatedDate 47 53 private LocalDateTime created; 48 54 49 55 @Column(name = "modified") 56 @LastModifiedDate 50 57 private LocalDateTime modified; 51 58 -
src/main/java/edu/gjoko/schedlr/entity/Service.java
r2b0a4db r46fd0c7 11 11 12 12 import javax.persistence.*; 13 import java.sql.Timestamp;14 13 import java.time.LocalDateTime; 15 14 … … 27 26 private Long id; 28 27 29 @Column(name = "name")30 private String name;31 32 28 @Column(name = "duration") 33 29 private Integer duration; 34 30 35 @Column(name = "price") 36 private Float price; 37 38 @OneToOne 31 @OneToOne(cascade = CascadeType.MERGE) 39 32 @JoinColumn(name = "service_type_id", referencedColumnName = "id") 40 33 private ServiceType serviceType; 41 34 42 35 @ManyToOne 43 @JoinColumn(name ="business_fk")36 @JoinColumn(name = "business_fk") 44 37 @JsonBackReference 45 38 private Business business; -
src/main/java/edu/gjoko/schedlr/repositories/BusinessTypeRepository.java
r2b0a4db r46fd0c7 2 2 3 3 import edu.gjoko.schedlr.entity.BusinessType; 4 import edu.gjoko.schedlr.entity.Stakeholder;5 4 import org.springframework.data.jpa.repository.JpaRepository; 6 5 import org.springframework.stereotype.Repository; -
src/main/resources/static/js/register_business.js
r2b0a4db r46fd0c7 3 3 $.ajax({ 4 4 url: "http://localhost:8080/api/nomenclatures/businessTypes" 5 }).then(function (data) {5 }).then(function (data) { 6 6 enumerations = data; 7 7 var $el = $("#companyType"); 8 8 //$el.empty(); // remove old options 9 9 10 $.each(data, function (index, obj) {10 $.each(data, function (index, obj) { 11 11 $el.append("<option value=" + obj.value + ">" + obj.text + "</option>"); 12 12 }); 13 13 }); 14 14 15 $("#companyType").change(function () {15 $("#companyType").change(function () { 16 16 var selectedVal = $(this).find(':selected').val(); 17 alert(JSON.stringify(enumerations[selectedVal-1])); 18 var selectedObj = enumerations[selectedVal-1]; 17 var selectedObj = enumerations[selectedVal - 1]; 19 18 var $el = $("#predefined_services"); 20 19 $el.empty(); 21 20 $.each(selectedObj['serviceTypes'], function (index, obj) { 22 21 $el.append( 23 '<div class="form-check">\n' + 24 ' <input class="form-check-input" type="checkbox" value=\"' + obj.id + '\" id=\"'+ obj.id +'\">\n' + 25 ' <label class="form-check-label" for=\"' + obj.id + '\">\n' + 26 obj.name + 27 ' </label>\n' + 28 ' </div>') 22 '<div class=\"form-outline mb-4\">' + 23 ' <div class="row">' + 24 ' <div class="col-md-8">\n' + 25 ' <input class="form-check-input" type="checkbox" value=\"' + obj.id + '\" id=\"' + obj.id + '\">\n' + 26 ' <label class="form-check-label" for=\"' + obj.id + '\">\n' + 27 obj.name + 28 ' </label>\n' + 29 ' </div>' + 30 ' <div class=\"form-outline col-md-2 d-grid\">' + 31 ' <input type=\"text\" id=\"' + obj.id + obj.name.replace(/\s/g, "") + '\" class=\"form-control\" />' + 32 ' </div>' + 33 ' </div>' + 34 '</div>'); 29 35 }); 30 }) 36 $("#input_service").prop('disabled', false); 37 $("#add_service").prop('disabled', false); 38 }); 39 40 $("#add_service").click(function () { 41 var input_service = $("#input_service").val(); 42 // clear the input 43 $("#input_service").val(''); 44 45 /*$("#predefined_services").append( 46 '<div class="form-check">\n' + 47 ' <input class="form-check-input" type="checkbox" checked value=\"' + -1 + '\" id=\"'+ -1 +'\">\n' + 48 ' <label class="form-check-label" for=\"' + -1 + '\">\n' + 49 input_service + 50 ' </label>\n' + 51 ' </div>' 52 );*/ 53 54 $("#predefined_services").append( 55 '<div class="form-outline mb-4">' + 56 ' <div class="row">' + 57 ' <div class="col-md-8">\n' + 58 ' <input class="form-check-input" type="checkbox" checked value="' + -1 + '" id="' + -1 + '">\n' + 59 ' <label class="form-check-label" for="' + -1 + '">\n' + 60 input_service + 61 ' </label>\n' + 62 ' </div>' + 63 ' <div class="form-outline col-md-2 d-grid">' + 64 ' <input type="text" id="' + -1 + input_service.replace(/\s/g, "") + '" class="form-control" />' + 65 ' </div>' + 66 ' </div>' + 67 '</div>'); 68 event.preventDefault(); 69 }); 70 71 $('#signup_business_button').click(function () { 72 let businessObj = {}; 73 let ownerObj = {}; 74 75 ownerObj['firstName'] = $('#firstName').val(); 76 ownerObj['lastName'] = $('#lastName').val(); 77 ownerObj['email'] = $('#email').val(); 78 ownerObj['username'] = $('#username').val(); 79 ownerObj['password'] = $('#password').val(); 80 businessObj['owner'] = ownerObj; 81 82 businessObj['companyName'] = $('#companyName').val(); 83 84 businessObj['businessType'] = {'value': $('#companyType').val()}; 85 86 servicesObj = []; 87 88 $.each($('#predefined_services input:checked').siblings(), function(index, label) { 89 90 let service = {}; 91 var id = $(label).prop('for'); 92 var text = $(label).text(); 93 var time = $($($(label).parent()).siblings()[0]).children()[0].value; 94 95 var serviceType = {} 96 if(parseInt(id) != -1) { 97 serviceType['id'] = id; 98 } 99 serviceType['name'] = text.trim(); 100 service['serviceType'] = serviceType; 101 service['duration'] = time; 102 servicesObj.push(service); 103 }); 104 businessObj['services'] = servicesObj; 105 console.log(JSON.stringify(businessObj)); 106 $.ajax({ 107 url: "http://localhost:8080/api/business", 108 type:"POST", 109 data: JSON.stringify(businessObj), 110 contentType:"application/json; charset=utf-8", 111 dataType: 'text', 112 success: function(succ){ 113 alert( "Well done! You have finished the registration process. " + 114 "Please check periodically to see if the company has been approved." ); 115 window.location.href = "/homepage"; 116 }, 117 error: function(err) { 118 alert(err); 119 } 120 }); 121 event.preventDefault(); 122 }); 31 123 }); -
src/main/resources/templates/register_business.html
r2b0a4db r46fd0c7 37 37 <div class="col-md-6 mb-4"> 38 38 <div class="form-outline"> 39 <input type="text" id="firstName" class="form-control" placeholder=" Username"40 aria-label=" Username"/>39 <input type="text" id="firstName" class="form-control" placeholder="First name" 40 aria-label="Firstname"/> 41 41 </div> 42 42 </div> … … 72 72 73 73 <div class="form-outline mb-4"> 74 <input type=" email" id="companyName" class="form-control" placeholder="Company Name"74 <input type="text" id="companyName" class="form-control" placeholder="Company Name" 75 75 aria-label="companyName"/> 76 76 </div> … … 86 86 </div> 87 87 88 <div class="row"> 89 <div class="form-outline col-md-10"> 90 <div class="form-outline"> 91 <input type="text" id="services" class="form-control" placeholder="Services" 92 aria-label="services"/> 88 <div class="form-outline mb-4"> 89 <div class="row"> 90 <div class="col-md-10"> 91 <div class="form-outline"> 92 <input type="text" id="input_service" class="form-control" 93 placeholder="Services" 94 aria-label="services" disabled="true"/> 95 </div> 93 96 </div> 94 </div>95 <div class="form-outline col-md-2 d-grid">96 < button class="btn btn-primary" id="add_service">Add</button>97 <div class="form-outline col-md-2 d-grid"> 98 <button class="btn btn-primary" id="add_service" disabled="true">Add</button> 99 </div> 97 100 </div> 98 101 </div> … … 104 107 105 108 <!-- Submit button --> 106 <button type=" submit" class="btn btn-primary btn-block mb-4">109 <button type="buttom" class="btn btn-primary btn-block mb-4" id="signup_business_button"> 107 110 Sign up 108 111 </button>
Note:
See TracChangeset
for help on using the changeset viewer.