- 작성자 아바타: post/comment 조회 시 member JOIN(google_picture/profile_image),
목록·상세·댓글 응답에 노출
- 추천/비추천: post_vote/comment_vote 테이블 + 토글 API
(POST /board/posts|comments/{id}/vote), 게시글/댓글 응답에 up/down/myVote
- 추천자 목록: GET /board/posts/{id}/recommenders + PostDetail.recommenders
- 포인트: member.points + point_history. 글/댓글 작성 시 10P, 하루 3회 한도(합산).
PointService, GET /auth/points, MemberResponse.points 노출
- @MapperScan 에 point.mapper 추가, AuthController WebMvc 테스트 MockBean 보강
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -7,7 +7,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
@MapperScan({"com.sb.web.user.mapper", "com.sb.web.auth.mapper", "com.sb.web.board.mapper", "com.sb.web.account.mapper", "com.sb.web.admin.mapper"})
|
||||
@MapperScan({"com.sb.web.user.mapper", "com.sb.web.auth.mapper", "com.sb.web.board.mapper", "com.sb.web.account.mapper", "com.sb.web.admin.mapper", "com.sb.web.point.mapper"})
|
||||
public class SbBtApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -29,6 +29,7 @@ public class AuthController {
|
||||
|
||||
private final AuthService authService;
|
||||
private final com.sb.web.admin.service.AppSettingService appSettingService;
|
||||
private final com.sb.web.point.PointService pointService;
|
||||
|
||||
/** 회원가입 허용 여부 (비보호) — 프론트가 가입 진입 전에 차단 표시용 */
|
||||
@GetMapping("/signup-enabled")
|
||||
@@ -79,6 +80,13 @@ public class AuthController {
|
||||
return current;
|
||||
}
|
||||
|
||||
/** 현재 사용자 활동 포인트 (최신값 — 게시판 작성으로 수시 변동) */
|
||||
@GetMapping("/points")
|
||||
public java.util.Map<String, Long> points(
|
||||
@RequestAttribute(AuthInterceptor.CURRENT_MEMBER) SessionUser current) {
|
||||
return java.util.Map.of("points", pointService.getPoints(current.getId()));
|
||||
}
|
||||
|
||||
@PutMapping("/password")
|
||||
public ResponseEntity<Void> changePassword(
|
||||
@Valid @RequestBody PasswordChangeRequest req,
|
||||
|
||||
@@ -30,6 +30,7 @@ public class Member implements Serializable {
|
||||
private String profileImage; // 사용자 지정 프로필 이미지(data URL). 우선순위: profileImage > googlePicture > 이니셜
|
||||
private String role; // USER / ADMIN
|
||||
private String plan; // FREE / PREMIUM (멤버십)
|
||||
private Long points; // 활동 포인트 (게시판 글/댓글 작성 보상)
|
||||
private String status; // ACTIVE / SUSPENDED / WITHDRAWN
|
||||
private LocalDateTime createdAt;
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@@ -18,6 +18,7 @@ public class MemberResponse {
|
||||
private String provider;
|
||||
private String role;
|
||||
private String plan; // FREE / PREMIUM
|
||||
private Long points; // 활동 포인트
|
||||
private String googlePicture; // 구글 아바타 URL
|
||||
private String profileImage; // 사용자 지정 프로필 이미지(data URL)
|
||||
|
||||
@@ -30,6 +31,7 @@ public class MemberResponse {
|
||||
.provider(m.getProvider())
|
||||
.role(m.getRole())
|
||||
.plan(m.getPlan())
|
||||
.points(m.getPoints())
|
||||
.googlePicture(m.getGooglePicture())
|
||||
.profileImage(m.getProfileImage())
|
||||
.build();
|
||||
|
||||
@@ -8,7 +8,10 @@ import com.sb.web.board.dto.PageResponse;
|
||||
import com.sb.web.board.dto.PostDetail;
|
||||
import com.sb.web.board.dto.PostRequest;
|
||||
import com.sb.web.board.dto.PostSummary;
|
||||
import com.sb.web.board.dto.Recommender;
|
||||
import com.sb.web.board.dto.TagCategoryResponse;
|
||||
import com.sb.web.board.dto.VoteRequest;
|
||||
import com.sb.web.board.dto.VoteResponse;
|
||||
import com.sb.web.board.service.BoardService;
|
||||
import com.sb.web.board.service.TagService;
|
||||
import jakarta.validation.Valid;
|
||||
@@ -143,4 +146,28 @@ public class BoardController {
|
||||
boardService.deleteComment(commentId, current);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
/** 게시글 추천/비추천 (토글) */
|
||||
@PostMapping("/posts/{id}/vote")
|
||||
public VoteResponse votePost(
|
||||
@PathVariable Long id,
|
||||
@Valid @RequestBody VoteRequest req,
|
||||
@RequestAttribute(AuthInterceptor.CURRENT_MEMBER) SessionUser current) {
|
||||
return boardService.votePost(id, req.getType(), current);
|
||||
}
|
||||
|
||||
/** 게시글 추천(👍)한 사람 목록 */
|
||||
@GetMapping("/posts/{id}/recommenders")
|
||||
public List<Recommender> recommenders(@PathVariable Long id) {
|
||||
return boardService.recommenders(id);
|
||||
}
|
||||
|
||||
/** 댓글 추천/비추천 (토글) */
|
||||
@PostMapping("/comments/{commentId}/vote")
|
||||
public VoteResponse voteComment(
|
||||
@PathVariable Long commentId,
|
||||
@Valid @RequestBody VoteRequest req,
|
||||
@RequestAttribute(AuthInterceptor.CURRENT_MEMBER) SessionUser current) {
|
||||
return boardService.voteComment(commentId, req.getType(), current);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ public class Comment implements Serializable {
|
||||
private Long postId;
|
||||
private Long authorId;
|
||||
private String authorName;
|
||||
private String authorGooglePicture; // 조회 시 member JOIN (저장 안 함)
|
||||
private String authorProfileImage; // 조회 시 member JOIN (저장 안 함)
|
||||
private String content;
|
||||
private LocalDateTime createdAt;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ public class Post implements Serializable {
|
||||
private String content;
|
||||
private Long authorId;
|
||||
private String authorName;
|
||||
private String authorGooglePicture; // 조회 시 member JOIN (저장 안 함)
|
||||
private String authorProfileImage; // 조회 시 member JOIN (저장 안 함)
|
||||
private Integer viewCount;
|
||||
private Boolean blocked;
|
||||
private String blockReason;
|
||||
|
||||
@@ -16,16 +16,25 @@ public class CommentResponse {
|
||||
private Long id;
|
||||
private Long authorId;
|
||||
private String authorName;
|
||||
private String authorGooglePicture;
|
||||
private String authorProfileImage;
|
||||
private String content;
|
||||
private LocalDateTime createdAt;
|
||||
private Integer upCount; // 추천 수
|
||||
private Integer downCount; // 비추천 수
|
||||
private String myVote; // 현재 사용자의 투표: UP / DOWN / null
|
||||
|
||||
public static CommentResponse from(Comment c) {
|
||||
return CommentResponse.builder()
|
||||
.id(c.getId())
|
||||
.authorId(c.getAuthorId())
|
||||
.authorName(c.getAuthorName())
|
||||
.authorGooglePicture(c.getAuthorGooglePicture())
|
||||
.authorProfileImage(c.getAuthorProfileImage())
|
||||
.content(c.getContent())
|
||||
.createdAt(c.getCreatedAt())
|
||||
.upCount(0)
|
||||
.downCount(0)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.sb.web.board.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 한 게시글의 댓글별 추천/비추천 집계 + 현재 사용자 투표 (N+1 방지용 일괄 조회 결과).
|
||||
*/
|
||||
@Data
|
||||
public class CommentVoteSummary {
|
||||
|
||||
private Long commentId;
|
||||
private int upCount;
|
||||
private int downCount;
|
||||
private String myVote; // UP / DOWN / null
|
||||
}
|
||||
@@ -19,6 +19,8 @@ public class PostDetail {
|
||||
private String content;
|
||||
private Long authorId;
|
||||
private String authorName;
|
||||
private String authorGooglePicture;
|
||||
private String authorProfileImage;
|
||||
private Integer viewCount;
|
||||
private Boolean blocked;
|
||||
private String blockReason;
|
||||
@@ -28,6 +30,10 @@ public class PostDetail {
|
||||
private LocalDateTime updatedAt;
|
||||
private List<String> tags;
|
||||
private List<CommentResponse> comments;
|
||||
private Integer upCount; // 추천 수
|
||||
private Integer downCount; // 비추천 수
|
||||
private String myVote; // 현재 사용자의 투표: UP / DOWN / null
|
||||
private List<Recommender> recommenders; // 추천(👍)한 사람 목록 (아바타 표기용)
|
||||
|
||||
public static PostDetail of(Post p, List<String> tags, List<CommentResponse> comments) {
|
||||
return PostDetail.builder()
|
||||
@@ -36,6 +42,8 @@ public class PostDetail {
|
||||
.content(p.getContent())
|
||||
.authorId(p.getAuthorId())
|
||||
.authorName(p.getAuthorName())
|
||||
.authorGooglePicture(p.getAuthorGooglePicture())
|
||||
.authorProfileImage(p.getAuthorProfileImage())
|
||||
.viewCount(p.getViewCount())
|
||||
.blocked(Boolean.TRUE.equals(p.getBlocked()))
|
||||
.blockReason(p.getBlockReason())
|
||||
|
||||
@@ -13,9 +13,13 @@ public class PostSummary {
|
||||
|
||||
private Long id;
|
||||
private String title;
|
||||
private Long authorId;
|
||||
private String authorName;
|
||||
private String authorGooglePicture;
|
||||
private String authorProfileImage;
|
||||
private Integer viewCount;
|
||||
private Integer commentCount;
|
||||
private Integer upCount; // 추천 수
|
||||
private Boolean blocked;
|
||||
private Boolean notice;
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.sb.web.board.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 추천(👍)한 사람 (본문 하단 아바타·이름 표기용).
|
||||
*/
|
||||
@Data
|
||||
public class Recommender {
|
||||
|
||||
private Long memberId;
|
||||
private String name;
|
||||
private String googlePicture;
|
||||
private String profileImage;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.sb.web.board.dto;
|
||||
|
||||
import jakarta.validation.constraints.Pattern;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 추천/비추천 요청. 같은 표를 다시 보내면 취소(토글), 반대면 전환.
|
||||
*/
|
||||
@Data
|
||||
public class VoteRequest {
|
||||
|
||||
@Pattern(regexp = "UP|DOWN", message = "투표는 UP 또는 DOWN 이어야 합니다.")
|
||||
private String type;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.sb.web.board.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 추천/비추천 후 최신 집계 + 현재 사용자 상태.
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class VoteResponse {
|
||||
|
||||
private int upCount;
|
||||
private int downCount;
|
||||
private String myVote; // UP / DOWN / null
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.sb.web.board.mapper;
|
||||
|
||||
import com.sb.web.board.dto.CommentVoteSummary;
|
||||
import com.sb.web.board.dto.Recommender;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 게시글/댓글 추천·비추천(post_vote / comment_vote) 매퍼.
|
||||
*/
|
||||
@Mapper
|
||||
public interface VoteMapper {
|
||||
|
||||
// ===== 게시글 =====
|
||||
/** 현재 사용자의 게시글 투표(UP/DOWN) 또는 null */
|
||||
String findPostVote(@Param("postId") Long postId, @Param("memberId") Long memberId);
|
||||
|
||||
/** 투표 등록/변경 (INSERT … ON DUPLICATE KEY UPDATE) */
|
||||
int upsertPostVote(@Param("postId") Long postId, @Param("memberId") Long memberId, @Param("type") String type);
|
||||
|
||||
int deletePostVote(@Param("postId") Long postId, @Param("memberId") Long memberId);
|
||||
|
||||
int countPostVotes(@Param("postId") Long postId, @Param("type") String type);
|
||||
|
||||
/** 추천(👍)한 사람 목록 (최신순) */
|
||||
List<Recommender> findPostRecommenders(@Param("postId") Long postId);
|
||||
|
||||
int deletePostVotesByPost(@Param("postId") Long postId);
|
||||
|
||||
// ===== 댓글 =====
|
||||
String findCommentVote(@Param("commentId") Long commentId, @Param("memberId") Long memberId);
|
||||
|
||||
int upsertCommentVote(@Param("commentId") Long commentId, @Param("memberId") Long memberId, @Param("type") String type);
|
||||
|
||||
int deleteCommentVote(@Param("commentId") Long commentId, @Param("memberId") Long memberId);
|
||||
|
||||
int countCommentVotes(@Param("commentId") Long commentId, @Param("type") String type);
|
||||
|
||||
/** 한 게시글의 댓글별 집계 + 현재 사용자 투표 (일괄) */
|
||||
List<CommentVoteSummary> findCommentVoteSummary(@Param("postId") Long postId, @Param("memberId") Long memberId);
|
||||
|
||||
int deleteCommentVotesByComment(@Param("commentId") Long commentId);
|
||||
|
||||
/** 게시글 삭제 시 그 글의 모든 댓글 투표 정리 */
|
||||
int deleteCommentVotesByPost(@Param("postId") Long postId);
|
||||
}
|
||||
@@ -5,14 +5,19 @@ import com.sb.web.board.domain.Comment;
|
||||
import com.sb.web.board.domain.Post;
|
||||
import com.sb.web.board.dto.CommentRequest;
|
||||
import com.sb.web.board.dto.CommentResponse;
|
||||
import com.sb.web.board.dto.CommentVoteSummary;
|
||||
import com.sb.web.board.dto.PageResponse;
|
||||
import com.sb.web.board.dto.PostDetail;
|
||||
import com.sb.web.board.dto.PostRequest;
|
||||
import com.sb.web.board.dto.PostSummary;
|
||||
import com.sb.web.board.dto.Recommender;
|
||||
import com.sb.web.board.dto.VoteResponse;
|
||||
import com.sb.web.board.mapper.CommentMapper;
|
||||
import com.sb.web.board.mapper.PostMapper;
|
||||
import com.sb.web.board.mapper.TagMapper;
|
||||
import com.sb.web.board.mapper.VoteMapper;
|
||||
import com.sb.web.common.exception.ApiException;
|
||||
import com.sb.web.point.PointService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.http.HttpStatus;
|
||||
@@ -20,7 +25,9 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@@ -33,10 +40,14 @@ public class BoardService {
|
||||
private final PostMapper postMapper;
|
||||
private final TagMapper tagMapper;
|
||||
private final CommentMapper commentMapper;
|
||||
private final VoteMapper voteMapper;
|
||||
private final PointService pointService;
|
||||
private final RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
/** 같은 사용자가 이 시간 내 재열람 시 조회수를 다시 올리지 않음 */
|
||||
private static final Duration VIEW_DEDUP_TTL = Duration.ofHours(24);
|
||||
private static final String UP = "UP";
|
||||
private static final String DOWN = "DOWN";
|
||||
|
||||
/* ===================== 게시글 ===================== */
|
||||
|
||||
@@ -80,7 +91,7 @@ public class BoardService {
|
||||
postMapper.increaseViewCount(id);
|
||||
post.setViewCount(post.getViewCount() + 1);
|
||||
}
|
||||
return assemble(post);
|
||||
return assemble(post, viewer);
|
||||
}
|
||||
|
||||
/** 게시글 열람 제한/해제 (관리자 전용) */
|
||||
@@ -122,7 +133,8 @@ public class BoardService {
|
||||
.build();
|
||||
postMapper.insert(post);
|
||||
applyTags(post.getId(), req.getTagIds());
|
||||
return assemble(mustFindPost(post.getId()));
|
||||
pointService.awardBoardWrite(author.getId()); // 글 작성 보상(일 3회 한도)
|
||||
return assemble(mustFindPost(post.getId()), author);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@@ -144,13 +156,16 @@ public class BoardService {
|
||||
|
||||
tagMapper.deletePostTagsByPostId(id);
|
||||
applyTags(id, req.getTagIds());
|
||||
return assemble(mustFindPost(id));
|
||||
return assemble(mustFindPost(id), user);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void delete(Long id, SessionUser user) {
|
||||
Post post = mustFindPost(id);
|
||||
assertCanModify(post.getAuthorId(), user);
|
||||
// 투표 정리(댓글 투표는 댓글 삭제 전에 — 서브쿼리가 comment 참조)
|
||||
voteMapper.deleteCommentVotesByPost(id);
|
||||
voteMapper.deletePostVotesByPost(id);
|
||||
tagMapper.deletePostTagsByPostId(id);
|
||||
commentMapper.deleteByPostId(id);
|
||||
postMapper.delete(id);
|
||||
@@ -171,6 +186,7 @@ public class BoardService {
|
||||
.content(req.getContent())
|
||||
.build();
|
||||
commentMapper.insert(comment);
|
||||
pointService.awardBoardWrite(author.getId()); // 댓글 작성 보상(일 3회 한도, 글과 합산)
|
||||
return CommentResponse.from(commentMapper.findById(comment.getId()));
|
||||
}
|
||||
|
||||
@@ -181,9 +197,57 @@ public class BoardService {
|
||||
throw new ApiException(HttpStatus.NOT_FOUND, "댓글을 찾을 수 없습니다.");
|
||||
}
|
||||
assertCanModify(comment.getAuthorId(), user);
|
||||
voteMapper.deleteCommentVotesByComment(commentId);
|
||||
commentMapper.delete(commentId);
|
||||
}
|
||||
|
||||
/* ===================== 추천/비추천 ===================== */
|
||||
|
||||
/** 게시글 추천/비추천 토글. 같은 표 재요청 시 취소, 반대면 전환. */
|
||||
@Transactional
|
||||
public VoteResponse votePost(Long postId, String type, SessionUser user) {
|
||||
mustFindPost(postId);
|
||||
Long memberId = user.getId();
|
||||
String existing = voteMapper.findPostVote(postId, memberId);
|
||||
boolean cancel = type.equals(existing);
|
||||
if (cancel) {
|
||||
voteMapper.deletePostVote(postId, memberId);
|
||||
} else {
|
||||
voteMapper.upsertPostVote(postId, memberId, type);
|
||||
}
|
||||
return new VoteResponse(
|
||||
voteMapper.countPostVotes(postId, UP),
|
||||
voteMapper.countPostVotes(postId, DOWN),
|
||||
cancel ? null : type);
|
||||
}
|
||||
|
||||
/** 댓글 추천/비추천 토글 */
|
||||
@Transactional
|
||||
public VoteResponse voteComment(Long commentId, String type, SessionUser user) {
|
||||
Comment comment = commentMapper.findById(commentId);
|
||||
if (comment == null) {
|
||||
throw new ApiException(HttpStatus.NOT_FOUND, "댓글을 찾을 수 없습니다.");
|
||||
}
|
||||
Long memberId = user.getId();
|
||||
String existing = voteMapper.findCommentVote(commentId, memberId);
|
||||
boolean cancel = type.equals(existing);
|
||||
if (cancel) {
|
||||
voteMapper.deleteCommentVote(commentId, memberId);
|
||||
} else {
|
||||
voteMapper.upsertCommentVote(commentId, memberId, type);
|
||||
}
|
||||
return new VoteResponse(
|
||||
voteMapper.countCommentVotes(commentId, UP),
|
||||
voteMapper.countCommentVotes(commentId, DOWN),
|
||||
cancel ? null : type);
|
||||
}
|
||||
|
||||
/** 추천(👍)한 사람 목록 (본문 하단 표기/모달용) */
|
||||
public List<Recommender> recommenders(Long postId) {
|
||||
mustFindPost(postId);
|
||||
return voteMapper.findPostRecommenders(postId);
|
||||
}
|
||||
|
||||
/* ===================== 태그 ===================== */
|
||||
|
||||
public List<String> allTags() {
|
||||
@@ -192,11 +256,33 @@ public class BoardService {
|
||||
|
||||
/* ===================== 내부 ===================== */
|
||||
|
||||
private PostDetail assemble(Post post) {
|
||||
List<String> tags = tagMapper.findNamesByPostId(post.getId());
|
||||
List<CommentResponse> comments = commentMapper.findByPostId(post.getId())
|
||||
.stream().map(CommentResponse::from).toList();
|
||||
return PostDetail.of(post, tags, comments);
|
||||
private PostDetail assemble(Post post, SessionUser viewer) {
|
||||
Long postId = post.getId();
|
||||
Long viewerId = viewer == null ? null : viewer.getId();
|
||||
List<String> tags = tagMapper.findNamesByPostId(postId);
|
||||
|
||||
// 댓글별 추천/비추천 집계를 한 번에 조회(N+1 방지)
|
||||
Map<Long, CommentVoteSummary> voteByComment = new HashMap<>();
|
||||
for (CommentVoteSummary s : voteMapper.findCommentVoteSummary(postId, viewerId)) {
|
||||
voteByComment.put(s.getCommentId(), s);
|
||||
}
|
||||
List<CommentResponse> comments = commentMapper.findByPostId(postId).stream().map(c -> {
|
||||
CommentResponse cr = CommentResponse.from(c);
|
||||
CommentVoteSummary s = voteByComment.get(c.getId());
|
||||
if (s != null) {
|
||||
cr.setUpCount(s.getUpCount());
|
||||
cr.setDownCount(s.getDownCount());
|
||||
cr.setMyVote(s.getMyVote());
|
||||
}
|
||||
return cr;
|
||||
}).toList();
|
||||
|
||||
PostDetail detail = PostDetail.of(post, tags, comments);
|
||||
detail.setUpCount(voteMapper.countPostVotes(postId, UP));
|
||||
detail.setDownCount(voteMapper.countPostVotes(postId, DOWN));
|
||||
detail.setMyVote(viewerId == null ? null : voteMapper.findPostVote(postId, viewerId));
|
||||
detail.setRecommenders(voteMapper.findPostRecommenders(postId));
|
||||
return detail;
|
||||
}
|
||||
|
||||
/** 선택된 태그 ID 중 실제 DB에 존재하는 것만 게시글에 연결 (신규 태그 생성 없음) */
|
||||
|
||||
@@ -25,7 +25,7 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
// 인증: 로그인 필요한 경로 (관리자 경로 포함 — SessionUser 세팅용으로 먼저 실행)
|
||||
registry.addInterceptor(authInterceptor)
|
||||
.addPathPatterns("/api/auth/me", "/api/auth/logout", "/api/auth/password",
|
||||
.addPathPatterns("/api/auth/me", "/api/auth/points", "/api/auth/logout", "/api/auth/password",
|
||||
"/api/auth/verify-password", "/api/auth/profile", "/api/auth/profile-image",
|
||||
"/api/board/**", "/api/admin/**", "/api/account/**");
|
||||
// 인가: 관리자 전용 경로 (authInterceptor 다음에 실행되어 role 검사)
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.sb.web.point;
|
||||
|
||||
import com.sb.web.point.mapper.PointMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 활동 포인트 적립/조회.
|
||||
* 게시판 글/댓글 작성 시 10점, 하루 3회까지만 지급(글+댓글 합산).
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PointService {
|
||||
|
||||
private final PointMapper pointMapper;
|
||||
|
||||
public static final int BOARD_WRITE_POINT = 10;
|
||||
public static final int BOARD_WRITE_DAILY_LIMIT = 3;
|
||||
public static final String REASON_BOARD_WRITE = "BOARD_WRITE";
|
||||
|
||||
/**
|
||||
* 게시판 글/댓글 작성 보상. 오늘 지급 횟수가 한도 미만일 때만 지급한다.
|
||||
* @return 지급되면 지급 포인트, 한도 초과로 미지급이면 0
|
||||
*/
|
||||
@Transactional
|
||||
public int awardBoardWrite(Long memberId) {
|
||||
int today = pointMapper.countTodayGrants(memberId, REASON_BOARD_WRITE);
|
||||
if (today >= BOARD_WRITE_DAILY_LIMIT) {
|
||||
return 0;
|
||||
}
|
||||
pointMapper.insertHistory(memberId, BOARD_WRITE_POINT, REASON_BOARD_WRITE);
|
||||
pointMapper.addPoints(memberId, BOARD_WRITE_POINT);
|
||||
return BOARD_WRITE_POINT;
|
||||
}
|
||||
|
||||
public long getPoints(Long memberId) {
|
||||
Long p = pointMapper.getPoints(memberId);
|
||||
return p == null ? 0L : p;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.sb.web.point.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* 포인트(member.points) 및 적립 이력(point_history) 매퍼.
|
||||
*/
|
||||
@Mapper
|
||||
public interface PointMapper {
|
||||
|
||||
/** 오늘 특정 사유로 지급된 횟수 (일일 한도 계산용) */
|
||||
int countTodayGrants(@Param("memberId") Long memberId, @Param("reason") String reason);
|
||||
|
||||
int insertHistory(@Param("memberId") Long memberId, @Param("amount") int amount, @Param("reason") String reason);
|
||||
|
||||
int addPoints(@Param("memberId") Long memberId, @Param("amount") int amount);
|
||||
|
||||
Long getPoints(@Param("memberId") Long memberId);
|
||||
}
|
||||
Reference in New Issue
Block a user