docs: added documentation

This commit is contained in:
David Janowski 2024-07-11 12:27:35 +02:00
parent 5c9266edb5
commit 69376e5ed2

View File

@ -3,13 +3,24 @@ package endpoints
import (
"encoding/json"
"fmt"
"log"
"net/http"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/model"
"git.dragse.it/anthrove/e621-sdk-go/pkg/e621/utils"
)
// GetDmail retrieves a specific DMail by its ID.
//
// This function performs an HTTP GET request to the e621 DMail endpoint and parses
// the JSON content to extract the DMail data.
//
// Parameters:
// - requestContext: The model.RequestContext for the API request.
// - ID: The ID of the DMail to be fetched.
//
// Returns:
// - model.DMail: A struct containing the DMail data.
// - error: An error, if any, encountered during the API request or response handling.
func GetDmail(requestContext model.RequestContext, ID int) (model.DMail, error) {
// Create a new HTTP GET request to fetch the post information.
r, err := http.NewRequest("GET", fmt.Sprintf("%s/dmails/%d.json", requestContext.Host, ID), nil)
@ -52,7 +63,17 @@ func GetDmail(requestContext model.RequestContext, ID int) (model.DMail, error)
return postResponse, nil
}
func DeleateDmail(requestContext model.RequestContext, ID int) error {
// DeleteDmail deletes a specific DMail by its ID.
//
// This function performs an HTTP DELETE request to the e621 DMail endpoint.
//
// Parameters:
// - requestContext: The model.RequestContext for the API request.
// - ID: The ID of the DMail to be deleted.
//
// Returns:
// - error: An error, if any, encountered during the API request or response handling.
func DeleteDmail(requestContext model.RequestContext, ID int) error {
// Create a new HTTP GET request to fetch the post information.
r, err := http.NewRequest("DELETE", fmt.Sprintf("%s/dmails/%d.json", requestContext.Host, ID), nil)
if err != nil {
@ -82,10 +103,23 @@ func DeleateDmail(requestContext model.RequestContext, ID int) error {
return nil
}
// MarkAsReadDmail marks a specific DMail as read by its ID.
//
// This function performs an HTTP PUT request to the e621 DMail endpoint.
//
// Parameters:
// - requestContext: The model.RequestContext for the API request.
// - ID: The ID of the DMail to be marked as read.
//
// Returns:
// - error: An error, if any, encountered during the API request or response handling.
func MarkAsReadDmail(requestContext model.RequestContext, ID int) error {
// Create a new HTTP GET request to fetch the post information.
r, err := http.NewRequest("PUT", fmt.Sprintf("%s/dmails/%d/mark_as_read.json", requestContext.Host, ID), nil)
log.Print(r.URL)
if err != nil {
// Log the error and return an empty Post struct and the error.
return err
}
r.Header.Set("User-Agent", requestContext.UserAgent)
r.Header.Add("Accept", "application/json")
@ -108,6 +142,18 @@ func MarkAsReadDmail(requestContext model.RequestContext, ID int) error {
return nil
}
// GetAllDmails retrieves all DMails.
//
// This function performs an HTTP GET request to the e621 DMail endpoint and parses
// the JSON content to extract the DMail data.
//
// Parameters:
// - requestContext: The model.RequestContext for the API request.
// - query: A map containing the query parameters for the request.
//
// Returns:
// - []model.DMail: A slice of structs containing the DMail data.
// - error: An error, if any, encountered during the API request or response handling.
func GetAllDmails(requestContext model.RequestContext, query map[string]string) ([]model.DMail, error) {
// Create a new HTTP GET request.
r, err := http.NewRequest("GET", fmt.Sprintf("%s/dmails.json", requestContext.Host), nil)
@ -153,6 +199,15 @@ func GetAllDmails(requestContext model.RequestContext, query map[string]string)
return postResponse, nil
}
// MarkAsReadAllDmails marks all DMails as read.
//
// This function performs an HTTP PUT request to the e621 DMail endpoint.
//
// Parameters:
// - requestContext: The model.RequestContext for the API request.
//
// Returns:
// - error: An error, if any, encountered during the API request or response handling.
func MarkAsReadAllDmails(requestContext model.RequestContext) error {
// Create a new HTTP GET request to fetch the post information.
r, err := http.NewRequest("PUT", fmt.Sprintf("%s/dmails/mark_all_as_read.json", requestContext.Host), nil)