Ignore:
Timestamp:
03/13/23 00:58:07 (21 months ago)
Author:
Gjoko Kostadinov <gjoko.kostadinov@…>
Branches:
master
Children:
9050790
Parents:
2b0a4db
Message:

Add admin page initial work.

Location:
src/main/java/edu/gjoko/schedlr
Files:
5 added
9 edited

Legend:

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

    r2b0a4db r46fd0c7  
    44import org.springframework.security.core.context.SecurityContextImpl;
    55import org.springframework.security.core.userdetails.UserDetails;
     6import org.springframework.util.StringUtils;
    67import org.springframework.web.filter.GenericFilterBean;
    78
     
    2324        HttpSession session = httpServletRequest.getSession(false);
    2425
     26        if(httpServletRequest.getRequestURI().endsWith(".js") || httpServletRequest.getRequestURI().endsWith(".css")) {
     27            filterChain.doFilter(servletRequest, servletResponse);
     28            return;
     29        }
    2530        if(session != null) {
    2631            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");
    3035            SecurityContextImpl sci = (SecurityContextImpl) session.getAttribute("SPRING_SECURITY_CONTEXT");
    3136            if(sci != null) {
     
    3439                for (final GrantedAuthority grantedAuthority : authorities) {
    3540                    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);
    4655                        return;
    4756                    }
  • src/main/java/edu/gjoko/schedlr/config/AppSecurityConfig.java

    r2b0a4db r46fd0c7  
    6060                .antMatchers("/register_business").permitAll()
    6161                .antMatchers("/api/nomenclatures/*").permitAll()
     62                .antMatchers("/api/business").permitAll()
    6263                .antMatchers("/homepage").permitAll()
    6364                .antMatchers("/css/**").permitAll()
  • src/main/java/edu/gjoko/schedlr/config/MvcConfig.java

    r2b0a4db r46fd0c7  
    22
    33import org.springframework.context.annotation.Configuration;
     4import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
    45import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
    56import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
     
    1415        registry.addViewController("/register_business").setViewName("register_business");
    1516        registry.addViewController("/homepage").setViewName("homepage");
     17        registry.addViewController("/admin").setViewName("admin");
    1618    }
    1719
    18 
     20    @Override
     21    public void addResourceHandlers(ResourceHandlerRegistry registry) {
     22        registry.addResourceHandler("/resources/**")
     23                .addResourceLocations("/resources/");
     24    }
    1925}
  • src/main/java/edu/gjoko/schedlr/controllers/HomePageController.java

    r2b0a4db r46fd0c7  
    1111public class HomePageController {
    1212
    13     @GetMapping(name = "/homepage")
     13    @GetMapping(path = "/homepage")
    1414    public String getHomePageTemplate(Model model, Principal principal) {
    1515        System.out.println(principal);
     
    1717    }
    1818
    19     @PostMapping(name = "/homepage")
     19    @PostMapping(path = "/homepage")
    2020    public String postHomePageTemplate(Model model) {
    2121        return "homepage";
  • src/main/java/edu/gjoko/schedlr/controllers/RegisterController.java

    r2b0a4db r46fd0c7  
    2020    }
    2121
    22     @GetMapping(value ="/register_customer")
     22    @GetMapping(path ="/register_customer")
    2323    public String getCustomerRegisterPage(Model model) {
    2424        model.addAttribute("stakeholder", new Stakeholder());
     
    2626    }
    2727
    28     @PostMapping(value = "/register_customer")
     28    @PostMapping(path = "/register_customer")
    2929    public String registerCustomer(@ModelAttribute Stakeholder customer, Model model) {
    3030        Stakeholder user = stakeholderService.saveStakeholder(customer);
     
    3232    }
    3333
    34     @GetMapping(value = "/register_business")
     34    @GetMapping(path = "/register_business")
    3535    public String getBusinessRegisterPage(Model model) {
    3636        return "register_business";
     
    3939    @PostMapping(value = "/register_business")
    4040    public String registerBusiness(Model model) {
    41         return "register_business";
     41        return "redirect:login";
    4242    }
    4343}
  • src/main/java/edu/gjoko/schedlr/entity/Appointment.java

    r2b0a4db r46fd0c7  
    55import lombok.NoArgsConstructor;
    66import lombok.Setter;
     7import org.springframework.data.annotation.LastModifiedDate;
     8import org.springframework.data.jpa.domain.support.AuditingEntityListener;
    79
    810import javax.persistence.*;
     
    1012
    1113@Entity
     14@EntityListeners(AuditingEntityListener.class)
    1215@Table(name = "appointment")
    1316@Getter
     
    3134
    3235    @Column(name = "created")
     36    @LastModifiedDate
    3337    private LocalDateTime created;
    3438
    3539    @Column(name = "modified")
     40    @LastModifiedDate
    3641    private LocalDateTime modified;
    3742}
  • src/main/java/edu/gjoko/schedlr/entity/Business.java

    r2b0a4db r46fd0c7  
    22
    33import com.fasterxml.jackson.annotation.JsonManagedReference;
     4import com.fasterxml.jackson.annotation.JsonProperty;
    45import lombok.AllArgsConstructor;
    56import lombok.Getter;
    67import lombok.NoArgsConstructor;
    78import lombok.Setter;
     9import org.springframework.data.annotation.CreatedDate;
     10import org.springframework.data.annotation.LastModifiedDate;
     11import org.springframework.data.jpa.domain.support.AuditingEntityListener;
    812
    913import javax.persistence.*;
     
    1216
    1317@Entity
     18@EntityListeners(AuditingEntityListener.class)
    1419@Table(name = "business")
    1520@Getter
     
    2328    private Long id;
    2429
    25     @Column(name = "name")
    26     private String name;
     30    @Column(name = "company_name")
     31    private String companyName;
    2732
    2833    @OneToOne
    2934    @JoinColumn(name = "business_type_id", referencedColumnName = "id")
     35    @JsonProperty("businessType")
    3036    private BusinessType businessType;
    3137
    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)
    3939    @JoinColumn(name = "owner_id", referencedColumnName = "id", nullable = false)
     40    @JsonProperty("owner")
    4041    private Stakeholder owner;
    4142
    42     @OneToMany(mappedBy = "business")
     43    @OneToMany(mappedBy = "business", cascade = CascadeType.PERSIST)
    4344    @JsonManagedReference
    4445    private List<Service> services;
    4546
     47    @Column(name = "business_status")
     48    @Enumerated(EnumType.STRING)
     49    private BusinessStatus businessStatus;
     50
    4651    @Column(name = "created")
     52    @CreatedDate
    4753    private LocalDateTime created;
    4854
    4955    @Column(name = "modified")
     56    @LastModifiedDate
    5057    private LocalDateTime modified;
    5158
  • src/main/java/edu/gjoko/schedlr/entity/Service.java

    r2b0a4db r46fd0c7  
    1111
    1212import javax.persistence.*;
    13 import java.sql.Timestamp;
    1413import java.time.LocalDateTime;
    1514
     
    2726    private Long id;
    2827
    29     @Column(name = "name")
    30     private String name;
    31 
    3228    @Column(name = "duration")
    3329    private Integer duration;
    3430
    35     @Column(name = "price")
    36     private Float price;
    37 
    38     @OneToOne
     31    @OneToOne(cascade = CascadeType.MERGE)
    3932    @JoinColumn(name = "service_type_id", referencedColumnName = "id")
    4033    private ServiceType serviceType;
    4134
    4235    @ManyToOne
    43     @JoinColumn(name="business_fk")
     36    @JoinColumn(name = "business_fk")
    4437    @JsonBackReference
    4538    private Business business;
  • src/main/java/edu/gjoko/schedlr/repositories/BusinessTypeRepository.java

    r2b0a4db r46fd0c7  
    22
    33import edu.gjoko.schedlr.entity.BusinessType;
    4 import edu.gjoko.schedlr.entity.Stakeholder;
    54import org.springframework.data.jpa.repository.JpaRepository;
    65import org.springframework.stereotype.Repository;
Note: See TracChangeset for help on using the changeset viewer.