tsk-35: Add API documentation (#39)

Closes #35

Reviewed-on: phoenix/textsender-api#39
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
phoenix
2025-11-13 21:45:17 +00:00
committed by phoenix
parent 0cd71c5506
commit f69d56f527
14 changed files with 2597 additions and 23 deletions
+26
View File
@@ -33,6 +33,18 @@ func NewContactHandler(str store.ContactStore) *ContactHandler {
return &ContactHandler{ContactStore: str}
}
// AddContact godoc
// @Summary Add contact
// @Description Add a contact record to have a recipient to send a text to (requires JWT)
// @Tags contacts
// @Accept json
// @Produce json
// @Security BearerAuth
// @Param request body RequestAddContact true "Data to add contact"
// @Success 201 {object} AddContactResponse
// @Failure 400 {object} AddContactResponse
// @Failure 500 {object} AddContactResponse
// @Router /contact/new [post]
func (c *ContactHandler) AddContact(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
@@ -76,6 +88,19 @@ func (c *ContactHandler) AddContact(w http.ResponseWriter, r *http.Request) {
RespondWithJSON(w, statusCode, &resp)
}
// GetContact godoc
// @Summary Get contact
// @Description Get a contact record to have a recipient to send a text to (requires JWT)
// @Tags contacts
// @Accept json
// @Produce json
// @Param id path string true "Contact Id"
// @Param user_id path string true "User Id"
// @Security BearerAuth
// @Success 200 {object} GetContactResponse
// @Failure 400 {object} GetContactResponse
// @Failure 500 {object} GetContactResponse
// @Router /contact [get]
func (c *ContactHandler) GetContact(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
fmt.Println("Method:", r.Method)
@@ -83,6 +108,7 @@ func (c *ContactHandler) GetContact(w http.ResponseWriter, r *http.Request) {
return
}
// One or the other
var id, userId uuid.UUID
queryParams := r.URL.Query()
+1
View File
@@ -4,6 +4,7 @@ import "net/http"
import "git.kundeng.us/phoenix/textsender-api/internal/model"
// TODO: Remove file
func DraftMessageHandler(w http.ResponseWriter, r *http.Request) {
da := model.MessageItem{
Id: 1,
+29 -5
View File
@@ -33,6 +33,17 @@ func NewMessageHandler(str store.MessageStore) *MessageHandler {
return &MessageHandler{MessageStore: str}
}
// AddMessage godoc
// @Summary Add message
// @Description Add a message record to send a text to (requires JWT)
// @Tags messages
// @Accept json
// @Produce json
// @Security BearerAuth
// @Param request body RequestAddMessage true "Data to add message"
// @Success 201 {object} AddMessageResponse
// @Failure 500 {object} AddMessageResponse
// @Router /message/new [post]
func (m *MessageHandler) AddMessage(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
@@ -64,6 +75,19 @@ func (m *MessageHandler) AddMessage(w http.ResponseWriter, r *http.Request) {
RespondWithJSON(w, statusCode, &resp)
}
// GetMessage godoc
// @Summary Get message
// @Description Get a message record to have a recipient to send a text to (requires JWT)
// @Tags messages
// @Accept json
// @Produce json
// @Param id path string true "Message Id"
// @Param user_id path string true "User Id"
// @Security BearerAuth
// @Success 200 {object} GetMessageResponse
// @Failure 400 {object} GetMessageResponse
// @Failure 500 {object} GetMessageResponse
// @Router /message [get]
func (c *MessageHandler) GetMessage(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
@@ -114,10 +138,10 @@ func (c *MessageHandler) GetMessage(w http.ResponseWriter, r *http.Request) {
}
} else if userId != uuid.Nil {
fmt.Println("Checking with User Id")
if contacts, err := c.MessageStore.GetAllMessages(ctx); err == nil {
for _, con := range contacts {
if con.UserId == userId {
resp.Data = append(resp.Data, *con)
if messages, err := c.MessageStore.GetAllMessages(ctx); err == nil {
for _, msg := range messages {
if msg.UserId == userId {
resp.Data = append(resp.Data, *msg)
}
}
@@ -126,7 +150,7 @@ func (c *MessageHandler) GetMessage(w http.ResponseWriter, r *http.Request) {
resp.Message = "Successful"
} else {
statusCode = http.StatusNotFound
resp.Message = "Contact not found"
resp.Message = "Message not found"
}
} else {
statusCode = http.StatusInternalServerError
@@ -33,6 +33,19 @@ func NewScheduledMessageStatusHandler(str store.ScheduledMessageEventStore, schS
return &ScheduledMessageStatusHandler{ScheduledMessageEventStore: str, ScheduledMessageStore: schStore}
}
// UpdateStatus godoc
// @Summary Update status
// @Description Update the status of a scheduled message (requires JWT)
// @Tags status
// @Accept json
// @Produce json
// @Security BearerAuth
// @Param request body RequestScheduledMessageStatus true "Used to update scheduled message status"
// @Success 201 {object} ScheduledMessageStatusResponse
// @Failure 400 {object} ScheduledMessageStatusResponse
// @Failure 404 {object} ScheduledMessageStatusResponse
// @Failure 500 {object} ScheduledMessageStatusResponse
// @Router /schedule/message/status/update [patch]
func (s *ScheduledMessageStatusHandler) UpdateStatus(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPatch {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
+36 -1
View File
@@ -14,7 +14,6 @@ import (
type RequestAddScheduledMessage struct {
Scheduled time.Time `json:"scheduled"`
Created time.Time `json:"created"`
Status string `json:"status"`
UserId uuid.UUID `json:"user_id"`
}
@@ -42,6 +41,18 @@ func NewScheduledMessageHandler(str store.ScheduledMessageStore) *ScheduledMessa
return &ScheduledMessageHandler{ScheduledMessageStore: str}
}
// AddScheduledMessage godoc
// @Summary Add scheduled message
// @Description Adds a scheduled message (requires JWT)
// @Tags scheduled messages
// @Accept json
// @Produce json
// @Security BearerAuth
// @Param request body RequestAddScheduledMessage true "Data to add scheduled message"
// @Success 201 {object} AddScheduledMessageResponse
// @Failure 400 {object} AddScheduledMessageResponse
// @Failure 500 {object} AddScheduledMessageResponse
// @Router /schedule/message [post]
func (s *ScheduledMessageHandler) AddScheduledMessage(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
@@ -93,6 +104,19 @@ func (s *ScheduledMessageHandler) AddScheduledMessage(w http.ResponseWriter, r *
RespondWithJSON(w, statusCode, &resp)
}
// GetScheduledMessage godoc
// @Summary Get scheduled message
// @Description Get a scheduled message (requires JWT)
// @Tags scheduled messages
// @Accept json
// @Produce json
// @Security BearerAuth
// @Param id path string true "Contact Id"
// @Param user_id path string true "User Id"
// @Success 200 {object} GetScheduledMessageResponse
// @Failure 400 {object} GetScheduledMessageResponse
// @Failure 500 {object} GetScheduledMessageResponse
// @Router /schedule/message [get]
func (s *ScheduledMessageHandler) GetScheduledMessage(w http.ResponseWriter, r *http.Request) {
var id, userId uuid.UUID
@@ -157,6 +181,17 @@ func (s *ScheduledMessageHandler) GetScheduledMessage(w http.ResponseWriter, r *
RespondWithJSON(w, statusCode, &resp)
}
// FetchNextMessage godoc
// @Summary Fetch scheduled message
// @Description Fetches a scheduled message that is available to be processed (requires JWT)
// @Tags scheduled messages
// @Accept json
// @Produce json
// @Security BearerAuth
// @Success 200 {object} FetchNextMessageResponse
// @Failure 400 {object} FetchNextMessageResponse
// @Failure 500 {object} FetchNextMessageResponse
// @Router /schedule/message/fetch [get]
func (s *ScheduledMessageHandler) FetchNextMessage(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
var resp FetchNextMessageResponse
@@ -41,6 +41,18 @@ func NewScheduledMessageEventHandler(str store.ScheduledMessageEventStore, schSt
return &ScheduledMessageEventHandler{ScheduledMessageEventStore: str, ScheduledMessageStore: schStore}
}
// AddContact godoc
// @Summary Add scheduled message event
// @Description Add a scheduled message event (requires JWT)
// @Tags scheduled message events
// @Accept json
// @Produce json
// @Security BearerAuth
// @Param request body RequestAddScheduledMessageEvent true "Data to add scheduled message event"
// @Success 201 {object} AddScheduledMessageEventResponse
// @Failure 400 {object} AddScheduledMessageEventResponse
// @Failure 500 {object} AddScheduledMessageEventResponse
// @Router /schedule/message/event [post]
func (s *ScheduledMessageEventHandler) AddScheduledMessageEvent(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
@@ -103,6 +115,19 @@ func (s *ScheduledMessageEventHandler) AddScheduledMessageEvent(w http.ResponseW
RespondWithJSON(w, statusCode, &resp)
}
// GetScheduledMessageEvent godoc
// @Summary Get scheduled message event
// @Description Gets a scheduled message event (requires JWT)
// @Tags scheduled message events
// @Accept json
// @Produce json
// @Param id path string true "Contact Id"
// @Param scheduled_message_id path string true "Scheduled Message Id"
// @Security BearerAuth
// @Success 200 {object} GetScheduledMessageEventResponse
// @Failure 400 {object} GetScheduledMessageEventResponse
// @Failure 500 {object} GetScheduledMessageEventResponse
// @Router /schedule/message/event [get]
func (s *ScheduledMessageEventHandler) GetScheduledMessageEvent(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
http.Error(w, "Metnot allowed", http.StatusMethodNotAllowed)
@@ -154,6 +179,18 @@ func (s *ScheduledMessageEventHandler) GetScheduledMessageEvent(w http.ResponseW
RespondWithJSON(w, statusCode, &resp)
}
// DeleteScheduledMessageEvent godoc
// @Summary Delete scheduled message event
// @Description Deletes a scheduled message event (requires JWT)
// @Tags scheduled message events
// @Accept json
// @Produce json
// @Security BearerAuth
// @Param id path string true "scheduled message event Id" Format(uuid)
// @Success 201 {object} DeleteScheduledMessageEventResponse
// @Failure 400 {object} DeleteScheduledMessageEventResponse
// @Failure 500 {object} DeleteScheduledMessageEventResponse
// @Router /schedule/message/event/{id} [delete]
func (s *ScheduledMessageEventHandler) DeleteScheduledMessageEvent(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodDelete {
http.Error(w, "Metnot allowed", http.StatusMethodNotAllowed)