Skip to content

Commit

Permalink
#EHA-34 Login admin is added.
Browse files Browse the repository at this point in the history
  • Loading branch information
beyzaaydeniz committed Jan 3, 2024
1 parent 6cdff30 commit f1c3ffb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import com.production.ehayvanbackendapi.DTO.CustomerDTO;
import com.production.ehayvanbackendapi.DTO.PetDTO;
import com.production.ehayvanbackendapi.DTO.VeterinarianDTO;
import com.production.ehayvanbackendapi.DTO.request.CreateOrUpdateCustomerDTO;
import com.production.ehayvanbackendapi.DTO.request.RegisterCustomerDTO;
import com.production.ehayvanbackendapi.Services.CustomerService;
import com.production.ehayvanbackendapi.Services.VeterinarianService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import org.springframework.http.HttpStatus;
Expand All @@ -23,9 +26,12 @@
@RequestMapping("/api/customers")
public class CustomerController {
private final CustomerService customerService;
private final VeterinarianService veterinarianService;

public CustomerController(CustomerService customerService) {

public CustomerController(CustomerService customerService, VeterinarianService veterinarianService) {
this.customerService = customerService;
this.veterinarianService = veterinarianService;
}

@GetMapping("/{id}")
Expand Down Expand Up @@ -74,14 +80,28 @@ public ResponseEntity<CustomerDTO> getCustomerLogin(@PathVariable String email,
}
}

// @GetMapping("/loginAdmin/{email}/{password}")
// public ResponseEntity<CustomerDTO> AdminLogin(@PathVariable String email,
// @PathVariable String password){
// CustomerDTO response = customerService.customerLogin(email, password);
// if(response != null&& Objects.equals(email, "admin@admin.com")){
// return new ResponseEntity<>(response, HttpStatus.OK);
// } else {
// return new ResponseEntity<>(HttpStatus.NOT_FOUND);
// }
// }

@GetMapping("/loginAdmin/{email}/{password}")
public ResponseEntity<CustomerDTO> getAdminLogin(@PathVariable String email,
@PathVariable String password){
public String getAdminLogin(@PathVariable String email,
@PathVariable String password, Model model){
CustomerDTO response = customerService.customerLogin(email, password);
if(response != null&& Objects.equals(email, "admin@admin.com")){
return new ResponseEntity<>(response, HttpStatus.OK);
List<VeterinarianDTO> veterinarians = veterinarianService.getAllVeterinarians();
model.addAttribute("veterinarians", veterinarians);
model.addAttribute("viewType", "default");
return "redirect:/api/veterinarians/desktop";
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
return "redirect:/api/customers/login";
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<div class="TitleAndBody" style="align-self: stretch; height: 42px; flex-direction: column; justify-content: center; align-items: center; gap: 20px; display: flex">
<div class="Title" style="align-self: stretch; text-align: center; color: #39434F; font-size: 34px; font-family: RocknRoll One; font-weight: 700; line-height: 42px; word-wrap: break-word">Log in</div>
</div>
<form id="loginForm" action="your_backend_endpoint" method="post">
<form id="loginForm" action="api/veterinarians/desktop" method="get">
<div class="InputsContainer" style="align-self: stretch; height: 134px; margin-top: 30px; flex-direction: column; justify-content: flex-start; align-items: flex-start; gap: 26px; display: flex">
<div class="InputPet" style="align-self: stretch; height: 54px; width: 250px; flex-direction: column; justify-content: flex-start; align-items: flex-start; gap: 5px; display: flex">
<div class="InputBox" style="align-self: stretch; height: 54px; border-radius: 14px; flex-direction: column; justify-content: flex-start; align-items: flex-start; gap: 10px; display: flex">
Expand Down

0 comments on commit f1c3ffb

Please sign in to comment.