Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
/go.work.sum
/.cache/
*.log
BackEnd/storage

# ====================================
# 🔑 Environment & sensitive files
Expand Down
Empty file removed BackEnd/README.md
Empty file.
80 changes: 0 additions & 80 deletions BackEnd/Readme.md

This file was deleted.

2 changes: 2 additions & 0 deletions BackEnd/internal/database/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Models struct {
Blogs model.BlogModel
Gallery model.GalleryModel
Pengurus model.PengurusModel
// Activities model.ActivityModel // Uncomment if you have ActivityModel
}

func NewModel(db *gorm.DB) Models {
Expand All @@ -21,5 +22,6 @@ func NewModel(db *gorm.DB) Models {
Blogs: model.BlogModel{DB: db},
Gallery: model.GalleryModel{DB: db},
Pengurus: model.PengurusModel{DB: db},
// Activities: model.ActivityModel{DB: db}, // Uncomment if you have ActivityModel
}
}
74 changes: 65 additions & 9 deletions BackEnd/internal/handler/blog.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,45 @@ import (
"web_doscom/internal/database/model"

"github.com/gin-gonic/gin"
"gorm.io/gorm"
)

type BlogHandler struct {
DB *gorm.DB
Model *model.BlogModel
}

func NewBlogHandler(db *gorm.DB) *BlogHandler {
return &BlogHandler{DB: db}
func NewBlogHandler(db *model.BlogModel) *BlogHandler {
return &BlogHandler{Model: db}
}

// Create Blog
func (h *BlogHandler) CreateBlog(c *gin.Context) {
var input model.RegisterBlog
if err := c.ShouldBindJSON(&input); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

blog := &model.Blog{
Title: input.Title,
GalleryID: input.GalleryID,
Slug: input.Slug,
Content: input.Content,
Kategori: input.Kategori,
PublishedAt: input.PublishedAt,
IsPublished: input.IsPublished,
WorkID: input.WorkID,
ActivityID: input.ActivityID,
PengurusID: input.PengurusID,
}

if err := h.DB.Create(blog).Error; err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}

c.JSON(http.StatusOK, blog)
}

// Create Blog (validation only, no DB insert)
func (h *BlogHandler) Create(c *gin.Context) {
var blog model.Blog
Expand Down Expand Up @@ -46,7 +73,7 @@ func (h *BlogHandler) Create(c *gin.Context) {
// List all Blogs
func (h *BlogHandler) List(c *gin.Context) {
var blogs []model.Blog
if err := h.DB.Order("created_at DESC").Find(&blogs).Error; err != nil {
if err := h.Model.Order("created_at DESC").Find(&blogs).Error; err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
Expand Down Expand Up @@ -100,16 +127,45 @@ func (h *BlogHandler) Update(c *gin.Context) {
c.JSON(http.StatusOK, blog)
}

// UpdateKategori updates the kategori of a blog by id
func (h *BlogHandler) UpdateKategori(c *gin.Context) {
// TODO: implement the logic for updating kategori
c.JSON(200, gin.H{"message": "UpdateKategori not implemented"})
id, err := strconv.Atoi(c.Param("id"))
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid id"})
return
}
var req struct {
Kategori string `json:"kategori" binding:"required"`
}
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
var blog model.Blog
if err := h.DB.First(&blog, id).Error; err != nil {
c.JSON(http.StatusNotFound, gin.H{"error": "blog not found"})
return
}
blog.Kategori = req.Kategori
if err := h.DB.Save(&blog).Error; err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{"message": "Kategori updated", "blog": blog})
}

// ListByKategori returns blogs filtered by kategori
func (h *BlogHandler) ListByKategori(c *gin.Context) {
kategori := c.Param("kategori")
// TODO: Implement logic to list blogs by kategori
c.JSON(200, gin.H{
var blogs []model.Blog
if err := h.DB.Where("kategori = ?", kategori).Order("created_at DESC").Find(&blogs).Error; err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{
"message": "List blogs by kategori",
"kategori": kategori,
"blogs": blogs,
})
}

Expand Down
2 changes: 1 addition & 1 deletion BackEnd/internal/handler/gallery.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (m *GalleryHandler) InsertGallery(c *gin.Context) {
// @Tags Gallery
// @Accept json
// @Produce json
// @Param type query string true "Gallery type (misal: event, pengurus, dokumentasi)"
// @Param type query string true "Gallery type (fun, proker, achievment, work, activity, blog, pengurus, etc)"
// @Param page query int false "Page number"
// @Param limit query int false "Page limit"
// @Success 200 {object} map[string]interface{} "Successfully fetch gallery data"
Expand Down
2 changes: 1 addition & 1 deletion BackEnd/internal/routes/route/pengurus_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ func RegisterPengurusRoutes(rg *gin.RouterGroup, pengurusHandler *handler.Pengur
p := rg.Group("/pengurus")
// public api
{
p.GET("/:id", pengurusHandler.GetPengurus)
p.GET("/", pengurusHandler.GetAllPengurus)
}

// private api -> need auth
pengurusAuth := p.Group("/")
pengurusAuth.Use(auth.AuthMiddleware("ANGGOTA", "KOOR", "BPH", "ADMIN"))
{
p.GET("/:id", pengurusHandler.GetPengurus)
pengurusAuth.POST("/", pengurusHandler.CreatePengurus)
pengurusAuth.PUT("/:id", pengurusHandler.UpdatePengurus)
}
Expand Down
2 changes: 1 addition & 1 deletion BackEnd/internal/service/gallery_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (m *GalleryService) InsertGallery(gallery *model.Gallery) (*model.Gallery,
}

// wrapper for get gallery by type
func (m *GalleryService) GetAllGalleryByType(tipe string, limit, offset, page int) ([]*model.GalleryResponse, int64, error) {
func (m *GalleryService) GetAllGalleryByType(tipe string, page, limit, offset int) ([]*model.GalleryResponse, int64, error) {

var response []*model.GalleryResponse
galleries, count, err := m.Model.GetGalleryByType(tipe, page, limit, offset)
Expand Down
Binary file modified BackEnd/tmp/main
Binary file not shown.