2022-02-18 20:21:15 +00:00
|
|
|
package databag
|
|
|
|
|
|
|
|
import (
|
2022-07-22 19:28:14 +00:00
|
|
|
"databag/internal/store"
|
|
|
|
"errors"
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
"net/http"
|
2022-02-18 20:21:15 +00:00
|
|
|
)
|
|
|
|
|
2022-07-29 07:21:32 +00:00
|
|
|
//GetChannelTopicDetail retrieves topic subject and attributes
|
2022-02-18 20:21:15 +00:00
|
|
|
func GetChannelTopicDetail(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
2022-07-22 19:28:14 +00:00
|
|
|
// scan parameters
|
|
|
|
params := mux.Vars(r)
|
|
|
|
topicID := params["topicID"]
|
|
|
|
|
|
|
|
var subject Subject
|
|
|
|
if err := ParseRequest(r, w, &subject); err != nil {
|
|
|
|
ErrResponse(w, http.StatusBadRequest, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-07-27 05:43:39 +00:00
|
|
|
channelSlot, _, code, err := getChannelSlot(r, false)
|
2022-07-22 19:28:14 +00:00
|
|
|
if err != nil {
|
|
|
|
ErrResponse(w, code, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// load topic
|
|
|
|
var topicSlot store.TopicSlot
|
|
|
|
if err = store.DB.Where("channel_id = ? AND topic_slot_id = ?", channelSlot.Channel.ID, topicID).First(&topicSlot).Error; err != nil {
|
|
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
|
code = http.StatusNotFound
|
|
|
|
} else {
|
|
|
|
code = http.StatusInternalServerError
|
|
|
|
}
|
2022-07-22 20:23:17 +00:00
|
|
|
ErrResponse(w, code, err)
|
2022-07-22 19:28:14 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
WriteResponse(w, getTopicDetailModel(&topicSlot))
|
2022-02-18 20:21:15 +00:00
|
|
|
}
|