Compare commits
2 Commits
cdd31fd6b7
...
5ccfc6ba2c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5ccfc6ba2c | ||
|
|
f0e3a129d0 |
@@ -48,7 +48,6 @@ public class NoticeController {
|
||||
if (dto.getCategory() == null) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new NoticeAdditionDTO("Nie ma takiej kategorii"));
|
||||
}
|
||||
|
||||
dto.setPublishDate(java.time.LocalDateTime.now());
|
||||
|
||||
Long newNoticeId = noticeService.addNotice(dto);
|
||||
@@ -56,7 +55,6 @@ public class NoticeController {
|
||||
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ę
|
||||
@PostMapping("/bulk_add")
|
||||
public ResponseEntity<String> addNotices(@RequestBody List<NoticeDTO> notices_list) {
|
||||
|
||||
@@ -15,7 +15,6 @@ import java.util.List;
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/wishlist")
|
||||
public class WishlistController {
|
||||
|
||||
private final WishlistService wishlistService;
|
||||
private final ClientService clientService;
|
||||
private final NoticeService noticeService;
|
||||
@@ -30,7 +29,6 @@ public class WishlistController {
|
||||
public ResponseEntity<RequestResponseDTO> toggleWishlist(@RequestBody WishlistDTO wishlistDTO) {
|
||||
Long noticeId = wishlistDTO.getNoticeId();
|
||||
Long clientId = wishlistDTO.getClientId();
|
||||
|
||||
NoticeDTO noticeDTO = noticeService.getNoticeById(noticeId);
|
||||
if (noticeDTO == null) {
|
||||
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) {
|
||||
List<WishlistDTO> wishlist = wishlistService.getWishlistForClientId(clientId);
|
||||
return ResponseEntity.ok(wishlist);
|
||||
}
|
||||
//
|
||||
// @GetMapping("/get/all")
|
||||
// public List<NoticeDTO> getAllNotices() {
|
||||
// return noticeService.getAllNotices();
|
||||
// @GetMapping("/{clientId}")
|
||||
// public ResponseEntity<List<WishlistDTO>> getWishlist(@PathVariable Long clientId) {
|
||||
// List<WishlistDTO> wishlist = wishlistService.getWishlistForClientId(clientId);
|
||||
// return ResponseEntity.ok(wishlist);
|
||||
// }
|
||||
@GetMapping("/")
|
||||
public List<NoticeDTO> getWishlistForClient() {
|
||||
Long clientId =1L;
|
||||
return wishlistService.getNoticesInWishlist(clientId);
|
||||
}
|
||||
|
||||
@GetMapping("/")
|
||||
public List<NoticeDTO> getWishlistForClient() {
|
||||
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.NoticeRepository;
|
||||
import _11.asktpk.artisanconnectbackend.dto.NoticeDTO;
|
||||
import _11.asktpk.artisanconnectbackend.repository.WishlistRepository;
|
||||
//import _11.asktpk.artisanconnectbackend.service.WishlistService;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -18,12 +18,13 @@ public class NoticeService {
|
||||
|
||||
private final NoticeRepository noticeRepository;
|
||||
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.clientRepository = clientRepository;
|
||||
this.wishlistRepository = wishlistRepository;//serwis zamiast repository
|
||||
this.wishlistService = wishlistService;
|
||||
}
|
||||
|
||||
public Notice fromDTO(NoticeDTO dto) {
|
||||
@@ -45,11 +46,11 @@ public class NoticeService {
|
||||
|
||||
private NoticeDTO toDTO(Notice notice) {
|
||||
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;
|
||||
if (client.isPresent()) {
|
||||
Client c = client.get();
|
||||
isWishlisted = wishlistRepository.existsByClientAndNotice(c,notice);
|
||||
isWishlisted = wishlistService.isWishlisted(c, notice);
|
||||
}
|
||||
dto.setNoticeId(notice.getIdNotice());
|
||||
dto.setTitle(notice.getTitle());
|
||||
|
||||
@@ -7,20 +7,22 @@ import _11.asktpk.artisanconnectbackend.entities.Client;
|
||||
import _11.asktpk.artisanconnectbackend.entities.Notice;
|
||||
import _11.asktpk.artisanconnectbackend.entities.Wishlist;
|
||||
import _11.asktpk.artisanconnectbackend.repository.WishlistRepository;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class WishlistService {
|
||||
|
||||
private final WishlistRepository wishlistRepository;
|
||||
private final NoticeService noticeService;
|
||||
|
||||
public WishlistService(WishlistRepository wishlistRepository, NoticeService noticeService) {
|
||||
public WishlistService(WishlistRepository wishlistRepository, @Lazy NoticeService noticeService) {
|
||||
this.wishlistRepository = wishlistRepository;
|
||||
this.noticeService = noticeService;//tak robimy
|
||||
this.noticeService = noticeService;
|
||||
}
|
||||
|
||||
public List<WishlistDTO> getWishlistForClientId(Long clientId) {
|
||||
|
||||
Reference in New Issue
Block a user