syntax = "v1"

info (
	title:   "Announcement API"
	desc:    "API for ppanel"
	author:  "Tension"
	email:   "tension@ppanel.com"
	version: "0.0.1"
)

import "../types.api"

type (
	CreateAnnouncementRequest {
		Title   string `json:"title" validate:"required"`
		Content string `json:"content" validate:"required"`
	}
	UpdateAnnouncementRequest {
		Id      int64  `json:"id" validate:"required"`
		Title   string `json:"title"`
		Content string `json:"content"`
		Show    *bool  `json:"show"`
		Pinned  *bool  `json:"pinned"`
		Popup   *bool  `json:"popup"`
	}
	UpdateAnnouncementEnableRequest {
		Id     int64 `json:"id" validate:"required"`
		Enable *bool `json:"enable" validate:"required"`
	}
	DeleteAnnouncementRequest {
		Id int64 `json:"id" validate:"required"`
	}
	GetAnnouncementListRequest {
		Page   int64  `form:"page"`
		Size   int64  `form:"size"`
		Show   *bool  `form:"show,omitempty"`
		Pinned *bool  `form:"pinned,omitempty"`
		Popup  *bool  `form:"popup,omitempty"`
		Search string `form:"search,omitempty"`
	}
	GetAnnouncementListResponse {
		Total int64          `json:"total"`
		List  []Announcement `json:"list"`
	}
	GetAnnouncementRequest {
		Id int64 `form:"id" validate:"required"`
	}
)

@server (
	prefix:     v1/admin/announcement
	group:      admin/announcement
	middleware: AuthMiddleware
)
service ppanel {
	@doc "Create announcement"
	@handler CreateAnnouncement
	post / (CreateAnnouncementRequest)

	@doc "Update announcement"
	@handler UpdateAnnouncement
	put / (UpdateAnnouncementRequest)

	@doc "Get announcement list"
	@handler GetAnnouncementList
	get /list (GetAnnouncementListRequest) returns (GetAnnouncementListResponse)

	@doc "Delete announcement"
	@handler DeleteAnnouncement
	delete / (DeleteAnnouncementRequest)

	@doc "Get announcement"
	@handler GetAnnouncement
	get /detail (GetAnnouncementRequest) returns (Announcement)
}

