Skip to content

Commit

Permalink
Merge pull request #34 from dezswap/fix/noti-chain
Browse files Browse the repository at this point in the history
fix: remove default chain
  • Loading branch information
jhlee-young authored Jan 4, 2024
2 parents 29fdfc5 + f2ea2b3 commit 3a8debb
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 10 deletions.
5 changes: 2 additions & 3 deletions api/controller/notice/dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
type NoticesRes []noticeItem
type noticeItem struct {
Id string `json:"id"`
Chain string `json:"chain"`
Title string `json:"title"`
Description string `json:"description"`
Timestamp time.Time `json:"timestamp"`
Expand All @@ -24,9 +25,6 @@ type PaginationReq struct {

func (p PaginationReq) Default() PaginationReq {
d := notice.DefaultPaginationCond
if p.Chain == "" {
p.Chain = notice.DEFAULT_CHAIN
}
if !p.Asc && p.After == 0 {
p.After = d.After
}
Expand All @@ -51,6 +49,7 @@ func (m *mapper) noticesToRes(notices []notice.NoticeItem) NoticesRes {
for i, n := range notices {
res[i] = noticeItem{
Id: fmt.Sprint(n.Id),
Chain: n.Chain,
Title: n.Title,
Description: n.Description,
Timestamp: n.Date,
Expand Down
4 changes: 2 additions & 2 deletions api/controller/notice/notice.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func InitNoticeController(s notice.Notice, route *gin.RouterGroup, logger loggin
}

func (c *noticeController) register(route *gin.RouterGroup) {
route.GET("/", c.Notices)
route.GET("", c.Notices)
}

// Dashboard godoc
Expand All @@ -40,7 +40,7 @@ func (c *noticeController) register(route *gin.RouterGroup) {
// @Failure 400 {object} httputil.BadRequestError
// @Failure 500 {object} httputil.InternalServerError
//
// @Param chain query string false "target chain name e.g. (dimension, cube), default (dimension)"
// @Param chain query string false "target chain name e.g. (dimension, cube)"
// @Param after query uint false "condition to get items after the id"
// @Param limit query uint false "the number of items to return (default: 10)"
// @Param asc query bool false "order of items to return (default: descending order)"
Expand Down
2 changes: 1 addition & 1 deletion api/controller/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func InitRouterController(s rs.Router, route *gin.RouterGroup, logger logging.Lo
}

func (c *routerController) register(route *gin.RouterGroup) {
route.GET("/", c.Routes)
route.GET("", c.Routes)
}

// Routes godoc
Expand Down
5 changes: 4 additions & 1 deletion api/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ const docTemplate = `{
"parameters": [
{
"type": "string",
"description": "target chain name e.g. (dimension, cube), default (dimension)",
"description": "target chain name e.g. (dimension, cube)",
"name": "chain",
"in": "query"
},
Expand Down Expand Up @@ -1693,6 +1693,9 @@ const docTemplate = `{
"notice.noticeItem": {
"type": "object",
"properties": {
"chain": {
"type": "string"
},
"description": {
"type": "string"
},
Expand Down
5 changes: 4 additions & 1 deletion api/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@
"parameters": [
{
"type": "string",
"description": "target chain name e.g. (dimension, cube), default (dimension)",
"description": "target chain name e.g. (dimension, cube)",
"name": "chain",
"in": "query"
},
Expand Down Expand Up @@ -1682,6 +1682,9 @@
"notice.noticeItem": {
"type": "object",
"properties": {
"chain": {
"type": "string"
},
"description": {
"type": "string"
},
Expand Down
4 changes: 3 additions & 1 deletion api/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ definitions:
type: object
notice.noticeItem:
properties:
chain:
type: string
description:
type: string
id:
Expand Down Expand Up @@ -840,7 +842,7 @@ paths:
- application/json
description: get Notices
parameters:
- description: target chain name e.g. (dimension, cube), default (dimension)
- description: target chain name e.g. (dimension, cube)
in: query
name: chain
type: string
Expand Down
1 change: 1 addition & 0 deletions api/service/notice/dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var DefaultPaginationCond = PaginationCond{

type NoticeItem struct {
Id uint `json:"id"`
Chain string `json:"chain"`
Title string `json:"title"`
Description string `json:"description"`
Date time.Time `json:"date" gorm:"index:notice_date_idx type:timestamp without time zone"`
Expand Down
6 changes: 5 additions & 1 deletion api/service/notice/notice.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ func NewService(db *gorm.DB) Notice {
func (n *notice) Notices(chain string, cond PaginationCond) ([]NoticeItem, error) {
cond.Trim()

query := n.DB.Model(&models.Notice{}).Where("chain = ?", chain).Select("id, title, description, date AT TIME ZONE 'UTC' as date")
query := n.DB.Model(&models.Notice{}).Select("id, title, description, date AT TIME ZONE 'UTC' as date")
if chain != "" {
query = query.Where("chain = ?", chain)
}

if cond.Asc {
query = query.Where("id > ?", cond.After).Limit(int(cond.Limit)).Order("id asc")
} else {
Expand Down

0 comments on commit 3a8debb

Please sign in to comment.