chore: 领域模型 & DTO

This commit is contained in:
2025-12-16 15:43:05 +08:00
parent e7a769c1b7
commit a72a46838e
6 changed files with 55 additions and 0 deletions

2
interval/api/dto/doc.go Normal file
View File

@ -0,0 +1,2 @@
// Package dto contains data transfer objects used in the interval API.
package dto

View File

@ -0,0 +1,17 @@
package dto
import (
"git.jinshen.cn/remilia/push-server/interval/model"
)
type Message struct {
Topic string `json:"topic"`
Content string `json:"content"`
}
func MessageFromModel(m model.Message) Message {
return Message{
Topic: string(m.Topic),
Content: string(m.Content),
}
}

View File

@ -0,0 +1,17 @@
package dto
import (
"git.jinshen.cn/remilia/push-server/interval/model"
)
type Subscription struct {
Topic string `json:"topic"`
ClientID string `json:"client_id"`
}
func SubscriptionFromModel(s model.Subscription) Subscription {
return Subscription{
Topic: string(s.Topic),
ClientID: string(s.ClientID),
}
}

View File

@ -0,0 +1,6 @@
package model
type Message struct {
Topic Topic
Content []byte
}

View File

@ -0,0 +1,6 @@
package model
type Subscription struct {
Topic Topic
ClientID string
}

7
interval/model/topic.go Normal file
View File

@ -0,0 +1,7 @@
package model
type Topic string
func (t Topic) Valid() bool {
return t != ""
}