mirror of
https://github.com/Floriansylvain/RenewCMS.git
synced 2026-08-19 11:43:22 +02:00
feat: draft/online post field #26
This commit is contained in:
@@ -11,6 +11,7 @@ type Post struct {
|
||||
Title string
|
||||
Body string
|
||||
Images []*Image `gorm:"many2many:post_images;"`
|
||||
IsOnline bool `gorm:"not_null;default:false"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime"`
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ func NewPostRepository(db *gorm.DB) *PostRepository {
|
||||
}
|
||||
|
||||
func mapPostToDomain(post entity.Post) domain.Post {
|
||||
return domain.FromDb(post.ID, post.Title, post.Body, post.Images, post.CreatedAt, post.UpdatedAt)
|
||||
return domain.FromDb(post.ID, post.Title, post.Body, post.Images, post.IsOnline, post.CreatedAt, post.UpdatedAt)
|
||||
}
|
||||
|
||||
func (a *PostRepository) Get(id uint32) (domain.Post, error) {
|
||||
@@ -87,6 +87,7 @@ func (a *PostRepository) UpdateBody(id uint32, body string) (domain.Post, error)
|
||||
localPost.Title,
|
||||
localPost.Body,
|
||||
localPost.Images,
|
||||
localPost.IsOnline,
|
||||
localPost.CreatedAt,
|
||||
localPost.UpdatedAt,
|
||||
)
|
||||
@@ -94,6 +95,22 @@ func (a *PostRepository) UpdateBody(id uint32, body string) (domain.Post, error)
|
||||
return newPost, nil
|
||||
}
|
||||
|
||||
func (a *PostRepository) UpdateIsOnline(id uint32, isOnline bool) (domain.Post, error) {
|
||||
var localPost entity.Post
|
||||
err := a.db.Model(&entity.Post{}).First(&localPost, id).Error
|
||||
if err != nil {
|
||||
return domain.Post{}, err
|
||||
}
|
||||
|
||||
localPost.IsOnline = isOnline
|
||||
err = a.db.Save(&localPost).Error
|
||||
if err != nil {
|
||||
return domain.Post{}, err
|
||||
}
|
||||
|
||||
return mapPostToDomain(localPost), nil
|
||||
}
|
||||
|
||||
func (a *PostRepository) Delete(id uint32) error {
|
||||
return a.db.Delete(&entity.Post{}, id).Error
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@
|
||||
</li>
|
||||
</ul>
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-body-tertiary text-decoration-underline" href="https://www.paypal.com/donate/?hosted_button_id=S6LUFUYK84CYY">support me!</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link disconnect-link" href="/logout">Log out</a>
|
||||
</li>
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
{{.Head}}
|
||||
|
||||
<style>
|
||||
.btn-outline-info:hover > *,
|
||||
.btn-outline-danger:hover > * {
|
||||
fill: #fff !important;
|
||||
transition: fill ease-in-out 50ms;
|
||||
@@ -22,12 +23,13 @@
|
||||
<th scope="col">Name</th>
|
||||
<th scope="col">Creation Date</th>
|
||||
<th scope="col">Edition Date</th>
|
||||
<th scope="col">Status</th>
|
||||
<th scope="col">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td colspan="4" class="text-center">
|
||||
<td colspan="5" class="text-center">
|
||||
<form action="post/create" method="get">
|
||||
<button class="btn btn-sm btn-link w-100 h-100" type="submit">Create a new post...</button>
|
||||
</form>
|
||||
@@ -38,12 +40,26 @@
|
||||
<td>{{ $post.Title }}</td>
|
||||
<td class="date">{{ $post.CreatedAt }}</td>
|
||||
<td class="date">{{ $post.UpdatedAt }}</td>
|
||||
<td>{{ if $post.IsOnline }}🟢 Online{{ else }}🟠 Offline{{ end }}</td>
|
||||
<td>
|
||||
<a href="/post/{{ $post.ID }}/edit" class="btn btn-secondary btn-sm">
|
||||
<a href="/post/{{ $post.ID }}/edit" class="btn btn-outline-primary btn-sm">
|
||||
<svg width="12px" height="12px" fill="currentColor">
|
||||
<use xlink:href="/static/bootstrap-icons.svg#pen"/>
|
||||
</svg>
|
||||
</a>
|
||||
{{ if $post.IsOnline }}
|
||||
<a href="/post/{{ $post.ID }}/unpublish" class="btn btn-outline-info btn-sm">
|
||||
<svg width="12px" height="12px" fill="currentColor">
|
||||
<use xlink:href="/static/bootstrap-icons.svg#eye-slash"/>
|
||||
</svg>
|
||||
</a>
|
||||
{{ else }}
|
||||
<a href="/post/{{ $post.ID }}/publish" class="btn btn-outline-info btn-sm">
|
||||
<svg width="12px" height="12px" fill="currentColor">
|
||||
<use xlink:href="/static/bootstrap-icons.svg#eye"/>
|
||||
</svg>
|
||||
</a>
|
||||
{{ end }}
|
||||
<a href="/post/{{ $post.Title }}/delete" class="btn btn-outline-danger btn-sm" data-bs-toggle="modal"
|
||||
data-bs-target="#{{ $post.ID }}">
|
||||
<svg width=" 12px" height="12px" fill="currentColor">
|
||||
@@ -60,7 +76,8 @@
|
||||
aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p>You are about to delete the post <b>« {{ $post.Title }} »</b>, this is definitive, are you sure?</p>
|
||||
<p>You are about to delete the post <b>« {{ $post.Title }} »</b>, this is definitive,
|
||||
are you sure?</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-outline-secondary" data-bs-dismiss="modal">Cancel
|
||||
|
||||
Reference in New Issue
Block a user