Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/posts/{postId}/answers")
@RequiredArgsConstructor
Expand All @@ -26,7 +23,7 @@ public class AnswerController {
// ๊ฒŒ์‹œ๊ธ€์˜ ๋‹ต๋ณ€ ๋ชฉ๋ก ์กฐํšŒ
@GetMapping
public ResponseEntity<Page<AnswerDto>> getAnswersByPostId(
@PathVariable Long postId,
@PathVariable("postId") Long postId,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "5") int size) {

Expand All @@ -38,7 +35,7 @@ public ResponseEntity<Page<AnswerDto>> getAnswersByPostId(
// ๋‹ต๋ณ€ ์ž‘์„ฑ
@PostMapping
public ResponseEntity<AnswerDto> createAnswer(
@PathVariable Long postId,
@PathVariable("postId") Long postId,
@RequestBody AnswerDto answerDto,
@AuthenticationPrincipal CustomUserDetails userDetails) {
AnswerDto createdAnswer = answerService.createAnswer(postId, answerDto, userDetails.getId());
Expand All @@ -48,19 +45,19 @@ public ResponseEntity<AnswerDto> createAnswer(
// ๋‹ต๋ณ€ ์ฑ„ํƒ
@PutMapping("/{answerId}/select")
public ResponseEntity<Void> selectAnswer(
@PathVariable Long postId,
@PathVariable Long answerId,
@PathVariable("postId") Long postId,
@PathVariable("answerId") Long answerId,
@AuthenticationPrincipal CustomUserDetails userDetails) {
// ๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž์˜ ID๋ฅผ ์„œ๋น„์Šค์— ์ „๋‹ฌ
answerService.selectAnswer(postId, answerId, userDetails.getId());
return ResponseEntity.ok().build();
}

// ๋‹ต๋ณ€ ์‚ญ์ œ (๊ด€๋ฆฌ์ž๋งŒ ๊ฐ€๋Šฅ)
// ๋‹ต๋ณ€ ์‚ญ์ œ (๊ด€๋ฆฌ์ž์™€ ์ž‘์„ฑ์ž๋งŒ ๊ฐ€๋Šฅ)
@DeleteMapping("/{answerId}")
public ResponseEntity<Void> deleteAnswer(
@PathVariable Long postId,
@PathVariable Long answerId,
@PathVariable("postId") Long postId,
@PathVariable("answerId") Long answerId,
@AuthenticationPrincipal CustomUserDetails userDetails) {
answerService.deleteAnswer(postId, answerId, userDetails.getId(), userDetails.getRole());
return ResponseEntity.noContent().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class AnswerDto {
private Long id;
private Long postId;
private Long userId;
private String nickname;
private String content;
private LocalDateTime createdAt;
private boolean selected;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface AnswerMapper {
@Mapping(target = "content", expression = "java(answer.getDisplayContent())")
@Mapping(source = "user.id", target = "userId")
@Mapping(source = "post.id", target = "postId")
@Mapping(source = "user.nickname", target = "nickname")
AnswerDto toDto(Answer answer);

Answer toEntity(AnswerDto answerDto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface AnswerRepository extends JpaRepository<Answer, Long> {
// ํŽ˜์ด์ง€๋„ค์ด์…˜ ์ ์šฉํ•œ ๋‹ต๋ณ€ ๋ชฉ๋ก ์กฐํšŒ (post ๊ฐ์ฒด ์‚ฌ์šฉ)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,13 @@
import com.hyetaekon.hyetaekon.user.entity.User;
import com.hyetaekon.hyetaekon.user.repository.UserRepository;
import com.hyetaekon.hyetaekon.user.service.UserPointService;
import jakarta.persistence.EntityNotFoundException;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class AnswerService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.hyetaekon.hyetaekon.publicservice.entity.PublicService;
import com.hyetaekon.hyetaekon.publicservice.repository.PublicServiceRepository;
import com.hyetaekon.hyetaekon.publicservice.service.PublicServiceHandler;
import com.hyetaekon.hyetaekon.publicservice.service.mongodb.ServiceMatchedHandler;
import com.hyetaekon.hyetaekon.user.entity.User;
import com.hyetaekon.hyetaekon.user.repository.UserRepository;
import jakarta.transaction.Transactional;
Expand All @@ -21,7 +22,7 @@ public class BookmarkService {
private final BookmarkRepository bookmarkRepository;
private final UserRepository userRepository;
private final PublicServiceRepository publicServiceRepository;
private final PublicServiceHandler publicServiceHandler;
private final ServiceMatchedHandler serviceMatchedHandler;

public void addBookmark(String serviceId, Long userId) {
User user = userRepository.findById(userId)
Expand All @@ -45,6 +46,8 @@ public void addBookmark(String serviceId, Long userId) {
// ๋ถ๋งˆํฌ ์ˆ˜ ์ฆ๊ฐ€
publicService.increaseBookmarkCount();
publicServiceRepository.save(publicService);
// ์บ์‹œ ๋ฌดํšจํ™” ์ถ”๊ฐ€
serviceMatchedHandler.refreshMatchedServicesCache(userId);
}

@Transactional
Expand All @@ -58,5 +61,7 @@ public void removeBookmark(String serviceId, Long userId) {
PublicService publicService = bookmark.getPublicService();
publicService.decreaseBookmarkCount();
publicServiceRepository.save(publicService);
// ์บ์‹œ ๋ฌดํšจํ™” ์ถ”๊ฐ€
serviceMatchedHandler.refreshMatchedServicesCache(userId);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.hyetaekon.hyetaekon.comment.controller;

import com.hyetaekon.hyetaekon.comment.dto.CommentCreateRequestDto;
import com.hyetaekon.hyetaekon.comment.dto.CommentDto;
import com.hyetaekon.hyetaekon.comment.dto.CommentListResponseDto;
import com.hyetaekon.hyetaekon.comment.service.CommentService;
import com.hyetaekon.hyetaekon.common.jwt.CustomUserDetails;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

Expand Down
21 changes: 0 additions & 21 deletions src/main/java/com/hyetaekon/hyetaekon/comment/dto/CommentDto.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.hyetaekon.hyetaekon.comment.mapper;

import com.hyetaekon.hyetaekon.comment.dto.CommentCreateRequestDto;
import com.hyetaekon.hyetaekon.comment.dto.CommentDto;
import com.hyetaekon.hyetaekon.comment.dto.CommentListResponseDto;
import com.hyetaekon.hyetaekon.comment.entity.Comment;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;

@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface CommentMapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;
Expand All @@ -20,6 +21,10 @@ public class BaseEntity {
@Column(name = "created_at", nullable = false, updatable = false, columnDefinition = "DATETIME(0)")
private LocalDateTime createdAt;

@LastModifiedDate
@Column(name = "modified_at", nullable = false, columnDefinition = "DATETIME(0)")
private LocalDateTime modifiedAt;

@Column(name = "deleted_at")
private LocalDateTime deletedAt;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class PostController {
// PostType์— ํ•ด๋‹นํ•˜๋Š” ๊ฒŒ์‹œ๊ธ€ ๋ชฉ๋ก ์กฐํšŒ
@GetMapping("/type")
public ResponseEntity<Page<PostListResponseDto>> getPosts(
@RequestParam(required = false, defaultValue = "์ „์ฒด") String postType,
@RequestParam(required = false, defaultValue = "ALL") String postType,
@RequestParam(required = false) String keyword, // ๐Ÿ”ฅ ์ œ๋ชฉ ๊ฒ€์ƒ‰ ์ถ”๊ฐ€
@RequestParam(defaultValue = "createdAt") String sortBy, // ๐Ÿ”ฅ ์ •๋ ฌ ํ‚ค์›Œ๋“œ ์ถ”๊ฐ€
@RequestParam(defaultValue = "DESC") String direction, // ๐Ÿ”ฅ ์ •๋ ฌ ๋ฐฉํ–ฅ ์ถ”๊ฐ€
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/hyetaekon/hyetaekon/post/entity/PostType.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,19 @@ public static PostType fromKoreanName(String koreanName) {
// ์ผ์น˜ํ•˜๋Š” ์ด๋ฆ„์ด ์—†๊ฑฐ๋‚˜ null์ธ ๊ฒฝ์šฐ ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ ALL ๋ฐ˜ํ™˜
return ALL;
}

/**
* ํด๋ผ์ด์–ธํŠธ์—์„œ ์˜๋ฌธ ํƒ€์ž… ์ฝ”๋“œ๋กœ ์ „์†ก๋œ PostType์„ ์ฐพ์Šต๋‹ˆ๋‹ค.
*/
public static PostType fromString(String typeCode) {
if (typeCode == null || typeCode.trim().isEmpty()) {
return ALL; // ๊ธฐ๋ณธ๊ฐ’
}

try {
return PostType.valueOf(typeCode.toUpperCase());
} catch (IllegalArgumentException e) {
return ALL;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ public PostDetailResponseDto createPost(PostCreateRequestDto requestDto, Long us
User user = userRepository.findById(userId)
.orElseThrow(() -> new EntityNotFoundException("์‚ฌ์šฉ์ž๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค: " + userId));

PostType postType = PostType.fromKoreanName(requestDto.getPostType());
PostType postType = PostType.fromString(requestDto.getPostType());
log.info("Received postType: '{}'", requestDto.getPostType());

Post post = postMapper.toEntity(requestDto);
post.setUser(user);
Expand Down Expand Up @@ -165,9 +166,9 @@ public PostDetailResponseDto updatePost(Long postId, PostUpdateRequestDto update
throw new AccessDeniedException("๊ฒŒ์‹œ๊ธ€ ์ˆ˜์ • ๊ถŒํ•œ์ด ์—†์Šต๋‹ˆ๋‹ค");
}

// PostType ๋ณ€ํ™˜
// ์˜๋ฌธ ํƒ€์ž… ์ฝ”๋“œ๋กœ PostType ์ฐพ๊ธฐ
if (updateDto.getPostType() != null) {
PostType postType = PostType.fromKoreanName(updateDto.getPostType());
PostType postType = PostType.fromString(updateDto.getPostType());
post.setPostType(postType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.hyetaekon.hyetaekon.userInterest.repository.UserInterestRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -88,4 +89,8 @@ public List<PublicServiceListResponseDto> getPersonalizedServices(Long userId, i
.collect(Collectors.toList());
}

@CacheEvict(value = "matchedServices", key = "#userId")
public void refreshMatchedServicesCache(Long userId) {
// ์บ์‹œ ๊ฐฑ์‹  ๋ฉ”์„œ๋“œ
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import com.fasterxml.jackson.annotation.JsonIgnore;
import com.hyetaekon.hyetaekon.common.util.BaseEntity;
import com.hyetaekon.hyetaekon.post.entity.Post;
import com.hyetaekon.hyetaekon.user.entity.User;
import jakarta.persistence.*;
Expand All @@ -15,7 +16,7 @@
@Builder(toBuilder = true)
@NoArgsConstructor
@AllArgsConstructor
public class Recommend {
public class Recommend extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
Expand Down