-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
331 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
DB_URL=jdbc:postgresql://localhost:5432/filter | ||
DB_USERNAME=postgres | ||
DB_PASSWORD=qwerty | ||
RABBIT_HOST=localhost | ||
RABBIT_USERNAME=user | ||
RABBIT_PASSWORD=qwerty | ||
RABBIT_PORT=5672 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.brash.controller; | ||
|
||
import com.brash.data.entity.Mark; | ||
import com.brash.dto.web.ItemsDTO; | ||
import com.brash.service.MarkService; | ||
import com.brash.util.Mapper; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping(path = "/api/filter") | ||
public class FilterController { | ||
|
||
// private final UserService userService; | ||
// private final ItemService itemService; | ||
private final MarkService markService; | ||
|
||
@Operation( | ||
summary = "Получить все элементы по убыванию рейтинга оценки для пользователя" | ||
) | ||
@GetMapping("/all") | ||
public ResponseEntity<ItemsDTO> getAll(@NotNull @RequestParam long userId, | ||
@NotNull @RequestParam int offset, | ||
@NotNull @RequestParam int limit) { | ||
List<Mark> marks = markService.getMarks(userId, offset, limit); | ||
return ResponseEntity.ok(Mapper.mapToItemsDTO(marks)); | ||
} | ||
|
||
@Operation( | ||
summary = "Получить элементы с сгенерированными оценками по убыванию рейтинга для пользователя" | ||
) | ||
@GetMapping("/generated") | ||
public ResponseEntity<ItemsDTO> getAllGeneratedMarks(@NotNull @RequestParam long userId, | ||
@NotNull @RequestParam int offset, | ||
@NotNull @RequestParam int limit) { | ||
List<Mark> marks = markService.getGeneratedMarks(userId, offset, limit); | ||
return ResponseEntity.ok(Mapper.mapToItemsDTO(marks)); | ||
} | ||
|
||
@Operation( | ||
summary = "Получить схожие элементы с переданным по убыванию рейтинга оценки сходства" | ||
) | ||
@GetMapping("/item") | ||
public ResponseEntity<ItemsDTO> getSimilarityItems(@NotNull @RequestParam long itemId, | ||
@NotNull @RequestParam int offset, | ||
@NotNull @RequestParam int limit) { | ||
List<Mark> marks = markService.getGeneratedMarks(itemId, offset, limit); | ||
return ResponseEntity.ok(Mapper.mapToItemsDTO(marks)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.brash.dto.web; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
import java.util.List; | ||
|
||
public record ItemsDTO ( | ||
@NotNull List<Long> ids | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.brash.exception; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@RestControllerAdvice | ||
public class ControllerAdvice { | ||
|
||
@ExceptionHandler(Exception.class) | ||
@ResponseStatus(HttpStatus.BAD_REQUEST) | ||
ExceptionBodyResponse handleExceptions(Exception e) { | ||
return new ExceptionBodyResponse(e.getMessage()); | ||
} | ||
|
||
|
||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/brash/exception/ExceptionBodyResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.brash.exception; | ||
|
||
import lombok.Data; | ||
|
||
import java.util.Date; | ||
import java.util.Map; | ||
|
||
@Data | ||
public class ExceptionBodyResponse { | ||
private String message; | ||
private Map<String, String> errors; | ||
private long creationTime; | ||
|
||
public ExceptionBodyResponse(String message) { | ||
this.message = message; | ||
this.creationTime = new Date().getTime(); | ||
} | ||
|
||
public ExceptionBodyResponse(String message, Map<String, String> errors) { | ||
this.message = message; | ||
this.errors = errors; | ||
this.creationTime = new Date().getTime(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.brash.filter; | ||
|
||
import com.brash.data.entity.Item; | ||
import com.brash.filter.data.ItemNeighbours; | ||
import com.brash.filter.data.SimpleSimilarItems; | ||
import com.brash.filter.data.UserNeighbours; | ||
import com.brash.util.PageableUtils; | ||
import lombok.Getter; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.awt.print.Pageable; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@Component | ||
public class SimilarityStorage { | ||
|
||
@Getter | ||
private ItemNeighbours itemNeighbours; | ||
|
||
@Getter | ||
private UserNeighbours userNeighbours; | ||
|
||
private LocalDateTime lastUpdate; | ||
|
||
public List<SimpleSimilarItems> getNeighbours(Item item) { | ||
return itemNeighbours.neighbours().get(item); | ||
} | ||
|
||
public List<SimpleSimilarItems> getNeighbours(Item item, int offset, int limit) { | ||
List<SimpleSimilarItems> similarItems = itemNeighbours.neighbours().get(item); | ||
return PageableUtils.getPage(similarItems, offset, limit); | ||
} | ||
|
||
public void setItemNeighbours(ItemNeighbours itemNeighbours) { | ||
this.itemNeighbours = itemNeighbours; | ||
lastUpdate = LocalDateTime.now(); | ||
} | ||
|
||
public void setUserNeighbours(UserNeighbours userNeighbours) { | ||
this.userNeighbours = userNeighbours; | ||
lastUpdate = LocalDateTime.now(); | ||
} | ||
} |
Oops, something went wrong.