Skip to content

Commit

Permalink
Merge pull request Tuwaiq-Team-4#90 from Tuwaiq-Team-4/bakr
Browse files Browse the repository at this point in the history
update test carRepo,DriverTrips DriverService studentTripsController Tuwaiq-Team-4#21,add AuthenticationPrincipal in student controller Tuwaiq-Team-4#5
  • Loading branch information
Bakr44 authored Sep 10, 2023
2 parents a32fad3 + c7855c8 commit daed3b1
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public ResponseEntity getAllStudent() {


@PutMapping("/update/{id}")
public ResponseEntity updateStudent(@PathVariable Integer id,@RequestBody @Valid StudentDTO studentDTO){
studentService.updateStudent(id, studentDTO);
public ResponseEntity updateStudent(@AuthenticationPrincipal User user,@RequestBody @Valid StudentDTO studentDTO){
studentService.updateStudent(user.getId(), studentDTO);
return ResponseEntity.status(200).body("Student updated successfully");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.example.wayz.Controller;

import com.example.wayz.Model.StudentTrips;
import com.example.wayz.Model.User;
import com.example.wayz.Service.StudentTripsService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

@RestController
Expand All @@ -15,7 +17,7 @@ public class StudentTripsController {
private final StudentTripsService studentTripsService;

@GetMapping("/get-all")
public ResponseEntity getAllStudentTrips() {
public ResponseEntity getAllStudentTrips(@AuthenticationPrincipal User user) {
return ResponseEntity.status(200).body(studentTripsService.getAllStudentTrips());
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/example/wayz/Service/StudentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public List<Student> getAllStudent() {
return studentRepository.findAll();
}

public void updateStudent(Integer id, StudentDTO studentDTO) {
Student student = studentRepository.findStudentById(id);
public void updateStudent(Integer studentId, StudentDTO studentDTO) {
Student student = studentRepository.findStudentById(studentId);
studentDTO.setUsername(student.getUser().getUsername());
studentDTO.setPassword(student.getUser().getPassword());
studentDTO.setName(student.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ class StudentTripsControllerTest {

@BeforeEach
void setUp() {
user = new User(null,"0501111111","12345","DRIVER",
user = new User(null,"0501111111","12345Abcdefghi_#12345","STUDENT",
null,null,null);

student=new Student(null,"sara","PNU","Location",20,2500,user,null,null,null,null);
student=new Student(null,"sara","PNU","Location",20,user,null,null,null);
studentRepository.save(student);

studentTrips1=new StudentTrips(null,5,"going",LocalDateTime.of(2023, 9, 8, 15, 30, 45),student);
studentTrips2=new StudentTrips(null,5,"return", LocalDateTime.now().plusDays(1),student);
studentTrips1=new StudentTrips(null,5,"going",LocalDateTime.of(2023, 9, 8, 15, 30, 45),student,null);
studentTrips2=new StudentTrips(null,5,"return", LocalDateTime.now().plusDays(1),student,null);

studentTripsList1= Arrays.asList(studentTrips1);
studentTripsList2=Arrays.asList(studentTrips2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class AuthRepositoryTest {

@BeforeEach
void setUp() {
userAdmin = new User(null, "05333333333", "abc1234", "ADMIN", null, null, null);
user = new User(null, "0522222222", "abc1234", "USER", null, null, null);
userAdmin = new User(null, "0506333333", "Abcdefghi_#1234", "ADMIN", null, null, null);
user = new User(null, "0509222222", "Abccdefghi_#1234", "USER", null, null, null);
authRepository.save(user);
authRepository.save(userAdmin);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class CarRepositoryTest {

@BeforeEach
void setUp() {
user1 = new User(null,"0501111111","12345","DRIVER",
user1 = new User(null,"0501111111","Abcdefghi_#12345","DRIVER",
null,null,null);

Driver driver=new Driver(null,"bakr","pending",null,null,null,null,5,user1,null,null,null);
Driver driver=new Driver(null,"bakr","pending",5,user1,null,null,null,null);
car1 = new Car(null, 2017, 5, "abe 123", "Sedan", driver);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ class DriverTripsRepositoryTest {

@BeforeEach
void setUp() {
user = new User(null,"0501111111","12345","DRIVER",
user = new User(null,"0501111111","Abcdefghi_#12345","DRIVER",
null,null,null);

driver=new Driver(null,"bakr","pending",null,null,null,null,5,user,null,null,null);
driver=new Driver(null,"bakr","pending",5,user,null,null,null,null);
driverRepository.save(driver);

driverTrips1=new DriverTrips(null,"umm Al-qura", LocalDateTime.now(),LocalDateTime.now().plusHours(1),driver);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class StudentRepositoryTest {

@BeforeEach
void setUp() {
user = new User(null, "0522222222", "abc1234", "USER", null, null, null);
student = new Student(null, "saleh", "noura", "googlemaps.com/1234", 0, 0, user, null, null, null, null);
user = new User(null, "0502222222", "Abcdefghi_#12345", "USER", null, null, null);
student = new Student(null, "saleh", "noura", "googlemaps.com/1234", 10, user, null, null, null);
authRepository.save(user);
studentRepository.save(student);
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/example/wayz/Service/DriverServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ void setUp() {
user = new User(null,"0501111111","12345","DRIVER",
null,null,null);

driver1=new Driver(null,"bakr","pending",null,null,null,null,5,user,null,null,null);
driver2=new Driver(null,"bakr2","pending",null,null,null,null,5,user,null,null,null);
driver1=new Driver(null,"bakr","pending",5,user,null,null,null,null);
driver2=new Driver(null,"bakr2","pending",5,user,null,null,null,null);

drivers=new ArrayList<>();
drivers.add(driver1);
Expand Down

0 comments on commit daed3b1

Please sign in to comment.