This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/models"
|
||||
"kontor-api-gin/internal/repository"
|
||||
"kontor-api-gin/internal/service"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ArticleHandler struct {
|
||||
Service *service.ArticleService
|
||||
}
|
||||
|
||||
func NewArticleHandler(db *gorm.DB) *ArticleHandler {
|
||||
handler := &ArticleHandler{Service: service.NewArticleService(repository.NewArticleRepository(db))}
|
||||
return handler
|
||||
}
|
||||
|
||||
func (handler *ArticleHandler) List(c *gin.Context) {
|
||||
articles, err := handler.Service.List(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
dtos := models.ConvertArticlesToDtos(articles)
|
||||
c.JSON(http.StatusOK, dtos)
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/models"
|
||||
"kontor-api-gin/internal/repository"
|
||||
"kontor-api-gin/internal/service"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ArticleAuthorHandler struct {
|
||||
Service *service.ArticleAuthorService
|
||||
}
|
||||
|
||||
func NewArticleAuthorHandler(db *gorm.DB) *ArticleAuthorHandler {
|
||||
handler := &ArticleAuthorHandler{Service: service.NewArticleAuthorService(repository.NewArticleAuthorRepository(db))}
|
||||
return handler
|
||||
}
|
||||
|
||||
func (handler *ArticleAuthorHandler) List(c *gin.Context) {
|
||||
authors, err := handler.Service.List(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
dtos := models.ConvertArticleAuthorsToDtos(authors)
|
||||
c.JSON(http.StatusOK, dtos)
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/models"
|
||||
"kontor-api-gin/internal/repository"
|
||||
"kontor-api-gin/internal/service"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type AuthorHandler struct {
|
||||
Service *service.AuthorService
|
||||
}
|
||||
|
||||
func NewAuthorHandler(db *gorm.DB) *AuthorHandler {
|
||||
handler := &AuthorHandler{Service: service.NewAuthorService(repository.NewAuthorRepository(db))}
|
||||
return handler
|
||||
}
|
||||
|
||||
func (handler *AuthorHandler) List(c *gin.Context) {
|
||||
artists, err := handler.Service.List(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
dtos := models.ConvertAuthorsToDtos(artists)
|
||||
c.JSON(http.StatusOK, dtos)
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/models"
|
||||
"kontor-api-gin/internal/repository"
|
||||
"kontor-api-gin/internal/service"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type BookHandler struct {
|
||||
Service *service.BookService
|
||||
}
|
||||
|
||||
func NewBookHandler(db *gorm.DB) *BookHandler {
|
||||
handler := &BookHandler{Service: service.NewBookService(repository.NewBookRepository(db))}
|
||||
return handler
|
||||
}
|
||||
|
||||
func (handler *BookHandler) List(c *gin.Context) {
|
||||
books, err := handler.Service.List(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
dtos := models.ConvertBooksToDtos(books)
|
||||
c.JSON(http.StatusOK, dtos)
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/models"
|
||||
"kontor-api-gin/internal/repository"
|
||||
"kontor-api-gin/internal/service"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type BookAuthorHandler struct {
|
||||
Service *service.BookAuthorService
|
||||
}
|
||||
|
||||
func NewBookAuthorHandler(db *gorm.DB) *BookAuthorHandler {
|
||||
handler := &BookAuthorHandler{Service: service.NewBookAuthorService(repository.NewBookAuthorRepository(db))}
|
||||
return handler
|
||||
}
|
||||
|
||||
func (handler *BookAuthorHandler) List(c *gin.Context) {
|
||||
authors, err := handler.Service.List(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
dtos := models.ConvertBookAuthorsToDtos(authors)
|
||||
c.JSON(http.StatusOK, dtos)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type BookshelfHandler struct {
|
||||
ArticleHandler *ArticleHandler
|
||||
BookshelfPublisherHandler *BookshelfPublisherHandler
|
||||
BookHandler *BookHandler
|
||||
AuthorHandler *AuthorHandler
|
||||
ArticleAuthorHandler *ArticleAuthorHandler
|
||||
BookAuthorHandler *BookAuthorHandler
|
||||
}
|
||||
|
||||
func NewBookshelfHandler(db *gorm.DB) *BookshelfHandler {
|
||||
bookshelfHandler := &BookshelfHandler{
|
||||
ArticleHandler: NewArticleHandler(db),
|
||||
BookshelfPublisherHandler: NewBookshelfPublisherHandler(db),
|
||||
BookHandler: NewBookHandler(db),
|
||||
AuthorHandler: NewAuthorHandler(db),
|
||||
ArticleAuthorHandler: NewArticleAuthorHandler(db),
|
||||
BookAuthorHandler: NewBookAuthorHandler(db),
|
||||
}
|
||||
return bookshelfHandler
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"kontor-api-gin/internal/models"
|
||||
"kontor-api-gin/internal/repository"
|
||||
"kontor-api-gin/internal/service"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type BookshelfPublisherHandler struct {
|
||||
Service *service.BookshelfPublisherService
|
||||
}
|
||||
|
||||
func NewBookshelfPublisherHandler(db *gorm.DB) *BookshelfPublisherHandler {
|
||||
handler := &BookshelfPublisherHandler{Service: service.NewBookshelfPublisherService(repository.NewBookshelfPublisherRepository(db))}
|
||||
return handler
|
||||
}
|
||||
|
||||
func (handler *BookshelfPublisherHandler) List(c *gin.Context) {
|
||||
publishers, err := handler.Service.List(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
dtos := models.ConvertBookshelfPublishersToDtos(publishers)
|
||||
c.JSON(http.StatusOK, dtos)
|
||||
}
|
||||
Reference in New Issue
Block a user