Compare commits
2 Commits
initWishli
...
initNotice
| Author | SHA1 | Date | |
|---|---|---|---|
| d869a18901 | |||
|
|
1d55f40753 |
29
pom.xml
29
pom.xml
@@ -10,7 +10,7 @@
|
||||
</parent>
|
||||
<groupId>_11.asktpk</groupId>
|
||||
<artifactId>ArtisanConnectBackend</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<version>1.0.0</version>
|
||||
<name>ArtisanConnectBackend</name>
|
||||
<description>ArtisanConnectBackend</description>
|
||||
<url/>
|
||||
@@ -34,31 +34,16 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-rest</artifactId>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||
<!-- <artifactId>spring-boot-starter-oauth2-client</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<scope>runtime</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||
<!-- <artifactId>spring-boot-docker-compose</artifactId>-->
|
||||
<!-- <scope>runtime</scope>-->
|
||||
<!-- <optional>true</optional>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
@@ -73,15 +58,10 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.security</groupId>-->
|
||||
<!-- <artifactId>spring-security-test</artifactId>-->
|
||||
<!-- <scope>test</scope>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>4.9.3</version>
|
||||
<version>4.12.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
@@ -93,11 +73,6 @@
|
||||
<artifactId>jakarta.validation-api</artifactId>
|
||||
<version>3.1.0</version>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springdoc</groupId>-->
|
||||
<!-- <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>-->
|
||||
<!-- <version>2.8.5</version>-->
|
||||
<!-- </dependency>-->
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package _11.asktpk.artisanconnectbackend.controller;
|
||||
|
||||
import _11.asktpk.artisanconnectbackend.dto.NoticeAdditionDTO;
|
||||
import _11.asktpk.artisanconnectbackend.dto.NoticeBoostDTO;
|
||||
import _11.asktpk.artisanconnectbackend.dto.RequestResponseDTO;
|
||||
import _11.asktpk.artisanconnectbackend.service.ClientService;
|
||||
import _11.asktpk.artisanconnectbackend.service.NoticeService;
|
||||
import _11.asktpk.artisanconnectbackend.dto.NoticeDTO;
|
||||
@@ -29,7 +31,7 @@ public class NoticeController {
|
||||
}
|
||||
|
||||
@GetMapping("/get/{id}")
|
||||
public ResponseEntity getNoticeById(@PathVariable long id) {
|
||||
public ResponseEntity<?> getNoticeById(@PathVariable long id) {
|
||||
if (noticeService.noticeExists(id)) {
|
||||
return ResponseEntity.ok(noticeService.getNoticeById(id));
|
||||
} else {
|
||||
@@ -98,12 +100,22 @@ public class NoticeController {
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public ResponseEntity deleteNotice(@PathVariable("id") long id) {
|
||||
public ResponseEntity<RequestResponseDTO> deleteNotice(@PathVariable("id") long id) {
|
||||
if (noticeService.noticeExists(id)) {
|
||||
noticeService.deleteNotice(id);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new RequestResponseDTO("Pomyślnie usunięto ogłoszenie o ID: " + id));
|
||||
} else {
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new RequestResponseDTO("Nie znaleziono ogłoszenia o ID: " + id));
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/boost/{id}")
|
||||
public ResponseEntity<RequestResponseDTO> boostNotice(@PathVariable("id") long clientId, @RequestBody NoticeBoostDTO dto) {
|
||||
if (!noticeService.isNoticeOwnedByClient(dto.getNoticeId(), clientId)) {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new RequestResponseDTO("Ogłoszenie nie istnieje lub nie należy do zalogowanego klienta."));
|
||||
}
|
||||
noticeService.boostNotice(dto.getNoticeId());
|
||||
|
||||
return ResponseEntity.status(HttpStatus.OK).body(new RequestResponseDTO("Ogłoszenie zostało pomyślnie wypromowane."));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package _11.asktpk.artisanconnectbackend.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter @Setter
|
||||
public class NoticeBoostDTO {
|
||||
private Long noticeId;
|
||||
}
|
||||
@@ -5,4 +5,7 @@ import _11.asktpk.artisanconnectbackend.entities.Notice;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface NoticeRepository extends JpaRepository<Notice, Long> {
|
||||
|
||||
boolean existsByIdNoticeAndClientId(long noticeId, long clientId);
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import _11.asktpk.artisanconnectbackend.dto.NoticeDTO;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
@@ -119,4 +120,20 @@ public class NoticeService {
|
||||
throw new EntityNotFoundException("Nie znaleziono ogłoszenia o ID: " + id);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isNoticeOwnedByClient(long noticeId, long clientId) {
|
||||
return noticeRepository.existsByIdNoticeAndClientId(noticeId, clientId);
|
||||
}
|
||||
|
||||
public void boostNotice(long noticeId) {
|
||||
Notice notice = noticeRepository.findById(noticeId)
|
||||
.orElseThrow(() -> new EntityNotFoundException("Ogłoszenie o ID " + noticeId + " nie istnieje."));
|
||||
|
||||
notice.setPublishDate(LocalDateTime.now());
|
||||
|
||||
noticeRepository.save(notice);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user