Skip to content

Commit 3534bab

Browse files
[Feature] Add uptated at to news (#544)
1 parent 7be8232 commit 3534bab

7 files changed

Lines changed: 40 additions & 2 deletions

File tree

src/main/java/com/itasocialacademy/oitassist/news/controller/NewsController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public ResponseEntity<List<ArchivedNewsByYearDto>> getArchivedNews() {
124124
@GetMapping("/admin")
125125
@PreAuthorize("hasAnyRole('ADMIN', 'ORG')")
126126
public ResponseEntity<PageResponse<ResponseNewsAdminListItemDto>> getAllNewsForAdmin(
127-
@ParameterObject @PageableDefault(size = 15, sort = "createdAt", direction = DESC) Pageable pageable,
127+
@ParameterObject @PageableDefault(size = 15, sort = "updatedAt", direction = DESC) Pageable pageable,
128128
@RequestParam(required = false) String search,
129129
@RequestParam(required = false) List<NewsStatus> statuses,
130130
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate dateFrom,

src/main/java/com/itasocialacademy/oitassist/news/dao/dto/response/ResponseNewsAdminListItemDto.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public class ResponseNewsAdminListItemDto {
2424
private OffsetDateTime createdAt;
2525
@Schema(description = "Date and time when the news was published")
2626
private OffsetDateTime publishedAt;
27+
@Schema(description = "Date and time when the news was last updated")
28+
private OffsetDateTime updatedAt;
2729
@Schema(description = "Date and time when the news was archived")
2830
private OffsetDateTime archivedAt;
2931
}

src/main/java/com/itasocialacademy/oitassist/news/dao/model/News.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import lombok.NoArgsConstructor;
99
import lombok.Setter;
1010
import org.hibernate.annotations.CreationTimestamp;
11+
import org.hibernate.annotations.UpdateTimestamp;
1112

1213
@Entity
1314
@Table(name = "news")
@@ -39,6 +40,10 @@ public class News {
3940
@Column(name = "published_at")
4041
private OffsetDateTime publishedAt;
4142

43+
@UpdateTimestamp
44+
@Column(name = "updated_at")
45+
private OffsetDateTime updatedAt;
46+
4247
@Column(name = "archived_at")
4348
private OffsetDateTime archivedAt;
4449

src/main/java/com/itasocialacademy/oitassist/security/config/SecurityConfig.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ public SecurityFilterChain configure(HttpSecurity http) {
8282
"/api/v1/news/**",
8383
"/api/v1/user-activation/verify",
8484
"/ui",
85-
"/ui/**")
85+
"/ui/**",
86+
"/uploads/news/**")
8687
.permitAll()
8788
.requestMatchers(
8889
"/index.html",

src/main/resources/db/changelog/db.changelog-master.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@
2727
<include file="/db/changelog/logs/2026-07-27-ch-create-invitations-Haleliuk.xml"/>
2828
<include file="/db/changelog/logs/2026-07-27-ch-alter-invitations-Haleliuk.xml"/>
2929
<include file="/db/changelog/logs/2026-08-04-ch-create-task-owners-table-Murashko.xml"/>
30+
<include file="/db/changelog/logs/2026-08-13-ch-add-news-updated-at-Rakuta.xml"/>
3031
</databaseChangeLog>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
5+
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
6+
7+
<changeSet id="add-news-updated-at" author="AnastasiaRakuta">
8+
<addColumn tableName="news">
9+
<column name="updated_at" type="TIMESTAMP WITH TIME ZONE">
10+
<constraints nullable="true"/>
11+
</column>
12+
</addColumn>
13+
14+
<update tableName="news">
15+
<column name="updated_at" valueComputed="created_at"/>
16+
<where>updated_at IS NULL</where>
17+
</update>
18+
19+
<addNotNullConstraint tableName="news"
20+
columnName="updated_at"
21+
columnDataType="TIMESTAMP WITH TIME ZONE"/>
22+
23+
<rollback>
24+
<dropColumn tableName="news" columnName="updated_at"/>
25+
</rollback>
26+
</changeSet>
27+
</databaseChangeLog>

src/test/java/com/itasocialacademy/oitassist/news/controller/NewsControllerTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ void testGetAllNewsForAdmin_shouldReturnPagedResponse() throws Exception {
269269
NewsStatus.PUBLISHED,
270270
OffsetDateTime.parse("2026-03-14T08:00:00Z"),
271271
OffsetDateTime.parse("2026-03-15T10:30:00Z"),
272+
OffsetDateTime.parse("2026-03-15T10:30:00Z"),
272273
null);
273274

274275
Page<ResponseNewsAdminListItemDto> page = new PageImpl<>(
@@ -302,6 +303,7 @@ void testGetAllNewsForAdmin_withSearchParam_returnsMatchingResults() throws Exce
302303
NewsStatus.DRAFT,
303304
OffsetDateTime.parse("2026-03-10T12:00:00Z"),
304305
OffsetDateTime.parse("2026-03-10T14:20:00Z"),
306+
OffsetDateTime.parse("2026-03-10T14:20:00Z"),
305307
null);
306308

307309
Page<ResponseNewsAdminListItemDto> page = new PageImpl<>(

0 commit comments

Comments
 (0)