Changeset 43c9090 for src/main/java


Ignore:
Timestamp:
10/12/24 21:32:15 (5 weeks ago)
Author:
macagaso <gasoskamarija@…>
Branches:
master
Parents:
743de55
Message:

Updated version

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  
    9494        try {
    9595            Long userId = appointmentService.updateAppointment(term);
    96             System.out.println(userId);
    9796            return ResponseEntity.ok(userId.toString());
    9897        } catch (Exception e) {
     
    120119        try {
    121120            appointmentService.deleteAppointmentByTerm(term);
    122             return ResponseEntity.noContent().build(); // Returns 204 No Content on success
     121            return ResponseEntity.noContent().build();
    123122        } catch (IllegalArgumentException e) {
    124             return ResponseEntity.notFound().build(); // Returns 404 Not Found if appointment doesn't exist
     123            return ResponseEntity.notFound().build();
    125124        }
    126125    }
     
    149148    }
    150149
    151 
    152150}
  • src/main/java/finki/it/terapijamkbackend/spring/controllers/AuthController.java

    r743de55 r43c9090  
    33import finki.it.terapijamkbackend.spring.dto.LoginResponse;
    44import finki.it.terapijamkbackend.spring.entities.User;
    5 import finki.it.terapijamkbackend.spring.entities.UserRole;
    65import finki.it.terapijamkbackend.spring.services.UserService;
    76import jakarta.servlet.http.Cookie;
     
    4948            Cookie usernameCookie = new Cookie("username", temp.getUsername());
    5049            usernameCookie.setPath("/");
    51             usernameCookie.setMaxAge(60*5);
     50            usernameCookie.setMaxAge(600);
    5251            response.addCookie(usernameCookie);
     52
     53            Cookie roleCookie = new Cookie("role", temp.getUserRole().toString());
     54            roleCookie.setPath("/");
     55            roleCookie.setMaxAge(600);
     56            response.addCookie(roleCookie);
    5357
    5458            return ResponseEntity.ok(loginResponse);
  • src/main/java/finki/it/terapijamkbackend/spring/controllers/CouponController.java

    r743de55 r43c9090  
    33import finki.it.terapijamkbackend.spring.services.CouponsService;
    44import jakarta.persistence.EntityNotFoundException;
    5 import jakarta.transaction.Transactional;
    65import org.springframework.beans.factory.annotation.Autowired;
    76import org.springframework.http.HttpStatus;
     
    2019    @PutMapping("/createCoupon")
    2120    public ResponseEntity<Coupon> updateCoupon(@RequestBody Coupon couponItem) {
    22         System.out.println(couponItem);
    2321        if (couponItem.getTitle() == null || couponItem.getCode() == null) {
    2422            return ResponseEntity.badRequest().build();
     
    5351        coupon.setCode(newCouponData.getCode());
    5452        coupon.setDescription(newCouponData.getDescription());
    55         couponService.save(coupon); // Save the updated coupon
     53        couponService.save(coupon);
    5654
    5755        return ResponseEntity.ok().build();
    5856    }
     57
     58
     59    @GetMapping("/getCouponNames")
     60    public ResponseEntity<List<String>> getCouponNames() {
     61        List<String> couponNames = couponService.getCouponNames();
     62        return ResponseEntity.ok(couponNames);
     63    }
    5964}
  • src/main/java/finki/it/terapijamkbackend/spring/controllers/EventController.java

    r743de55 r43c9090  
    11package finki.it.terapijamkbackend.spring.controllers;
    22
    3 import finki.it.terapijamkbackend.spring.entities.Coupon;
    43import finki.it.terapijamkbackend.spring.entities.Event;
    5 import finki.it.terapijamkbackend.spring.services.AppointmentService;
    64import finki.it.terapijamkbackend.spring.services.EventService;
    75import jakarta.persistence.EntityNotFoundException;
     
    2321    @PutMapping("/createEvent")
    2422    public ResponseEntity<Event> updateEvent(@RequestBody Event eventItem) {
    25         System.out.println(eventItem);
    2623        if (eventItem.getTitle() == null || eventItem.getText() == null) {
    2724            return ResponseEntity.badRequest().build();
     
    5754        event.setText(newEventData.getText());
    5855        event.setImgSrc(newEventData.getImgSrc());
    59         eventService.saveEvent(event); // Save the updated coupon
     56        eventService.saveEvent(event);
    6057
    6158        return ResponseEntity.ok().build();
  • src/main/java/finki/it/terapijamkbackend/spring/controllers/RequestController.java

    r743de55 r43c9090  
    3737    @GetMapping("/listAll")
    3838    public List<TermsResponse> getRequestsByUser(@RequestParam("username") String username) {
    39         System.out.println(username);
    4039        List<Request>terms=requestService.findRequestsByUsername(username);
    4140        return terms.stream()
  • src/main/java/finki/it/terapijamkbackend/spring/controllers/UserController.java

    r743de55 r43c9090  
    4545            response = new HashMap<>();
    4646            response.put("message", "User created successfully!");
    47             System.out.println(response);
    4847            return ResponseEntity.ok(response);
    4948        } catch (Exception e) {
     
    5453    @GetMapping("/editUser")
    5554    public ResponseEntity<User> getUser(@RequestParam String username) {
    56         User user = userService.getUserByUsername(username); // Fetch user data from service
     55        User user = userService.getUserByUsername(username);
    5756        if (user != null) {
    58             return ResponseEntity.ok(user); // Return user data as JSON
     57            return ResponseEntity.ok(user);
    5958        } else {
    60             return ResponseEntity.notFound().build(); // Handle user not found
     59            return ResponseEntity.notFound().build();
    6160        }
    6261    }
     
    7675            String oldUsername=getCookieValue(request, "username");
    7776            User user = userService.updateUser(oldUsername, updatedUser);
    78             return ResponseEntity.ok(user); // Return the updated user in the response
     77            return ResponseEntity.ok(user);
    7978        } catch (UserNotFoundException e) {
    80             return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); // Return a 404 if user is not found
     79            return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
    8180        } catch (Exception e) {
    82             return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); // Return a 500 for other errors
     81            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    8382        }
    8483    }
  • src/main/java/finki/it/terapijamkbackend/spring/controllers/WebController.java

    r743de55 r43c9090  
    11package finki.it.terapijamkbackend.spring.controllers;
    22
     3import finki.it.terapijamkbackend.spring.services.UserService;
     4import org.springframework.beans.factory.annotation.Autowired;
    35import org.springframework.stereotype.Controller;
    46import org.springframework.web.bind.annotation.GetMapping;
    57
     8
    69@Controller
    710public class WebController {
    8 
    911    @GetMapping(path="/")
    1012    public String index() {
     
    5153        return "html/adminCoupons";
    5254    }
     55
     56    @GetMapping(path="/userInfo.html")
     57    public String userInfo() {
     58        return "html/userInfo";
     59    }
    5360}
  • src/main/java/finki/it/terapijamkbackend/spring/entities/Appointment.java

    r743de55 r43c9090  
    2626    private Long id;
    2727
    28     @ManyToOne(fetch = FetchType.LAZY)  // Fetch the related entity lazily to avoid loading all properties
     28    @ManyToOne(fetch = FetchType.LAZY)
    2929    @JoinColumn(name="request_id", referencedColumnName = "id")
    3030    @JsonIgnore
  • src/main/java/finki/it/terapijamkbackend/spring/entities/Event.java

    r743de55 r43c9090  
    2525
    2626    private String title;
     27    @Lob
     28    @Column(name = "text", columnDefinition = "TEXT")
    2729    private String text;
    28     @Lob // Indicates that this field can hold large data
    29     @Column(name = "img_src", columnDefinition = "TEXT") // Ensure column type is TEXT in database
     30    @Lob
     31    @Column(name = "img_src", columnDefinition = "TEXT")
    3032    private String imgSrc;
    3133
  • src/main/java/finki/it/terapijamkbackend/spring/services/CouponsService.java

    r743de55 r43c9090  
    99import java.util.List;
    1010import java.util.Optional;
     11import java.util.stream.Collectors;
    1112
    1213@Service
     
    3334        return couponRepository.findByTitle(identifier);
    3435    }
     36    public List<String> getCouponNames() {
     37        return couponRepository.findAll().stream()
     38                .map(Coupon::getCode)
     39                .collect(Collectors.toList());
     40    }
    3541
    3642    public void save(Coupon coupon) {
  • src/main/java/finki/it/terapijamkbackend/spring/services/EventService.java

    r743de55 r43c9090  
    11package finki.it.terapijamkbackend.spring.services;
    22
    3 import finki.it.terapijamkbackend.spring.entities.Coupon;
    43import finki.it.terapijamkbackend.spring.entities.Event;
    54import finki.it.terapijamkbackend.spring.repositories.EventRepository;
    6 import finki.it.terapijamkbackend.spring.repositories.UserRepository;
    75import jakarta.persistence.EntityNotFoundException;
    86import org.springframework.beans.factory.annotation.Autowired;
  • src/main/java/finki/it/terapijamkbackend/spring/services/RequestService.java

    r743de55 r43c9090  
    4141    public List<Request> findRequestsByUsername(String username) {
    4242       User user=userRepository.findByUsername(username).orElse(null);
    43         System.out.println(user.getId());
    4443        return requestRepository.findRequestsForFreeAppointments(user.getId());
    4544    }
  • src/main/java/finki/it/terapijamkbackend/spring/services/UserService.java

    r743de55 r43c9090  
    5858            }
    5959
    60             return userRepository.save(existingUser); // Save the updated user back to the database
     60            return userRepository.save(existingUser);
    6161        } else {
    6262            throw new UserNotFoundException("User not found with username: " + username);
Note: See TracChangeset for help on using the changeset viewer.