Skip to content

Commit

Permalink
genres and tags
Browse files Browse the repository at this point in the history
  • Loading branch information
kayprogrammer committed Dec 7, 2024
1 parent 98d66fb commit a6fb04e
Show file tree
Hide file tree
Showing 6 changed files with 315 additions and 19 deletions.
98 changes: 96 additions & 2 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,53 @@ const docTemplate = `{
}
}
}
},
"delete": {
"security": [
{
"BearerAuth": []
}
],
"description": "Delete a genre.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Admin | Books"
],
"summary": "Delete Genre",
"parameters": [
{
"type": "string",
"description": "Genre slug",
"name": "slug",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "Genre Deleted Successfully",
"schema": {
"$ref": "#/definitions/schemas.ResponseSchema"
}
},
"400": {
"description": "Invalid request data",
"schema": {
"$ref": "#/definitions/utils.ErrorResponse"
}
},
"500": {
"description": "Internal server error",
"schema": {
"$ref": "#/definitions/utils.ErrorResponse"
}
}
}
}
},
"/admin/books/tags": {
Expand All @@ -257,7 +304,7 @@ const docTemplate = `{
"tags": [
"Admin | Books"
],
"summary": "Add Tags",
"summary": "Add Tag",
"parameters": [
{
"description": "Tag",
Expand Down Expand Up @@ -308,7 +355,7 @@ const docTemplate = `{
"tags": [
"Admin | Books"
],
"summary": "Update Tags",
"summary": "Update Tag",
"parameters": [
{
"type": "string",
Expand Down Expand Up @@ -347,6 +394,53 @@ const docTemplate = `{
}
}
}
},
"delete": {
"security": [
{
"BearerAuth": []
}
],
"description": "Delete a tag from the app.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Admin | Books"
],
"summary": "Delete Tag",
"parameters": [
{
"type": "string",
"description": "Tag slug",
"name": "slug",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "Tag delete successfully",
"schema": {
"$ref": "#/definitions/schemas.ResponseSchema"
}
},
"400": {
"description": "Invalid request data",
"schema": {
"$ref": "#/definitions/utils.ErrorResponse"
}
},
"500": {
"description": "Internal server error",
"schema": {
"$ref": "#/definitions/utils.ErrorResponse"
}
}
}
}
},
"/admin/payments/transactions": {
Expand Down
98 changes: 96 additions & 2 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,53 @@
}
}
}
},
"delete": {
"security": [
{
"BearerAuth": []
}
],
"description": "Delete a genre.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Admin | Books"
],
"summary": "Delete Genre",
"parameters": [
{
"type": "string",
"description": "Genre slug",
"name": "slug",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "Genre Deleted Successfully",
"schema": {
"$ref": "#/definitions/schemas.ResponseSchema"
}
},
"400": {
"description": "Invalid request data",
"schema": {
"$ref": "#/definitions/utils.ErrorResponse"
}
},
"500": {
"description": "Internal server error",
"schema": {
"$ref": "#/definitions/utils.ErrorResponse"
}
}
}
}
},
"/admin/books/tags": {
Expand All @@ -250,7 +297,7 @@
"tags": [
"Admin | Books"
],
"summary": "Add Tags",
"summary": "Add Tag",
"parameters": [
{
"description": "Tag",
Expand Down Expand Up @@ -301,7 +348,7 @@
"tags": [
"Admin | Books"
],
"summary": "Update Tags",
"summary": "Update Tag",
"parameters": [
{
"type": "string",
Expand Down Expand Up @@ -340,6 +387,53 @@
}
}
}
},
"delete": {
"security": [
{
"BearerAuth": []
}
],
"description": "Delete a tag from the app.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Admin | Books"
],
"summary": "Delete Tag",
"parameters": [
{
"type": "string",
"description": "Tag slug",
"name": "slug",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "Tag delete successfully",
"schema": {
"$ref": "#/definitions/schemas.ResponseSchema"
}
},
"400": {
"description": "Invalid request data",
"schema": {
"$ref": "#/definitions/utils.ErrorResponse"
}
},
"500": {
"description": "Internal server error",
"schema": {
"$ref": "#/definitions/utils.ErrorResponse"
}
}
}
}
},
"/admin/payments/transactions": {
Expand Down
64 changes: 62 additions & 2 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1457,6 +1457,36 @@ paths:
tags:
- Admin | Books
/admin/books/genres/{slug}:
delete:
consumes:
- application/json
description: Delete a genre.
parameters:
- description: Genre slug
in: path
name: slug
required: true
type: string
produces:
- application/json
responses:
"200":
description: Genre Deleted Successfully
schema:
$ref: '#/definitions/schemas.ResponseSchema'
"400":
description: Invalid request data
schema:
$ref: '#/definitions/utils.ErrorResponse'
"500":
description: Internal server error
schema:
$ref: '#/definitions/utils.ErrorResponse'
security:
- BearerAuth: []
summary: Delete Genre
tags:
- Admin | Books
put:
consumes:
- application/json
Expand Down Expand Up @@ -1522,10 +1552,40 @@ paths:
$ref: '#/definitions/utils.ErrorResponse'
security:
- BearerAuth: []
summary: Add Tags
summary: Add Tag
tags:
- Admin | Books
/admin/books/tags/{slug}:
delete:
consumes:
- application/json
description: Delete a tag from the app.
parameters:
- description: Tag slug
in: path
name: slug
required: true
type: string
produces:
- application/json
responses:
"200":
description: Tag delete successfully
schema:
$ref: '#/definitions/schemas.ResponseSchema'
"400":
description: Invalid request data
schema:
$ref: '#/definitions/utils.ErrorResponse'
"500":
description: Internal server error
schema:
$ref: '#/definitions/utils.ErrorResponse'
security:
- BearerAuth: []
summary: Delete Tag
tags:
- Admin | Books
put:
consumes:
- application/json
Expand Down Expand Up @@ -1559,7 +1619,7 @@ paths:
$ref: '#/definitions/utils.ErrorResponse'
security:
- BearerAuth: []
summary: Update Tags
summary: Update Tag
tags:
- Admin | Books
/admin/payments/transactions:
Expand Down
11 changes: 6 additions & 5 deletions models/book.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (

type Tag struct {
BaseModel
Name string `gorm:"unique"`
Slug string `gorm:"unique"`
Name string `gorm:"unique"`
Slug string `gorm:"unique"`
Genres []Genre `gorm:"many2many:genre_tags;"`
}

func (tag *Tag) BeforeSave(tx *gorm.DB) (err error) {
Expand All @@ -25,7 +26,7 @@ type Genre struct {
BaseModel
Name string `gorm:"unique"`
Slug string `gorm:"unique"`
Tags []Tag `json:"tags" gorm:"many2many:genre_tags;"`
Tags []Tag `gorm:"many2many:genre_tags;"`
}

func (genre *Genre) BeforeSave(tx *gorm.DB) (err error) {
Expand All @@ -36,14 +37,14 @@ func (genre *Genre) BeforeSave(tx *gorm.DB) (err error) {
type Book struct {
BaseModel
AuthorID uuid.UUID
Author User `gorm:"foreignKey:AuthorID;constraint:OnDelete:CASCADE;<-:false"`
Author User `gorm:"foreignKey:AuthorID;constraint:OnDelete:SET NULL;<-:false"`
Title string `gorm:"type: varchar(255)"`
Slug string `gorm:"unique"`
Blurb string `gorm:"type: varchar(255)"`
AgeDiscretion choices.AgeType

GenreID uuid.UUID `json:"genre_id"`
Genre Genre `gorm:"foreignKey:GenreID;constraint:OnDelete:CASCADE;<-:false"`
Genre Genre `gorm:"foreignKey:GenreID;constraint:OnDelete:SET NULL;<-:false"`
Tags []Tag `gorm:"many2many:book_tags;<-:false"`
Chapters []Chapter `gorm:"<-:false"`
CoverImage string `gorm:"type:varchar(10000)"`
Expand Down
Loading

0 comments on commit a6fb04e

Please sign in to comment.