File src/main/java/hu/dns/honlap/domain/PieceOfNews.java changed (mode: 100644) (index 4f1376c..9132d6d) |
1 |
1 |
package hu.dns.honlap.domain; |
package hu.dns.honlap.domain; |
2 |
2 |
|
|
3 |
3 |
import io.swagger.annotations.ApiModel; |
import io.swagger.annotations.ApiModel; |
4 |
|
import org.hibernate.annotations.Cache; |
|
5 |
|
import org.hibernate.annotations.CacheConcurrencyStrategy; |
|
6 |
|
|
|
|
4 |
|
import java.time.Instant; |
|
5 |
|
import java.time.LocalDate; |
|
6 |
|
import java.util.UUID; |
7 |
7 |
import javax.persistence.*; |
import javax.persistence.*; |
8 |
8 |
import javax.validation.constraints.*; |
import javax.validation.constraints.*; |
9 |
|
|
|
10 |
|
import java.time.Instant; |
|
|
9 |
|
import org.hibernate.annotations.Cache; |
|
10 |
|
import org.hibernate.annotations.CacheConcurrencyStrategy; |
11 |
11 |
|
|
12 |
12 |
/** |
/** |
13 |
13 |
* Hírek |
* Hírek |
|
... |
... |
import java.time.Instant; |
15 |
15 |
@ApiModel(description = "Hírek") |
@ApiModel(description = "Hírek") |
16 |
16 |
@Entity |
@Entity |
17 |
17 |
@Table(name = "piece_of_news") |
@Table(name = "piece_of_news") |
18 |
|
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) |
|
|
18 |
|
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE) |
19 |
19 |
public class PieceOfNews extends AbstractAuditingEntity { |
public class PieceOfNews extends AbstractAuditingEntity { |
20 |
20 |
|
|
21 |
21 |
private static final long serialVersionUID = 1L; |
private static final long serialVersionUID = 1L; |
|
... |
... |
public class PieceOfNews extends AbstractAuditingEntity { |
27 |
27 |
|
|
28 |
28 |
@NotNull |
@NotNull |
29 |
29 |
@Column(name = "app_id", nullable = false) |
@Column(name = "app_id", nullable = false) |
30 |
|
private Integer appId; |
|
|
30 |
|
private UUID appId; |
31 |
31 |
|
|
32 |
32 |
@NotNull |
@NotNull |
33 |
33 |
@Column(name = "news_date", nullable = false) |
@Column(name = "news_date", nullable = false) |
34 |
|
private Instant newsDate; |
|
|
34 |
|
private LocalDate newsDate; |
35 |
35 |
|
|
36 |
36 |
@NotNull |
@NotNull |
37 |
37 |
@Size(max = 300) |
@Size(max = 300) |
|
... |
... |
public class PieceOfNews extends AbstractAuditingEntity { |
51 |
51 |
@Column(name = "publish_date") |
@Column(name = "publish_date") |
52 |
52 |
private Instant publishDate; |
private Instant publishDate; |
53 |
53 |
|
|
54 |
|
// jhipster-needle-entity-add-field - JHipster will add fields here, do not remove |
|
|
54 |
|
// jhipster-needle-entity-add-field - JHipster will add fields here |
55 |
55 |
public Long getId() { |
public Long getId() { |
56 |
56 |
return id; |
return id; |
57 |
57 |
} |
} |
|
... |
... |
public class PieceOfNews extends AbstractAuditingEntity { |
60 |
60 |
this.id = id; |
this.id = id; |
61 |
61 |
} |
} |
62 |
62 |
|
|
63 |
|
public Integer getAppId() { |
|
64 |
|
return appId; |
|
|
63 |
|
public PieceOfNews id(Long id) { |
|
64 |
|
this.id = id; |
|
65 |
|
return this; |
|
66 |
|
} |
|
67 |
|
|
|
68 |
|
public UUID getAppId() { |
|
69 |
|
return this.appId; |
65 |
70 |
} |
} |
66 |
71 |
|
|
67 |
|
public PieceOfNews appId(Integer appId) { |
|
|
72 |
|
public PieceOfNews appId(UUID appId) { |
68 |
73 |
this.appId = appId; |
this.appId = appId; |
69 |
74 |
return this; |
return this; |
70 |
75 |
} |
} |
71 |
76 |
|
|
72 |
|
public void setAppId(Integer appId) { |
|
|
77 |
|
public void setAppId(UUID appId) { |
73 |
78 |
this.appId = appId; |
this.appId = appId; |
74 |
79 |
} |
} |
75 |
80 |
|
|
76 |
|
public Instant getNewsDate() { |
|
77 |
|
return newsDate; |
|
|
81 |
|
public LocalDate getNewsDate() { |
|
82 |
|
return this.newsDate; |
78 |
83 |
} |
} |
79 |
84 |
|
|
80 |
|
public PieceOfNews newsDate(Instant newsDate) { |
|
|
85 |
|
public PieceOfNews newsDate(LocalDate newsDate) { |
81 |
86 |
this.newsDate = newsDate; |
this.newsDate = newsDate; |
82 |
87 |
return this; |
return this; |
83 |
88 |
} |
} |
84 |
89 |
|
|
85 |
|
public void setNewsDate(Instant newsDate) { |
|
|
90 |
|
public void setNewsDate(LocalDate newsDate) { |
86 |
91 |
this.newsDate = newsDate; |
this.newsDate = newsDate; |
87 |
92 |
} |
} |
88 |
93 |
|
|
89 |
94 |
public String getHeadline() { |
public String getHeadline() { |
90 |
|
return headline; |
|
|
95 |
|
return this.headline; |
91 |
96 |
} |
} |
92 |
97 |
|
|
93 |
98 |
public PieceOfNews headline(String headline) { |
public PieceOfNews headline(String headline) { |
|
... |
... |
public class PieceOfNews extends AbstractAuditingEntity { |
100 |
105 |
} |
} |
101 |
106 |
|
|
102 |
107 |
public String getContent() { |
public String getContent() { |
103 |
|
return content; |
|
|
108 |
|
return this.content; |
104 |
109 |
} |
} |
105 |
110 |
|
|
106 |
111 |
public PieceOfNews content(String content) { |
public PieceOfNews content(String content) { |
|
... |
... |
public class PieceOfNews extends AbstractAuditingEntity { |
113 |
118 |
} |
} |
114 |
119 |
|
|
115 |
120 |
public String getLink() { |
public String getLink() { |
116 |
|
return link; |
|
|
121 |
|
return this.link; |
117 |
122 |
} |
} |
118 |
123 |
|
|
119 |
124 |
public PieceOfNews link(String link) { |
public PieceOfNews link(String link) { |
|
... |
... |
public class PieceOfNews extends AbstractAuditingEntity { |
126 |
131 |
} |
} |
127 |
132 |
|
|
128 |
133 |
public Instant getPublishDate() { |
public Instant getPublishDate() { |
129 |
|
return publishDate; |
|
|
134 |
|
return this.publishDate; |
130 |
135 |
} |
} |
131 |
136 |
|
|
132 |
137 |
public PieceOfNews publishDate(Instant publishDate) { |
public PieceOfNews publishDate(Instant publishDate) { |
|
... |
... |
public class PieceOfNews extends AbstractAuditingEntity { |
158 |
163 |
return this; |
return this; |
159 |
164 |
} |
} |
160 |
165 |
|
|
161 |
|
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove |
|
|
166 |
|
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here |
162 |
167 |
|
|
163 |
168 |
@Override |
@Override |
164 |
169 |
public boolean equals(Object o) { |
public boolean equals(Object o) { |
|
... |
... |
public class PieceOfNews extends AbstractAuditingEntity { |
173 |
178 |
|
|
174 |
179 |
@Override |
@Override |
175 |
180 |
public int hashCode() { |
public int hashCode() { |
176 |
|
return 31; |
|
|
181 |
|
// see https://vladmihalcea.com/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/ |
|
182 |
|
return getClass().hashCode(); |
177 |
183 |
} |
} |
178 |
184 |
|
|
|
185 |
|
// prettier-ignore |
179 |
186 |
@Override |
@Override |
180 |
187 |
public String toString() { |
public String toString() { |
181 |
188 |
return "PieceOfNews{" + |
return "PieceOfNews{" + |
182 |
189 |
"id=" + getId() + |
"id=" + getId() + |
183 |
|
", appId=" + getAppId() + |
|
|
190 |
|
", appId='" + getAppId() + "'" + |
184 |
191 |
", newsDate='" + getNewsDate() + "'" + |
", newsDate='" + getNewsDate() + "'" + |
185 |
192 |
", headline='" + getHeadline() + "'" + |
", headline='" + getHeadline() + "'" + |
186 |
193 |
", content='" + getContent() + "'" + |
", content='" + getContent() + "'" + |
File src/main/java/hu/dns/honlap/repository/PieceOfNewsRepository.java changed (mode: 100644) (index 5707f06..bb65156) |
... |
... |
import hu.dns.honlap.domain.PieceOfNews; |
4 |
4 |
|
|
5 |
5 |
import java.time.Instant; |
import java.time.Instant; |
6 |
6 |
import java.util.List; |
import java.util.List; |
|
7 |
|
import java.util.UUID; |
7 |
8 |
|
|
8 |
9 |
import org.springframework.data.jpa.repository.*; |
import org.springframework.data.jpa.repository.*; |
9 |
10 |
import org.springframework.stereotype.Repository; |
import org.springframework.stereotype.Repository; |
|
... |
... |
import org.springframework.stereotype.Repository; |
14 |
15 |
@SuppressWarnings("unused") |
@SuppressWarnings("unused") |
15 |
16 |
@Repository |
@Repository |
16 |
17 |
public interface PieceOfNewsRepository extends JpaRepository<PieceOfNews, Long> { |
public interface PieceOfNewsRepository extends JpaRepository<PieceOfNews, Long> { |
17 |
|
List<PieceOfNews> findByAppIdAndPublishDateLessThanOrderByNewsDateDesc(Integer appId, Instant publishDate); |
|
18 |
|
List<PieceOfNews> findFirst4ByAppIdAndPublishDateLessThanOrderByNewsDateDesc(Integer appId, Instant publishDate); |
|
|
18 |
|
List<PieceOfNews> findByAppIdAndPublishDateLessThanOrderByNewsDateDesc(UUID appId, Instant publishDate); |
|
19 |
|
List<PieceOfNews> findFirst4ByAppIdAndPublishDateLessThanOrderByNewsDateDesc(UUID appId, Instant publishDate); |
19 |
20 |
} |
} |
File src/main/java/hu/dns/honlap/web/rest/PieceOfNewsResource.java changed (mode: 100644) (index e75291c..cd7781b) |
... |
... |
import java.net.URISyntaxException; |
24 |
24 |
import java.time.Instant; |
import java.time.Instant; |
25 |
25 |
import java.util.List; |
import java.util.List; |
26 |
26 |
import java.util.Optional; |
import java.util.Optional; |
|
27 |
|
import java.util.UUID; |
27 |
28 |
|
|
28 |
29 |
/** |
/** |
29 |
30 |
* REST controller for managing {@link hu.dns.honlap.domain.PieceOfNews}. |
* REST controller for managing {@link hu.dns.honlap.domain.PieceOfNews}. |
|
... |
... |
public class PieceOfNewsResource { |
108 |
109 |
@GetMapping("/piece-of-news/fresh") |
@GetMapping("/piece-of-news/fresh") |
109 |
110 |
public ResponseEntity<List<PieceOfNews>> getFreshNews() { |
public ResponseEntity<List<PieceOfNews>> getFreshNews() { |
110 |
111 |
log.debug("REST request to get the fresh news"); |
log.debug("REST request to get the fresh news"); |
111 |
|
List<PieceOfNews> news = pieceOfNewsRepository.findFirst4ByAppIdAndPublishDateLessThanOrderByNewsDateDesc(1, Instant.now()); |
|
|
112 |
|
List<PieceOfNews> news = pieceOfNewsRepository.findFirst4ByAppIdAndPublishDateLessThanOrderByNewsDateDesc(UUID.fromString("c68f359a-9c6d-4d01-9966-63a351c307d7"), Instant.now()); |
112 |
113 |
return ResponseEntity.ok().body(news); |
return ResponseEntity.ok().body(news); |
113 |
114 |
} |
} |
114 |
115 |
|
|
|
... |
... |
public class PieceOfNewsResource { |
120 |
121 |
@GetMapping("/piece-of-news/archive") |
@GetMapping("/piece-of-news/archive") |
121 |
122 |
public ResponseEntity<List<PieceOfNews>> getArchiveNews() { |
public ResponseEntity<List<PieceOfNews>> getArchiveNews() { |
122 |
123 |
log.debug("REST request to get the archive news"); |
log.debug("REST request to get the archive news"); |
123 |
|
List<PieceOfNews> news = pieceOfNewsRepository.findByAppIdAndPublishDateLessThanOrderByNewsDateDesc(1, Instant.now()); |
|
|
124 |
|
List<PieceOfNews> news = pieceOfNewsRepository.findByAppIdAndPublishDateLessThanOrderByNewsDateDesc(UUID.fromString("c68f359a-9c6d-4d01-9966-63a351c307d7"), Instant.now()); |
124 |
125 |
return ResponseEntity.ok().body(news); |
return ResponseEntity.ok().body(news); |
125 |
126 |
} |
} |
126 |
127 |
|
|
File src/test/java/hu/dns/honlap/web/rest/PieceOfNewsResourceIT.java changed (mode: 100644) (index 7f88758..3d332ad) |
... |
... |
import org.springframework.test.web.servlet.MockMvc; |
15 |
15 |
import org.springframework.transaction.annotation.Transactional; |
import org.springframework.transaction.annotation.Transactional; |
16 |
16 |
import javax.persistence.EntityManager; |
import javax.persistence.EntityManager; |
17 |
17 |
import java.time.Instant; |
import java.time.Instant; |
|
18 |
|
import java.time.LocalDate; |
18 |
19 |
import java.time.temporal.ChronoUnit; |
import java.time.temporal.ChronoUnit; |
19 |
20 |
import java.util.List; |
import java.util.List; |
|
21 |
|
import java.util.UUID; |
20 |
22 |
|
|
21 |
23 |
import static org.assertj.core.api.Assertions.assertThat; |
import static org.assertj.core.api.Assertions.assertThat; |
22 |
24 |
import static org.hamcrest.Matchers.hasItem; |
import static org.hamcrest.Matchers.hasItem; |
|
... |
... |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. |
32 |
34 |
@WithMockUser |
@WithMockUser |
33 |
35 |
public class PieceOfNewsResourceIT { |
public class PieceOfNewsResourceIT { |
34 |
36 |
|
|
35 |
|
private static final Integer DEFAULT_APP_ID = 1; |
|
36 |
|
private static final Integer UPDATED_APP_ID = 2; |
|
|
37 |
|
private static final UUID DEFAULT_APP_ID = UUID.fromString("c68f359a-9c6d-4d01-9966-63a351c307d2"); |
|
38 |
|
private static final UUID UPDATED_APP_ID = UUID.fromString("c68f359a-9c6d-4d01-9966-63a351c307d7"); |
37 |
39 |
|
|
38 |
|
private static final Instant DEFAULT_NEWS_DATE = Instant.ofEpochMilli(0L); |
|
39 |
|
private static final Instant UPDATED_NEWS_DATE = Instant.now().truncatedTo(ChronoUnit.MILLIS); |
|
|
40 |
|
private static final LocalDate DEFAULT_NEWS_DATE = LocalDate.now().minusDays(18L); |
|
41 |
|
private static final LocalDate UPDATED_NEWS_DATE = LocalDate.now(); |
40 |
42 |
|
|
41 |
43 |
private static final String DEFAULT_HEADLINE = "AAAAAAAAAA"; |
private static final String DEFAULT_HEADLINE = "AAAAAAAAAA"; |
42 |
44 |
private static final String UPDATED_HEADLINE = "BBBBBBBBBB"; |
private static final String UPDATED_HEADLINE = "BBBBBBBBBB"; |