Changeset 43c9090 for src/main/java/finki/it/terapijamkbackend/spring
- Timestamp:
- 10/12/24 21:32:15 (5 weeks ago)
- Branches:
- master
- Parents:
- 743de55
- Location:
- src/main/java/finki/it/terapijamkbackend/spring
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/finki/it/terapijamkbackend/spring/controllers/AppointmentController.java
r743de55 r43c9090 94 94 try { 95 95 Long userId = appointmentService.updateAppointment(term); 96 System.out.println(userId);97 96 return ResponseEntity.ok(userId.toString()); 98 97 } catch (Exception e) { … … 120 119 try { 121 120 appointmentService.deleteAppointmentByTerm(term); 122 return ResponseEntity.noContent().build(); // Returns 204 No Content on success121 return ResponseEntity.noContent().build(); 123 122 } catch (IllegalArgumentException e) { 124 return ResponseEntity.notFound().build(); // Returns 404 Not Found if appointment doesn't exist123 return ResponseEntity.notFound().build(); 125 124 } 126 125 } … … 149 148 } 150 149 151 152 150 } -
src/main/java/finki/it/terapijamkbackend/spring/controllers/AuthController.java
r743de55 r43c9090 3 3 import finki.it.terapijamkbackend.spring.dto.LoginResponse; 4 4 import finki.it.terapijamkbackend.spring.entities.User; 5 import finki.it.terapijamkbackend.spring.entities.UserRole;6 5 import finki.it.terapijamkbackend.spring.services.UserService; 7 6 import jakarta.servlet.http.Cookie; … … 49 48 Cookie usernameCookie = new Cookie("username", temp.getUsername()); 50 49 usernameCookie.setPath("/"); 51 usernameCookie.setMaxAge(60 *5);50 usernameCookie.setMaxAge(600); 52 51 response.addCookie(usernameCookie); 52 53 Cookie roleCookie = new Cookie("role", temp.getUserRole().toString()); 54 roleCookie.setPath("/"); 55 roleCookie.setMaxAge(600); 56 response.addCookie(roleCookie); 53 57 54 58 return ResponseEntity.ok(loginResponse); -
src/main/java/finki/it/terapijamkbackend/spring/controllers/CouponController.java
r743de55 r43c9090 3 3 import finki.it.terapijamkbackend.spring.services.CouponsService; 4 4 import jakarta.persistence.EntityNotFoundException; 5 import jakarta.transaction.Transactional;6 5 import org.springframework.beans.factory.annotation.Autowired; 7 6 import org.springframework.http.HttpStatus; … … 20 19 @PutMapping("/createCoupon") 21 20 public ResponseEntity<Coupon> updateCoupon(@RequestBody Coupon couponItem) { 22 System.out.println(couponItem);23 21 if (couponItem.getTitle() == null || couponItem.getCode() == null) { 24 22 return ResponseEntity.badRequest().build(); … … 53 51 coupon.setCode(newCouponData.getCode()); 54 52 coupon.setDescription(newCouponData.getDescription()); 55 couponService.save(coupon); // Save the updated coupon53 couponService.save(coupon); 56 54 57 55 return ResponseEntity.ok().build(); 58 56 } 57 58 59 @GetMapping("/getCouponNames") 60 public ResponseEntity<List<String>> getCouponNames() { 61 List<String> couponNames = couponService.getCouponNames(); 62 return ResponseEntity.ok(couponNames); 63 } 59 64 } -
src/main/java/finki/it/terapijamkbackend/spring/controllers/EventController.java
r743de55 r43c9090 1 1 package finki.it.terapijamkbackend.spring.controllers; 2 2 3 import finki.it.terapijamkbackend.spring.entities.Coupon;4 3 import finki.it.terapijamkbackend.spring.entities.Event; 5 import finki.it.terapijamkbackend.spring.services.AppointmentService;6 4 import finki.it.terapijamkbackend.spring.services.EventService; 7 5 import jakarta.persistence.EntityNotFoundException; … … 23 21 @PutMapping("/createEvent") 24 22 public ResponseEntity<Event> updateEvent(@RequestBody Event eventItem) { 25 System.out.println(eventItem);26 23 if (eventItem.getTitle() == null || eventItem.getText() == null) { 27 24 return ResponseEntity.badRequest().build(); … … 57 54 event.setText(newEventData.getText()); 58 55 event.setImgSrc(newEventData.getImgSrc()); 59 eventService.saveEvent(event); // Save the updated coupon56 eventService.saveEvent(event); 60 57 61 58 return ResponseEntity.ok().build(); -
src/main/java/finki/it/terapijamkbackend/spring/controllers/RequestController.java
r743de55 r43c9090 37 37 @GetMapping("/listAll") 38 38 public List<TermsResponse> getRequestsByUser(@RequestParam("username") String username) { 39 System.out.println(username);40 39 List<Request>terms=requestService.findRequestsByUsername(username); 41 40 return terms.stream() -
src/main/java/finki/it/terapijamkbackend/spring/controllers/UserController.java
r743de55 r43c9090 45 45 response = new HashMap<>(); 46 46 response.put("message", "User created successfully!"); 47 System.out.println(response);48 47 return ResponseEntity.ok(response); 49 48 } catch (Exception e) { … … 54 53 @GetMapping("/editUser") 55 54 public ResponseEntity<User> getUser(@RequestParam String username) { 56 User user = userService.getUserByUsername(username); // Fetch user data from service55 User user = userService.getUserByUsername(username); 57 56 if (user != null) { 58 return ResponseEntity.ok(user); // Return user data as JSON57 return ResponseEntity.ok(user); 59 58 } else { 60 return ResponseEntity.notFound().build(); // Handle user not found59 return ResponseEntity.notFound().build(); 61 60 } 62 61 } … … 76 75 String oldUsername=getCookieValue(request, "username"); 77 76 User user = userService.updateUser(oldUsername, updatedUser); 78 return ResponseEntity.ok(user); // Return the updated user in the response77 return ResponseEntity.ok(user); 79 78 } catch (UserNotFoundException e) { 80 return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); // Return a 404 if user is not found79 return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); 81 80 } catch (Exception e) { 82 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); // Return a 500 for other errors81 return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); 83 82 } 84 83 } -
src/main/java/finki/it/terapijamkbackend/spring/controllers/WebController.java
r743de55 r43c9090 1 1 package finki.it.terapijamkbackend.spring.controllers; 2 2 3 import finki.it.terapijamkbackend.spring.services.UserService; 4 import org.springframework.beans.factory.annotation.Autowired; 3 5 import org.springframework.stereotype.Controller; 4 6 import org.springframework.web.bind.annotation.GetMapping; 5 7 8 6 9 @Controller 7 10 public class WebController { 8 9 11 @GetMapping(path="/") 10 12 public String index() { … … 51 53 return "html/adminCoupons"; 52 54 } 55 56 @GetMapping(path="/userInfo.html") 57 public String userInfo() { 58 return "html/userInfo"; 59 } 53 60 } -
src/main/java/finki/it/terapijamkbackend/spring/entities/Appointment.java
r743de55 r43c9090 26 26 private Long id; 27 27 28 @ManyToOne(fetch = FetchType.LAZY) // Fetch the related entity lazily to avoid loading all properties28 @ManyToOne(fetch = FetchType.LAZY) 29 29 @JoinColumn(name="request_id", referencedColumnName = "id") 30 30 @JsonIgnore -
src/main/java/finki/it/terapijamkbackend/spring/entities/Event.java
r743de55 r43c9090 25 25 26 26 private String title; 27 @Lob 28 @Column(name = "text", columnDefinition = "TEXT") 27 29 private String text; 28 @Lob // Indicates that this field can hold large data29 @Column(name = "img_src", columnDefinition = "TEXT") // Ensure column type is TEXT in database30 @Lob 31 @Column(name = "img_src", columnDefinition = "TEXT") 30 32 private String imgSrc; 31 33 -
src/main/java/finki/it/terapijamkbackend/spring/services/CouponsService.java
r743de55 r43c9090 9 9 import java.util.List; 10 10 import java.util.Optional; 11 import java.util.stream.Collectors; 11 12 12 13 @Service … … 33 34 return couponRepository.findByTitle(identifier); 34 35 } 36 public List<String> getCouponNames() { 37 return couponRepository.findAll().stream() 38 .map(Coupon::getCode) 39 .collect(Collectors.toList()); 40 } 35 41 36 42 public void save(Coupon coupon) { -
src/main/java/finki/it/terapijamkbackend/spring/services/EventService.java
r743de55 r43c9090 1 1 package finki.it.terapijamkbackend.spring.services; 2 2 3 import finki.it.terapijamkbackend.spring.entities.Coupon;4 3 import finki.it.terapijamkbackend.spring.entities.Event; 5 4 import finki.it.terapijamkbackend.spring.repositories.EventRepository; 6 import finki.it.terapijamkbackend.spring.repositories.UserRepository;7 5 import jakarta.persistence.EntityNotFoundException; 8 6 import org.springframework.beans.factory.annotation.Autowired; -
src/main/java/finki/it/terapijamkbackend/spring/services/RequestService.java
r743de55 r43c9090 41 41 public List<Request> findRequestsByUsername(String username) { 42 42 User user=userRepository.findByUsername(username).orElse(null); 43 System.out.println(user.getId());44 43 return requestRepository.findRequestsForFreeAppointments(user.getId()); 45 44 } -
src/main/java/finki/it/terapijamkbackend/spring/services/UserService.java
r743de55 r43c9090 58 58 } 59 59 60 return userRepository.save(existingUser); // Save the updated user back to the database60 return userRepository.save(existingUser); 61 61 } else { 62 62 throw new UserNotFoundException("User not found with username: " + username);
Note:
See TracChangeset
for help on using the changeset viewer.