change repository to service in wishlist, add @Lazy
This commit is contained in:
@@ -48,7 +48,6 @@ public class NoticeController {
|
|||||||
if (dto.getCategory() == null) {
|
if (dto.getCategory() == null) {
|
||||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new NoticeAdditionDTO("Nie ma takiej kategorii"));
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new NoticeAdditionDTO("Nie ma takiej kategorii"));
|
||||||
}
|
}
|
||||||
|
|
||||||
dto.setPublishDate(java.time.LocalDateTime.now());
|
dto.setPublishDate(java.time.LocalDateTime.now());
|
||||||
|
|
||||||
Long newNoticeId = noticeService.addNotice(dto);
|
Long newNoticeId = noticeService.addNotice(dto);
|
||||||
@@ -56,7 +55,6 @@ public class NoticeController {
|
|||||||
return ResponseEntity.status(HttpStatus.CREATED).body(new NoticeAdditionDTO(newNoticeId ,"Dodano ogłoszenie."));
|
return ResponseEntity.status(HttpStatus.CREATED).body(new NoticeAdditionDTO(newNoticeId ,"Dodano ogłoszenie."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// TODO: zamiast dodawać tutaj pętlą, musi to robić NoticeService, trzeba zaimplementować odpowienią metodę
|
// TODO: zamiast dodawać tutaj pętlą, musi to robić NoticeService, trzeba zaimplementować odpowienią metodę
|
||||||
@PostMapping("/bulk_add")
|
@PostMapping("/bulk_add")
|
||||||
public ResponseEntity<String> addNotices(@RequestBody List<NoticeDTO> notices_list) {
|
public ResponseEntity<String> addNotices(@RequestBody List<NoticeDTO> notices_list) {
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import java.util.List;
|
|||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/v1/wishlist")
|
@RequestMapping("/api/v1/wishlist")
|
||||||
public class WishlistController {
|
public class WishlistController {
|
||||||
|
|
||||||
private final WishlistService wishlistService;
|
private final WishlistService wishlistService;
|
||||||
private final ClientService clientService;
|
private final ClientService clientService;
|
||||||
private final NoticeService noticeService;
|
private final NoticeService noticeService;
|
||||||
@@ -30,7 +29,6 @@ public class WishlistController {
|
|||||||
public ResponseEntity<RequestResponseDTO> toggleWishlist(@RequestBody WishlistDTO wishlistDTO) {
|
public ResponseEntity<RequestResponseDTO> toggleWishlist(@RequestBody WishlistDTO wishlistDTO) {
|
||||||
Long noticeId = wishlistDTO.getNoticeId();
|
Long noticeId = wishlistDTO.getNoticeId();
|
||||||
Long clientId = wishlistDTO.getClientId();
|
Long clientId = wishlistDTO.getClientId();
|
||||||
|
|
||||||
NoticeDTO noticeDTO = noticeService.getNoticeById(noticeId);
|
NoticeDTO noticeDTO = noticeService.getNoticeById(noticeId);
|
||||||
if (noticeDTO == null) {
|
if (noticeDTO == null) {
|
||||||
return ResponseEntity.badRequest().body(new RequestResponseDTO("Notice not found"));
|
return ResponseEntity.badRequest().body(new RequestResponseDTO("Notice not found"));
|
||||||
@@ -47,21 +45,15 @@ public class WishlistController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @GetMapping("/{clientId}")
|
||||||
|
// public ResponseEntity<List<WishlistDTO>> getWishlist(@PathVariable Long clientId) {
|
||||||
@GetMapping("/{clientId}")
|
// List<WishlistDTO> wishlist = wishlistService.getWishlistForClientId(clientId);
|
||||||
public ResponseEntity<List<WishlistDTO>> getWishlist(@PathVariable Long clientId) {
|
// return ResponseEntity.ok(wishlist);
|
||||||
List<WishlistDTO> wishlist = wishlistService.getWishlistForClientId(clientId);
|
|
||||||
return ResponseEntity.ok(wishlist);
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// @GetMapping("/get/all")
|
|
||||||
// public List<NoticeDTO> getAllNotices() {
|
|
||||||
// return noticeService.getAllNotices();
|
|
||||||
// }
|
// }
|
||||||
@GetMapping("/")
|
|
||||||
public List<NoticeDTO> getWishlistForClient() {
|
@GetMapping("/")
|
||||||
Long clientId =1L;
|
public List<NoticeDTO> getWishlistForClient() {
|
||||||
return wishlistService.getNoticesInWishlist(clientId);
|
Long clientId =1L;
|
||||||
}
|
return wishlistService.getNoticesInWishlist(clientId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -5,7 +5,7 @@ import _11.asktpk.artisanconnectbackend.entities.Notice;
|
|||||||
import _11.asktpk.artisanconnectbackend.repository.ClientRepository;
|
import _11.asktpk.artisanconnectbackend.repository.ClientRepository;
|
||||||
import _11.asktpk.artisanconnectbackend.repository.NoticeRepository;
|
import _11.asktpk.artisanconnectbackend.repository.NoticeRepository;
|
||||||
import _11.asktpk.artisanconnectbackend.dto.NoticeDTO;
|
import _11.asktpk.artisanconnectbackend.dto.NoticeDTO;
|
||||||
import _11.asktpk.artisanconnectbackend.repository.WishlistRepository;
|
//import _11.asktpk.artisanconnectbackend.service.WishlistService;
|
||||||
import jakarta.persistence.EntityNotFoundException;
|
import jakarta.persistence.EntityNotFoundException;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -18,12 +18,13 @@ public class NoticeService {
|
|||||||
|
|
||||||
private final NoticeRepository noticeRepository;
|
private final NoticeRepository noticeRepository;
|
||||||
private final ClientRepository clientRepository;
|
private final ClientRepository clientRepository;
|
||||||
private final WishlistRepository wishlistRepository;
|
// private final WishlistRepository wishlistRepository;
|
||||||
|
private final WishlistService wishlistService;
|
||||||
|
|
||||||
public NoticeService(NoticeRepository noticeRepository, ClientRepository clientRepository,WishlistRepository wishlistRepository) {
|
public NoticeService(NoticeRepository noticeRepository, ClientRepository clientRepository,WishlistService wishlistService) {
|
||||||
this.noticeRepository = noticeRepository;
|
this.noticeRepository = noticeRepository;
|
||||||
this.clientRepository = clientRepository;
|
this.clientRepository = clientRepository;
|
||||||
this.wishlistRepository = wishlistRepository;//serwis zamiast repository
|
this.wishlistService = wishlistService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Notice fromDTO(NoticeDTO dto) {
|
public Notice fromDTO(NoticeDTO dto) {
|
||||||
@@ -45,11 +46,11 @@ public class NoticeService {
|
|||||||
|
|
||||||
private NoticeDTO toDTO(Notice notice) {
|
private NoticeDTO toDTO(Notice notice) {
|
||||||
NoticeDTO dto = new NoticeDTO();
|
NoticeDTO dto = new NoticeDTO();
|
||||||
Optional<Client> client = clientRepository.findById(1L);
|
Optional<Client> client = clientRepository.findById(1L);//To be updated using AuthService after implementing authentication.
|
||||||
boolean isWishlisted = false;
|
boolean isWishlisted = false;
|
||||||
if (client.isPresent()) {
|
if (client.isPresent()) {
|
||||||
Client c = client.get();
|
Client c = client.get();
|
||||||
isWishlisted = wishlistRepository.existsByClientAndNotice(c,notice);
|
isWishlisted = wishlistService.isWishlisted(c, notice);
|
||||||
}
|
}
|
||||||
dto.setNoticeId(notice.getIdNotice());
|
dto.setNoticeId(notice.getIdNotice());
|
||||||
dto.setTitle(notice.getTitle());
|
dto.setTitle(notice.getTitle());
|
||||||
|
|||||||
Reference in New Issue
Block a user