本地主机消除502
This commit is contained in:
@@ -10,12 +10,6 @@ public class Notice {
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "shop_id", nullable = false)
|
||||
private Long shopId;
|
||||
|
||||
@Column(name = "user_id", nullable = false)
|
||||
private Long userId;
|
||||
|
||||
@Column(name = "title", nullable = false, length = 120)
|
||||
private String title;
|
||||
|
||||
@@ -57,10 +51,6 @@ public class Notice {
|
||||
}
|
||||
|
||||
public Long getId() { return id; }
|
||||
public Long getShopId() { return shopId; }
|
||||
public void setShopId(Long shopId) { this.shopId = shopId; }
|
||||
public Long getUserId() { return userId; }
|
||||
public void setUserId(Long userId) { this.userId = userId; }
|
||||
public String getTitle() { return title; }
|
||||
public void setTitle(String title) { this.title = title; }
|
||||
public String getContent() { return content; }
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.example.demo.notice;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@@ -18,13 +17,9 @@ public class NoticeController {
|
||||
this.noticeService = noticeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 简化:通过请求头 X-Shop-Id 传递当前店铺ID。
|
||||
*/
|
||||
@GetMapping
|
||||
public ResponseEntity<List<Notice>> list(@RequestHeader(name = "X-Shop-Id", required = false) Long shopId) {
|
||||
Long sid = (shopId == null ? 1L : shopId);
|
||||
return ResponseEntity.ok(noticeService.listActive(sid));
|
||||
public ResponseEntity<List<Notice>> list() {
|
||||
return ResponseEntity.ok(noticeService.listActive());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,10 +8,10 @@ import java.util.List;
|
||||
|
||||
public interface NoticeRepository extends JpaRepository<Notice, Long> {
|
||||
|
||||
@Query("SELECT n FROM Notice n WHERE n.shopId = :shopId AND n.status = :status " +
|
||||
@Query("SELECT n FROM Notice n WHERE n.status = :status " +
|
||||
"AND (n.startsAt IS NULL OR n.startsAt <= CURRENT_TIMESTAMP) AND (n.endsAt IS NULL OR n.endsAt >= CURRENT_TIMESTAMP) " +
|
||||
"ORDER BY n.pinned DESC, n.createdAt DESC")
|
||||
List<Notice> findActiveNotices(@Param("shopId") Long shopId, @Param("status") NoticeStatus status);
|
||||
List<Notice> findActiveNotices(@Param("status") NoticeStatus status);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ public class NoticeService {
|
||||
this.noticeRepository = noticeRepository;
|
||||
}
|
||||
|
||||
public List<Notice> listActive(Long shopId) {
|
||||
return noticeRepository.findActiveNotices(shopId, NoticeStatus.PUBLISHED);
|
||||
public List<Notice> listActive() {
|
||||
return noticeRepository.findActiveNotices(NoticeStatus.PUBLISHED);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user