You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
4.2 KiB

package com.youlai.boot.mini.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.boot.common.annotation.Log;
import com.youlai.boot.common.annotation.RepeatSubmit;
import com.youlai.boot.common.enums.ActionTypeEnum;
import com.youlai.boot.common.enums.LogModuleEnum;
import com.youlai.boot.common.result.Result;
import com.youlai.boot.framework.security.util.SecurityUtils;
import com.youlai.boot.mini.model.form.CommentLikeForm;
import com.youlai.boot.mini.model.form.DeleteStrayAnimalNoteCommentForm;
import com.youlai.boot.mini.model.form.StrayAnimalNoteCommentForm;
import com.youlai.boot.mini.model.query.AnimalNoteFirstLevelCommentQueryParam;
import com.youlai.boot.mini.model.query.AnimalNoteSecondLevelCommentQueryParam;
import com.youlai.boot.mini.model.vo.AnimalNoteFirstLevelCommentVO;
import com.youlai.boot.mini.model.vo.AnimalNoteSecondLevelCommentVO;
import com.youlai.boot.mini.model.vo.StrayAnimalNoteCommentVO;
import java.util.Map;
import com.youlai.boot.mini.service.StrayAnimalNoteCommentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@Tag(name = "流浪动物笔记评论相关接口")
@RestController
@RequestMapping("/api/v1/mini/noteComment")
@RequiredArgsConstructor
public class StrayAnimalNoteCommentController {
private final StrayAnimalNoteCommentService strayAnimalNoteCommentService;
@Operation(summary = "笔记评论接口")
@PostMapping(value = "add")
@RepeatSubmit
@Log(module = LogModuleEnum.STRAY_ANIMAL_NOTE_COMMENT, value = ActionTypeEnum.INSERT)
public Result<?> addNoteComment(
@Valid @RequestBody StrayAnimalNoteCommentForm formData
) {
StrayAnimalNoteCommentVO vo = strayAnimalNoteCommentService.addNoteComment(formData);
return Result.success(vo);
}
@Operation(summary = "删除笔记评论接口")
@PostMapping(value = "delete")
@PreAuthorize("isAuthenticated()")
@RepeatSubmit
@Log(module = LogModuleEnum.STRAY_ANIMAL_NOTE_COMMENT, value = ActionTypeEnum.DELETE)
public Result<?> deleteNoteComment(
@Valid @RequestBody DeleteStrayAnimalNoteCommentForm formData
) {
Long userId = SecurityUtils.getUserId();
strayAnimalNoteCommentService.deleteNoteComment(formData, userId);
return Result.success();
}
@Operation(summary = "分页查询笔记一级评论列表接口")
@PostMapping(value = "firstLevel/list")
@Log(module = LogModuleEnum.STRAY_ANIMAL_NOTE_COMMENT, value = ActionTypeEnum.LIST)
public Result<IPage<AnimalNoteFirstLevelCommentVO>> getFirstLevelCommentList(
@Valid @RequestBody AnimalNoteFirstLevelCommentQueryParam queryParam
) {
Long userId = SecurityUtils.getUserId();
IPage<AnimalNoteFirstLevelCommentVO> result = strayAnimalNoteCommentService.getFirstLevelCommentList(queryParam, userId);
return Result.success(result);
}
@Operation(summary = "分页查询笔记二级评论列表接口")
@PostMapping(value = "secondLevel/list")
@Log(module = LogModuleEnum.STRAY_ANIMAL_NOTE_COMMENT, value = ActionTypeEnum.LIST)
public Result<IPage<AnimalNoteSecondLevelCommentVO>> getSecondLevelCommentList(
@Valid @RequestBody AnimalNoteSecondLevelCommentQueryParam queryParam
) {
Long userId = SecurityUtils.getUserId();
IPage<AnimalNoteSecondLevelCommentVO> result = strayAnimalNoteCommentService.getSecondLevelCommentList(queryParam, userId);
return Result.success(result);
}
@Operation(summary = "评论点赞/取消点赞接口")
@PostMapping(value = "like/toggle")
@PreAuthorize("isAuthenticated()")
@RepeatSubmit(expire = 1)
@Log(module = LogModuleEnum.STRAY_ANIMAL_NOTE_COMMENT, value = ActionTypeEnum.UPDATE)
public Result<Map<String, Object>> toggleLike(
@Valid @RequestBody CommentLikeForm form
) {
Long userId = SecurityUtils.getUserId();
Map<String, Object> result = strayAnimalNoteCommentService.toggleLike(form, userId);
return Result.success(result);
}
}