added statistics for create and found posts
This commit is contained in:
@@ -35,6 +35,7 @@ import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Service
|
||||
@@ -50,6 +51,7 @@ public class PostService {
|
||||
private final FavoriteRepository favoriteRepository;
|
||||
private final FileStorageService fileStorageService;
|
||||
private final ContentModerationFacade contentModerationFacade;
|
||||
private final StatisticsService statisticsService;
|
||||
|
||||
public PostRequest create(PostRequest request, List<MultipartFile> images) {
|
||||
|
||||
@@ -75,6 +77,7 @@ public class PostService {
|
||||
imageRepository.save(img);
|
||||
}
|
||||
}
|
||||
statisticsService.incrementCreated();
|
||||
return request;
|
||||
}
|
||||
|
||||
@@ -116,7 +119,7 @@ public class PostService {
|
||||
});
|
||||
}
|
||||
|
||||
public List <PostResponse> getById(Long id) {
|
||||
public List<PostResponse> getById(Long id) {
|
||||
List<Post> posts = repository.findByUserId(id);
|
||||
|
||||
List<Long> postIds = posts.stream()
|
||||
@@ -150,7 +153,8 @@ public class PostService {
|
||||
.toList();
|
||||
}
|
||||
|
||||
public PostResponse update(Long id, PostRequest request, List<MultipartFile> images, List<String> existingUrls) {
|
||||
public PostResponse update(Long id, PostRequest request, List<MultipartFile> images,
|
||||
List<String> existingUrls) {
|
||||
Post post = repository.findById(id)
|
||||
.orElseThrow(() -> new ApiException(
|
||||
ErrorCode.NOT_FOUND,
|
||||
@@ -234,6 +238,7 @@ public class PostService {
|
||||
repository.delete(post);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public PostResponse updateStatus(Long id, String statusString) {
|
||||
// Find the post
|
||||
Post post = repository.findById(id)
|
||||
@@ -264,10 +269,13 @@ public class PostService {
|
||||
);
|
||||
}
|
||||
|
||||
if (post.getStatus() != PostStatus.CLOSED && statusString.equals(PostStatus.CLOSED.toString())) {
|
||||
statisticsService.incrementFound();
|
||||
}
|
||||
|
||||
// Update status
|
||||
post.setStatus(newStatus);
|
||||
Post updated = repository.save(post);
|
||||
|
||||
// Convert to response with like count
|
||||
PostResponse response = mapper.toResponse(updated);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user