diff options
Diffstat (limited to 'nexus/services/account/account.go')
| -rw-r--r-- | nexus/services/account/account.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/nexus/services/account/account.go b/nexus/services/account/account.go new file mode 100644 index 0000000..a990659 --- /dev/null +++ b/nexus/services/account/account.go @@ -0,0 +1,46 @@ +package account
+
+import (
+ "fmt"
+ "nexus/models"
+ "nexus/repositories/account"
+ "nexus/utils/logger"
+ "nexus/utils/shortcuts"
+
+ "github.com/gofiber/fiber/v2"
+ "github.com/google/uuid"
+)
+
+func GetByID(id uuid.UUID) (*models.Account, *fiber.Error) {
+ a, err := account.FindByID(id)
+ if err != nil {
+ return nil, shortcuts.ServiceError(fiber.StatusNotFound, ErrAccountNotFound)
+ }
+ return a, nil
+}
+
+func Disable(id uuid.UUID) *fiber.Error {
+ if _, err := account.FindByID(id); err != nil {
+ return shortcuts.ServiceError(fiber.StatusNotFound, ErrAccountNotFound)
+ }
+
+ if err := account.Disable(id); err != nil {
+ logger.Errorf(LogPrefix, AccountDisableFailed, err)
+ return shortcuts.ServiceError(fiber.StatusInternalServerError, fmt.Sprintf(AccountDisableFailed, err))
+ }
+
+ return nil
+}
+
+func Delete(id uuid.UUID) *fiber.Error {
+ if _, err := account.FindByID(id); err != nil {
+ return shortcuts.ServiceError(fiber.StatusNotFound, ErrAccountNotFound)
+ }
+
+ if err := account.Delete(id); err != nil {
+ logger.Errorf(LogPrefix, AccountDeleteFailed, err)
+ return shortcuts.ServiceError(fiber.StatusInternalServerError, fmt.Sprintf(AccountDeleteFailed, err))
+ }
+
+ return nil
+}
|
