boost controller endpoint little fix

+ get rid of not used dependencies
This commit is contained in:
2025-05-16 13:42:24 +02:00
parent 1d55f40753
commit d869a18901
3 changed files with 22 additions and 37 deletions

29
pom.xml
View File

@@ -10,7 +10,7 @@
</parent> </parent>
<groupId>_11.asktpk</groupId> <groupId>_11.asktpk</groupId>
<artifactId>ArtisanConnectBackend</artifactId> <artifactId>ArtisanConnectBackend</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>1.0.0</version>
<name>ArtisanConnectBackend</name> <name>ArtisanConnectBackend</name>
<description>ArtisanConnectBackend</description> <description>ArtisanConnectBackend</description>
<url/> <url/>
@@ -34,31 +34,16 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId> <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency> </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> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId> <artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope> <scope>runtime</scope>
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.boot</groupId>-->
<!-- <artifactId>spring-boot-docker-compose</artifactId>-->
<!-- <scope>runtime</scope>-->
<!-- <optional>true</optional>-->
<!-- </dependency>-->
<dependency> <dependency>
<groupId>org.postgresql</groupId> <groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId> <artifactId>postgresql</artifactId>
@@ -73,15 +58,10 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId> <artifactId>spring-boot-starter-actuator</artifactId>
</dependency> </dependency>
<!-- <dependency>-->
<!-- <groupId>org.springframework.security</groupId>-->
<!-- <artifactId>spring-security-test</artifactId>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<dependency> <dependency>
<groupId>com.squareup.okhttp3</groupId> <groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId> <artifactId>okhttp</artifactId>
<version>4.9.3</version> <version>4.12.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
@@ -93,11 +73,6 @@
<artifactId>jakarta.validation-api</artifactId> <artifactId>jakarta.validation-api</artifactId>
<version>3.1.0</version> <version>3.1.0</version>
</dependency> </dependency>
<!-- <dependency>-->
<!-- <groupId>org.springdoc</groupId>-->
<!-- <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>-->
<!-- <version>2.8.5</version>-->
<!-- </dependency>-->
</dependencies> </dependencies>
<build> <build>

View File

@@ -1,6 +1,8 @@
package _11.asktpk.artisanconnectbackend.controller; package _11.asktpk.artisanconnectbackend.controller;
import _11.asktpk.artisanconnectbackend.dto.NoticeAdditionDTO; 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.ClientService;
import _11.asktpk.artisanconnectbackend.service.NoticeService; import _11.asktpk.artisanconnectbackend.service.NoticeService;
import _11.asktpk.artisanconnectbackend.dto.NoticeDTO; import _11.asktpk.artisanconnectbackend.dto.NoticeDTO;
@@ -29,7 +31,7 @@ public class NoticeController {
} }
@GetMapping("/get/{id}") @GetMapping("/get/{id}")
public ResponseEntity getNoticeById(@PathVariable long id) { public ResponseEntity<?> getNoticeById(@PathVariable long id) {
if (noticeService.noticeExists(id)) { if (noticeService.noticeExists(id)) {
return ResponseEntity.ok(noticeService.getNoticeById(id)); return ResponseEntity.ok(noticeService.getNoticeById(id));
} else { } else {
@@ -98,23 +100,22 @@ public class NoticeController {
} }
@DeleteMapping("/delete/{id}") @DeleteMapping("/delete/{id}")
public ResponseEntity deleteNotice(@PathVariable("id") long id) { public ResponseEntity<RequestResponseDTO> deleteNotice(@PathVariable("id") long id) {
if (noticeService.noticeExists(id)) { if (noticeService.noticeExists(id)) {
noticeService.deleteNotice(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 { } 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}") @PostMapping("/boost/{id}")
public ResponseEntity boostNotice(@PathVariable("id") long id) { public ResponseEntity<RequestResponseDTO> boostNotice(@PathVariable("id") long clientId, @RequestBody NoticeBoostDTO dto) {
long clientId = 1L; if (!noticeService.isNoticeOwnedByClient(dto.getNoticeId(), clientId)) {
if (!noticeService.isNoticeOwnedByClient(id, clientId)) { return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new RequestResponseDTO("Ogłoszenie nie istnieje lub nie należy do zalogowanego klienta."));
throw new EntityNotFoundException("Ogłoszenie nie istnieje lub nie należy do zalogowanego klienta.");
} }
noticeService.boostNotice(id); noticeService.boostNotice(dto.getNoticeId());
return ResponseEntity.ok("Ogłoszenie zostało pomyślnie wypromowane."); return ResponseEntity.status(HttpStatus.OK).body(new RequestResponseDTO("Ogłoszenie zostało pomyślnie wypromowane."));
} }
} }

View File

@@ -0,0 +1,9 @@
package _11.asktpk.artisanconnectbackend.dto;
import lombok.Getter;
import lombok.Setter;
@Getter @Setter
public class NoticeBoostDTO {
private Long noticeId;
}