Răsfoiți Sursa

2d展厅分享,点赞

licailing 3 ani în urmă
părinte
comite
b4e040d272

+ 3 - 1
src/main/java/com/izouma/nineth/domain/Showroom.java

@@ -21,7 +21,9 @@ import java.util.List;
 @Entity
 @Table(indexes = {
         @Index(columnList = "userId"),
-        @Index(columnList = "assetId")
+        @Index(columnList = "assetId"),
+        @Index(columnList = "likes"),
+        @Index(columnList = "share")
 })
 @Where(clause = "del = 0")
 @ApiModel("展厅")

+ 5 - 0
src/main/java/com/izouma/nineth/repo/ShowroomRepo.java

@@ -23,4 +23,9 @@ public interface ShowroomRepo extends JpaRepository<Showroom, Long>, JpaSpecific
     Optional<Showroom> findByUserIdAndAssetId(Long userId, Long assetId);
 
     Optional<Showroom> findByAssetId(Long assetId);
+
+    @Query("update Showroom t set t.share = t.share + ?2 where t.id = ?1")
+    @Modifying
+    @Transactional
+    void addShare(Long id, int num);
 }

+ 2 - 0
src/main/java/com/izouma/nineth/web/NewsController.java

@@ -13,6 +13,7 @@ import com.izouma.nineth.utils.ObjUtils;
 import com.izouma.nineth.utils.SecurityUtils;
 import com.izouma.nineth.utils.excel.ExcelUtils;
 import lombok.AllArgsConstructor;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.data.domain.Page;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
@@ -48,6 +49,7 @@ public class NewsController extends BaseController {
     }
 
     @GetMapping("/get/{id}")
+    @Cacheable("news")
     public News get(@PathVariable Long id) {
         News news = newsRepo.findById(id).orElseThrow(new BusinessException("无记录"));
         User user = SecurityUtils.getAuthenticatedUser();

+ 12 - 0
src/main/java/com/izouma/nineth/web/NewsLikeController.java

@@ -73,5 +73,17 @@ public class NewsLikeController extends BaseController {
     public void unlike(@PathVariable Long id) {
         newsLikeService.unlike(SecurityUtils.getAuthenticatedUser().getId(), id);
     }
+
+    @GetMapping("/{id}/likeRoom")
+    @ApiOperation("点赞")
+    public void likeRoom(@PathVariable Long id) {
+        newsLikeService.likeRoom(SecurityUtils.getAuthenticatedUser().getId(), id);
+    }
+
+    @GetMapping("/{id}/unlikeRoom")
+    @ApiOperation("取消点赞")
+    public void unlikeRoom(@PathVariable Long id) {
+        newsLikeService.unlikeRoom(SecurityUtils.getAuthenticatedUser().getId(), id);
+    }
 }
 

+ 8 - 9
src/main/java/com/izouma/nineth/web/ShowroomController.java

@@ -24,15 +24,8 @@ public class ShowroomController extends BaseController {
     private ShowroomRepo       showroomRepo;
     private ShowCollectionRepo showCollectionRepo;
 
-    //@PreAuthorize("hasRole('ADMIN')")
     @PostMapping("/save")
     public Showroom save(@RequestBody Showroom record) {
-//        if (record.getId() != null) {
-//            Showroom orig = showroomRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
-//            ObjUtils.merge(orig, record);
-//            return showroomRepo.save(orig);
-//        }
-//        return showroomRepo.save(record);
         return showroomService.save(SecurityUtils.getAuthenticatedUser().getId(), record);
     }
 
@@ -41,7 +34,6 @@ public class ShowroomController extends BaseController {
         return showroomService.update(SecurityUtils.getAuthenticatedUser().getId(), record);
     }
 
-    //@PreAuthorize("hasRole('ADMIN')")
     @PostMapping("/all")
     public Page<Showroom> all(@RequestBody PageQuery pageQuery) {
         return showroomService.all(pageQuery);
@@ -49,7 +41,9 @@ public class ShowroomController extends BaseController {
 
     @GetMapping("/get/{id}")
     public Showroom get(@PathVariable Long id) {
-        return showroomRepo.findById(id).orElseThrow(new BusinessException("无记录"));
+        Showroom showroom = showroomRepo.findById(id).orElseThrow(new BusinessException("无记录"));
+        showroom.setCollections(showCollectionRepo.findAllByShowroomId(id));
+        return showroom;
     }
 
     @PostMapping("/del/{id}")
@@ -64,5 +58,10 @@ public class ShowroomController extends BaseController {
         List<Showroom> data = all(pageQuery).getContent();
         ExcelUtils.export(response, data);
     }
+
+    @GetMapping("/{id}/share")
+    public void addShare(@PathVariable Long id) {
+        showroomRepo.addShare(id, 1);
+    }
 }