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
156 changes: 156 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@
"devDependencies": {
"@playwright/test": "^1.44.1",
"@types/node": "^20.14.2"
},
"dependencies": {
}
}
21 changes: 20 additions & 1 deletion server/service/core/action/medium/list.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package medium

import (
"fmt"
"net/http"
"time"

"github.com/factly/dega-server/service/core/service"
"github.com/factly/dega-server/util"
Expand Down Expand Up @@ -37,9 +39,26 @@ func list(w http.ResponseWriter, r *http.Request) {
searchQuery := r.URL.Query().Get("q")
sort := r.URL.Query().Get("sort")
offset, limit := paginationx.Parse(r.URL.Query())
dateStr := r.URL.Query().Get("date")

var year int
var month time.Month
var yearMonthProvided bool

if dateStr != "" {
layout := "2006-01"
dateInt, err := time.Parse(layout, dateStr)
if err != nil {
fmt.Println("Error parsing date:", err)
return
}
year = dateInt.Year()
month = dateInt.Month()
yearMonthProvided = true
}

mediumService := service.GetMediumService()
result, errMessages := mediumService.List(authCtx.SpaceID, offset, limit, searchQuery, sort)
result, errMessages := mediumService.List(authCtx.SpaceID, offset, limit, searchQuery, sort, year, month, yearMonthProvided, dateStr)
if errMessages != nil {
errorx.Render(w, errMessages)
return
Expand Down
33 changes: 27 additions & 6 deletions server/service/core/service/medium.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"net/http"
"strings"
"time"

Expand Down Expand Up @@ -40,14 +41,15 @@ type Medium struct {
type pagingMedium struct {
Total int64 `json:"total"`
Nodes []model.Medium `json:"nodes"`
Date time.Time `json:"date"`
}

type MediumService struct {
model *gorm.DB
}
type IMediumService interface {
GetById(sID, id uuid.UUID) (model.Medium, error)
List(sID uuid.UUID, offset, limit int, searchQuery, sort string) (pagingMedium, []errorx.Message)
List(sID uuid.UUID, offset, limit int, searchQuery, sort string, year int, month time.Month, yearMonthProvided bool, dateStr string) (pagingMedium, []errorx.Message)
Create(ctx context.Context, sID uuid.UUID, uID string, mediumList []Medium) (pagingMedium, []errorx.Message)
Update(sID, id uuid.UUID, uID string, medium *Medium) (model.Medium, []errorx.Message)
Delete(sID, id uuid.UUID) []errorx.Message
Expand All @@ -71,17 +73,36 @@ func (ms MediumService) GetById(sID, id uuid.UUID) (model.Medium, error) {
return *result, err
}

func (ms MediumService) List(sID uuid.UUID, offset, limit int, searchQuery, sort string) (pagingMedium, []errorx.Message) {
func (ms MediumService) List(sID uuid.UUID, offset, limit int, searchQuery, sort string, year int, month time.Month, yearMonthProvided bool, dateStr string) (pagingMedium, []errorx.Message) {
result := pagingMedium{}
result.Nodes = make([]model.Medium, 0)

tx := config.DB.Model(&model.Medium{}).Where(&model.Medium{
SpaceID: sID,
})

if yearMonthProvided {
// Validate year and month inputs
if year < 1 || (month < 1 || month > 12) {
return pagingMedium{}, []errorx.Message{errorx.GetMessage("Invalid year or month", http.StatusBadRequest)}
}

// Add year filter
if year > 0 {
tx = tx.Where("EXTRACT(YEAR FROM created_at) = ?", year)
}

// Add month filter
if month > 0 && month <= 12 {
tx = tx.Where("EXTRACT(MONTH FROM created_at) = ?", int(month))
}

}

if sort != "asc" {
sort = "desc"
}

tx := config.DB.Model(&model.Medium{}).Where(&model.Medium{
SpaceID: sID,
}).Order("created_at " + sort)
tx = tx.Order("created_at " + sort)

if searchQuery != "" {

Expand Down
8 changes: 4 additions & 4 deletions studio/src/actions/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ export const getMedia = (query, profile) => {
params: query,
})
.then((response) => {
dispatch(addMedia(response.data.nodes));
if (response.data === "") return [];
dispatch(addMedia(response?.data?.nodes));
dispatch(
addMediaRequest({
data: response.data.nodes.map((item) => item.id),
data: response?.data?.nodes.map((item) => item.id),
query: query,
total: response.data.total,
total: response?.data?.total,
}),
);
})
Expand Down Expand Up @@ -59,7 +60,6 @@ export const createMedium = (data, profile) => {
return axios
.post(MEDIA_API, profile ? data[0] : data)
.then((response) => {
dispatch(resetMedia());
dispatch(addSuccessNotification('Medium created'));
return profile ? response.data : response.data.nodes[0];
})
Expand Down
6 changes: 3 additions & 3 deletions studio/src/pages/media/components/MediumList.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function MediumList({ data, filters, setFilters }) {
xl: 4,
xxl: 5,
}}
pagination={{
pagination={data.total > 0 ? {
showTotal: (total, range) => `${range[0]}-${range[1]} of ${total} results`,
total: data.total,
current: filters.page,
Expand All @@ -24,15 +24,14 @@ function MediumList({ data, filters, setFilters }) {
setFilters({ ...filters, page: pageNumber || 1, limit: pageSize });
},
pageSizeOptions: ['10', '15', '20'],
}}
} : false}
dataSource={data.media}
renderItem={(item) => (
<List.Item style={{ borderRadius: '8px', margin: 0 }}>
<Link to={{ pathname: `/media/${item.id}/edit` }}>
<Card
size="default"
key={item.url}
// title={item.name}
hoverable
bodyStyle={{ padding: 0 }}
cover={
Expand All @@ -43,6 +42,7 @@ function MediumList({ data, filters, setFilters }) {
item.url?.[window.REACT_APP_ENABLE_IMGPROXY ? 'proxy' : 'raw']
}?gravity:sm/resize:fill:220:220` || ''
// 'https://source.unsplash.com/random/?city,night'

}
style={{
maxWidth: '100%',
Expand Down
Loading