Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prithvi 7 #20

Merged
merged 4 commits into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Backend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<h2>Great man!</h2>

</body>
</html>
2 changes: 2 additions & 0 deletions Backend/src/main/java/com/masai/controller/BusController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -17,6 +18,7 @@
import com.masai.service.BusOps;

import jakarta.validation.Valid;
import lombok.val;

@RestController
//@CrossOrigin(origins = "*")
Expand Down
21 changes: 13 additions & 8 deletions Backend/src/main/java/com/masai/controller/CustomerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.masai.entity.Customer;
import com.masai.entity.SubscribedEmail;
import com.masai.service.CustomerOps;

import jakarta.validation.Valid;
import lombok.val;

@RestController
//@CrossOrigin(origins = "*")
Expand All @@ -35,16 +38,16 @@ public ResponseEntity<Customer> registerCustomer(@RequestBody @Valid Customer cu
}


@PutMapping("/customer/update")
public ResponseEntity<Customer> updateCustomer(@RequestBody @Valid Customer customer) {
Customer c = co.updateCustomer(customer);
@PutMapping("/customer/update/{cid}")
public ResponseEntity<Customer> updateCustomer( @PathVariable Integer cid, @RequestBody @Valid Customer customer) {
Customer c = co.updateCustomer(cid,customer);
return new ResponseEntity<>(c,HttpStatus.OK);
}


@DeleteMapping("/customer/delete")
public ResponseEntity<Customer> deleteCustomer(@RequestBody @Valid Customer customer) {
Customer c = co.deleteCustomer(customer);
@DeleteMapping("/customer/delete/{cid}")
public ResponseEntity<Customer> deleteCustomer(@PathVariable Integer cid) {
Customer c = co.deleteCustomer(cid);
return new ResponseEntity<>(c,HttpStatus.OK);
}

Expand All @@ -60,6 +63,8 @@ public ResponseEntity<List<Customer>> viewAllCustomer(){
return new ResponseEntity<>(co.viewAllCustomer(),HttpStatus.OK);
}



@PostMapping("/subscriber")
public ResponseEntity<String> subscribe(@Valid @RequestBody SubscribedEmail se){
return new ResponseEntity<>("Subscribed!",HttpStatus.OK);
}
}
20 changes: 15 additions & 5 deletions Backend/src/main/java/com/masai/controller/EntryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
import org.springframework.web.bind.annotation.RestController;

import com.masai.entity.Admin;
import com.masai.entity.CredDto;
import com.masai.entity.Customer;
import com.masai.service.AdminOps;
import com.masai.service.CustomerOps;

import io.swagger.v3.oas.models.media.MediaType;
import jakarta.validation.Valid;

@RestController
Expand All @@ -29,13 +31,21 @@ public class EntryController {

@Autowired
private AdminOps adminService;
@GetMapping("/cusLogin")
public ResponseEntity<String> loginCustomerHandler(Authentication auth){
System.out.println(auth); // principal object
@GetMapping(value = "/cusLogin")
public ResponseEntity<CredDto> loginCustomerHandler(Authentication auth){
// System.out.println(auth); // principal object

Customer customer = customerService.getCustomerByEmail(auth.getName());

return new ResponseEntity<>("log in successfully with name "+customer.getCustomerName(), HttpStatus.OK);
// org.springframework.http.HttpHeaders hh= new org.springframework.http.HttpHeaders();
// hh.add("role", customer.getRole());

CredDto c=new CredDto();
c.setName(customer.getCustomerName());
c.setRole(customer.getRole());
c.setEmail(customer.getEmail());
c.setPassword(customer.getCustomerPassword());

return new ResponseEntity<>(c,HttpStatus.OK);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public class PackageBookingController {
PackageBookingOps b;

@PostMapping("/package/{CutomerId}/{PackageId}")
public ResponseEntity<PackageBooking> bookPackage(@PathVariable("CutomerId") Integer id,@PathVariable("PackageId") Integer id1,@RequestBody @Valid PackageBooking p){
PackageBooking p1 = b.makeBooking(id,id1,p);
public ResponseEntity<PackageBooking> bookPackage(@PathVariable("CutomerId") Integer id,@PathVariable("PackageId") Integer id1){
PackageBooking p1 = b.makeBooking(id,id1);
return new ResponseEntity<>(p1,HttpStatus.ACCEPTED);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public class PaymentDetailsController {

@PostMapping("/Payment/{PackageBookingID}/{customerId}")
public ResponseEntity<PaymentDetails> makePayment(@PathVariable("PackageBookingID") Integer id,
@PathVariable Integer customerId, @RequestBody @Valid PaymentDetails payment) {
return new ResponseEntity<>(p.makePayment(id, customerId, payment), HttpStatus.CREATED);
@PathVariable Integer customerId) {
return new ResponseEntity<>(p.makePayment(id, customerId), HttpStatus.CREATED);
}

@DeleteMapping("/Payment/{PaymentID}")
public ResponseEntity<PaymentDetails> cancelPayment(@PathVariable("PaymentID") Integer id) {
return new ResponseEntity<>(p.canclePayment(id), HttpStatus.OK);
@DeleteMapping("/Payment/{PaymentID}/{customerId}")
public ResponseEntity<PaymentDetails> cancelPayment(@PathVariable("PaymentID") Integer id,@PathVariable Integer customerId) {
return new ResponseEntity<>(p.canclePayment(id,customerId), HttpStatus.OK);
}

@GetMapping("/Payment")
Expand Down
11 changes: 6 additions & 5 deletions Backend/src/main/java/com/masai/controller/RouteController.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.springframework.web.bind.annotation.RestController;

import com.masai.entity.Route;
import com.masai.entity.RouteDto;
import com.masai.repository.RouteDao;
import com.masai.service.RouteOps;

Expand All @@ -38,18 +39,18 @@ public ResponseEntity<Route> addRoute(@PathVariable("BusId") Integer id,@Request
}

@DeleteMapping("/route/{routeID}")
public ResponseEntity<Route> deleteRoute(@PathVariable("BusId") Integer id){
public ResponseEntity<Route> deleteRoute(@PathVariable("routeID") Integer id){
return new ResponseEntity<>(r.removeRoute(id),HttpStatus.OK);
}

@GetMapping("/route/{routeID}")
public ResponseEntity<Route> getRoute(@PathVariable("BusId") Integer id){
public ResponseEntity<Route> getRoute(@PathVariable("routeID") Integer id){
return new ResponseEntity<>(r.searchRoute(id),HttpStatus.FOUND);
}

@PutMapping("/route/update")
public ResponseEntity<Route> updateRoute(RouteDao routedto,@RequestBody @Valid Route route){
return new ResponseEntity<>(r.updateRoute(routedto, route),HttpStatus.FOUND);
@PutMapping("/route/update/{routeId}")
public ResponseEntity<Route> updateRoute(RouteDto routedto, @PathVariable Integer routeId){
return new ResponseEntity<>(r.updateRoute(routedto, routeId),HttpStatus.FOUND);
}
@GetMapping("/route")
public ResponseEntity<List<Route>> getAllRoute(){
Expand Down
12 changes: 12 additions & 0 deletions Backend/src/main/java/com/masai/entity/CredDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.masai.entity;

import lombok.Data;

@Data
public class CredDto {

String name;
String role;
String email;
String password;
}
2 changes: 1 addition & 1 deletion Backend/src/main/java/com/masai/entity/Customer.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class Customer {
@NotBlank(message = "Please provide the customer password")
@NotNull(message = "Please provide the customer password")
// @Size(min = 6, max = 10, message = "min 6 and max 10 characters allowed only")
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
// @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)

private String customerPassword;

Expand Down
6 changes: 2 additions & 4 deletions Backend/src/main/java/com/masai/entity/RouteDto.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.masai.entity;

import java.time.LocalDateTime;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
Expand All @@ -23,9 +21,9 @@ public class RouteDto {
@NotBlank(message = "Please provide the departureTime")
@NotNull(message = "Please provide the departureTime")

private LocalDateTime departureTime;
private String departureTime;

@NotBlank(message = "Please provide the arrivalTime")
@NotNull(message = "Please provide the arrivalTime")
private LocalDateTime arrivalTime;
private String arrivalTime;
}
24 changes: 24 additions & 0 deletions Backend/src/main/java/com/masai/entity/SubscribedEmail.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.masai.entity;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
@Entity
public class SubscribedEmail {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Integer subsId;
@Email(message = "Valid email id")
@NotNull(message = "Value should not be null")
String email;

}
9 changes: 9 additions & 0 deletions Backend/src/main/java/com/masai/repository/SubsRepo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.masai.repository;

import org.springframework.data.jpa.repository.JpaRepository;

import com.masai.entity.SubscribedEmail;

public interface SubsRepo extends JpaRepository< SubscribedEmail,Integer> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,52 +22,45 @@ public class JwtTokenValidatorFilter extends OncePerRequestFilter {
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
throws ServletException, IOException {


String jwt= request.getHeader(SecurityConstants.JWT_HEADER);


if(jwt != null) {

String jwt = request.getHeader(SecurityConstants.JWT_HEADER);

if (jwt != null && jwt.startsWith("Bearer")) {

try {

//extracting the word Bearer
// extracting the word Bearer
jwt = jwt.substring(7);


SecretKey key= Keys.hmacShaKeyFor(SecurityConstants.JWT_KEY.getBytes());

Claims claims= Jwts.parserBuilder().setSigningKey(key).build().parseClaimsJws(jwt).getBody();

String username= String.valueOf(claims.get("username"));

String authorities= (String)claims.get("authorities");

Authentication auth = new UsernamePasswordAuthenticationToken(username, null, AuthorityUtils.commaSeparatedStringToAuthorityList(authorities));
SecretKey key = Keys.hmacShaKeyFor(SecurityConstants.JWT_KEY.getBytes());

Claims claims = Jwts.parserBuilder().setSigningKey(key).build().parseClaimsJws(jwt).getBody();

String username = String.valueOf(claims.get("username"));

String authorities = (String) claims.get("authorities");

Authentication auth = new UsernamePasswordAuthenticationToken(username, null,
AuthorityUtils.commaSeparatedStringToAuthorityList(authorities));

SecurityContextHolder.getContext().setAuthentication(auth);

} catch (Exception e) {
throw new BadCredentialsException("Invalid Token received..");
}

}

filterChain.doFilter(request, response);
}


//this time this validation filter has to be executed for all the apis except the /signIn api

// this time this validation filter has to be executed for all the apis except
// the /signIn api

@Override
protected boolean shouldNotFilter(HttpServletRequest request) throws ServletException {

return request.getServletPath().equals("/travel/cusLogin");
}






}
15 changes: 8 additions & 7 deletions Backend/src/main/java/com/masai/security/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,23 @@ public CorsConfiguration getCorsConfiguration(HttpServletRequest request) {
});

}).authorizeHttpRequests(auth -> {
auth.requestMatchers("/**").permitAll();
auth.requestMatchers(HttpMethod.POST, "travel/customer/signup", "travel/addAdmin").permitAll()

.requestMatchers(HttpMethod.POST, "travel/updateAdmin", "travel/adddestination",
"travel/bus", "travel/bus/travels", "travel/destination", "travel/feedback",
"travel/hotel", "travel/Packages", "travel/route", "travel/travels")
"travel/bus", "travel/bus/travels", "travel/destination",
"travel/hotel")
.hasRole("ADMIN")

.requestMatchers("travel/Destination", "travel/Destination/travels", "travel/feedback",
"travel/Packages", "travel/reports", "travel/route", "travel/travels")
.requestMatchers("travel/Destination", "travel/Destination/travels",
"travel/reports","travel/route/update")
.hasRole("ADMIN")

.requestMatchers("travel/customers", "travel/bus", "travel/customers",
.requestMatchers("travel/customers", "travel/bus", "travel/customers","travel/feedback",
"travel/customer/delete", "travel/customer/update", "travel/customer",
"travel/Destination", "travel/feedback/customer", "travel/Hotel/Destination",
"travel/package", "travel/Payment", "travel/report")
.hasRole("USER")
"travel/package", "travel/Payment","travel/Packages", "travel/report","travel/travels","travel/route")
.hasAnyRole("USER","ADMIN")

.requestMatchers("/swagger-ui*/**", "/v3/api-docs/**").permitAll()
.requestMatchers("travel/customers/**", "travel/HotelBooking", "travel/Hotel", "packages")
Expand Down
6 changes: 3 additions & 3 deletions Backend/src/main/java/com/masai/service/BusOpsImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Bus addBus(int travelId, Bus bus) {
bus.setTravel(travels.get());
return bd.save(bus);
}
throw new TravelsNotFoundException("Tranvels not found to add bus");
throw new TravelsNotFoundException("Travels not found to add bus");
}

public Bus addDestination(int destId, int bId) {
Expand Down Expand Up @@ -80,7 +80,7 @@ public Bus searchBus(int busId) {
}
return bus.get();
}
throw new BusNotFoundException("Bus not found ");
throw new BusNotFoundException("Bus not found");
}

@Override
Expand All @@ -96,7 +96,7 @@ public List<Bus> viewBusByTravelsId(int travelId) {
return buses.stream().filter(a -> a.isStatus()).toList();
throw new EmptyBusListException("No bus is added by this traveler yet");
}
throw new TravelsNotFoundException("Tranvels not found to add bus");
throw new TravelsNotFoundException("Travels not found to add bus");
}

@Override
Expand Down
Loading