-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make repository structure for backend.
- Loading branch information
1 parent
0f9ba9c
commit 84b8817
Showing
16 changed files
with
358 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
backend/src/main/java/com/egor/rssaggregator/dto/input/AddFeedDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.egor.rssaggregator.dto.input; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
@Data | ||
@Builder | ||
public class AddFeedDto { | ||
@NotBlank | ||
@Size(max = 50) | ||
private String name; | ||
|
||
@NotBlank | ||
@Size(max = 250) | ||
private String url; | ||
} |
18 changes: 18 additions & 0 deletions
18
backend/src/main/java/com/egor/rssaggregator/dto/input/LoginDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.egor.rssaggregator.dto.input; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
@Data | ||
@Builder | ||
public class LoginDto { | ||
@NotBlank | ||
@Size(max = 50) | ||
private String email; | ||
|
||
@NotBlank | ||
@Size(max = 32) | ||
private String password; | ||
} |
18 changes: 18 additions & 0 deletions
18
backend/src/main/java/com/egor/rssaggregator/dto/input/RegDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.egor.rssaggregator.dto.input; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
@Data | ||
@Builder | ||
public class RegDto { | ||
@NotBlank | ||
@Size(max = 50) | ||
private String email; | ||
|
||
@NotBlank | ||
@Size(max = 32) | ||
private String password; | ||
} |
18 changes: 18 additions & 0 deletions
18
backend/src/main/java/com/egor/rssaggregator/dto/output/GetFeedDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.egor.rssaggregator.dto.output; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
@Data | ||
@Builder | ||
public class GetFeedDto { | ||
@NotBlank | ||
@Size(max = 50) | ||
private String name; | ||
|
||
@NotBlank | ||
@Size(max = 250) | ||
private String url; | ||
} |
24 changes: 24 additions & 0 deletions
24
backend/src/main/java/com/egor/rssaggregator/dto/output/MainNewsEntryDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.egor.rssaggregator.dto.output; | ||
|
||
import com.egor.rssaggregator.entity.Feed; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Data | ||
@Builder | ||
public class MainNewsEntryDto { | ||
@NotBlank | ||
@Size(max = 100) | ||
private String newsHead; | ||
|
||
@NotNull | ||
private LocalDate newsDate; | ||
|
||
@NotNull | ||
private Feed source; | ||
} |
26 changes: 26 additions & 0 deletions
26
backend/src/main/java/com/egor/rssaggregator/dto/output/MoreTextNewsEntryDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.egor.rssaggregator.dto.output; | ||
|
||
import com.egor.rssaggregator.entity.Feed; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Data | ||
@Builder | ||
public class MoreTextNewsEntryDto { | ||
@NotBlank | ||
@Size(max = 100) | ||
private String newsHead; | ||
|
||
@NotNull | ||
private LocalDate newsDate; | ||
|
||
private String newsText; | ||
|
||
@NotNull | ||
private Feed source; | ||
} |
48 changes: 48 additions & 0 deletions
48
backend/src/main/java/com/egor/rssaggregator/entity/Feed.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.egor.rssaggregator.entity; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.*; | ||
import org.hibernate.proxy.HibernateProxy; | ||
|
||
import java.util.Objects; | ||
|
||
@Entity | ||
@Table(name = "feeds") | ||
@Getter | ||
@Setter | ||
@ToString | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class Feed { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "id", nullable = false) | ||
private Long id; | ||
|
||
@Column(name = "name", unique = true, length = 50, nullable = false) | ||
private String name; | ||
|
||
@Column(name = "url", unique = true, length = 250, nullable = false) | ||
private String url; | ||
|
||
@ManyToOne(cascade = CascadeType.ALL) | ||
@JoinColumn(name = "user_id") | ||
private User user; | ||
|
||
@Override | ||
public final boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null) return false; | ||
Class<?> oEffectiveClass = o instanceof HibernateProxy ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() : o.getClass(); | ||
Class<?> thisEffectiveClass = this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() : this.getClass(); | ||
if (thisEffectiveClass != oEffectiveClass) return false; | ||
Feed feed = (Feed) o; | ||
return getId() != null && Objects.equals(getId(), feed.getId()); | ||
} | ||
|
||
@Override | ||
public final int hashCode() { | ||
return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode(); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
backend/src/main/java/com/egor/rssaggregator/entity/News.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.egor.rssaggregator.entity; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Objects; | ||
|
||
@Entity | ||
@Table(name = "news") | ||
@Getter | ||
@Setter | ||
@ToString | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class News { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "id", nullable = false) | ||
private Long id; | ||
|
||
@Column(name = "newsHead", length = 100, nullable = false) | ||
private String newsHead; | ||
|
||
@Column(name = "newsDate", nullable = false) | ||
private LocalDate newsDate; | ||
|
||
@Column(name = "newsText") | ||
@Lob | ||
private String newsText; | ||
|
||
@ToString.Exclude | ||
@ManyToOne(cascade = CascadeType.ALL) | ||
@JoinColumn(name = "feed_id") | ||
private Feed feed; | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
News news = (News) o; | ||
return Objects.equals(id, news.id) && | ||
Objects.equals(newsHead, news.newsHead) && | ||
Objects.equals(newsDate, news.newsDate) && | ||
Objects.equals(feed, news.feed); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, newsHead, newsDate, feed); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
backend/src/main/java/com/egor/rssaggregator/entity/User.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.egor.rssaggregator.entity; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.*; | ||
import org.springframework.security.core.GrantedAuthority; | ||
import org.springframework.security.core.authority.SimpleGrantedAuthority; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
|
||
import java.util.*; | ||
|
||
@Entity | ||
@Table(name = "users") | ||
@Getter | ||
@Setter | ||
@ToString | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class User implements UserDetails { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "id", nullable = false) | ||
private Long id; | ||
|
||
@Column(name = "email", unique = true, length = 50, nullable = false) | ||
private String email; | ||
|
||
@Column(name = "password", length = 120, nullable = false) | ||
@ToString.Exclude | ||
private String password; | ||
|
||
@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true) | ||
@ToString.Exclude | ||
private List<Feed> feeds = new ArrayList<>(); | ||
|
||
@Override | ||
public Collection<? extends GrantedAuthority> getAuthorities() { | ||
var userRole = new HashSet<SimpleGrantedAuthority>(); | ||
userRole.add(new SimpleGrantedAuthority("ROLE_USER")); // all users are users, not admins | ||
return userRole; | ||
} | ||
|
||
@Override | ||
public String getUsername() { | ||
return email; | ||
} | ||
|
||
@Override | ||
public boolean isAccountNonExpired() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isAccountNonLocked() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isCredentialsNonExpired() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isEnabled() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
User user = (User) o; | ||
return Objects.equals(id, user.id) && | ||
Objects.equals(email, user.email) && | ||
Objects.equals(password, user.password) && | ||
Objects.equals(feeds, user.feeds); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, email, password, feeds); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
backend/src/main/java/com/egor/rssaggregator/repo/FeedRepo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.egor.rssaggregator.repo; | ||
|
||
import com.egor.rssaggregator.entity.Feed; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface FeedRepo extends JpaRepository<Feed, Long> { | ||
Optional<Feed> findById(long id); | ||
} |
10 changes: 10 additions & 0 deletions
10
backend/src/main/java/com/egor/rssaggregator/repo/NewsRepo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.egor.rssaggregator.repo; | ||
|
||
import com.egor.rssaggregator.entity.News; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface NewsRepo extends JpaRepository<News, Long> { | ||
Optional<News> findById(long id); | ||
} |
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/com/egor/rssaggregator/repo/UserRepo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.egor.rssaggregator.repo; | ||
|
||
import com.egor.rssaggregator.entity.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface UserRepo extends JpaRepository<User, Long> { | ||
Optional<User> findByEmail(String email); | ||
|
||
Optional<User> findById(long id); | ||
} |
4 changes: 4 additions & 0 deletions
4
backend/src/main/java/com/egor/rssaggregator/service/FeedService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.egor.rssaggregator.service; | ||
|
||
public interface FeedService { | ||
} |
4 changes: 4 additions & 0 deletions
4
backend/src/main/java/com/egor/rssaggregator/service/UserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.egor.rssaggregator.service; | ||
|
||
public interface UserService { | ||
} |
6 changes: 6 additions & 0 deletions
6
backend/src/main/java/com/egor/rssaggregator/service/impl/FeedServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.egor.rssaggregator.service.impl; | ||
|
||
import com.egor.rssaggregator.service.FeedService; | ||
|
||
public class FeedServiceImpl implements FeedService { | ||
} |
6 changes: 6 additions & 0 deletions
6
backend/src/main/java/com/egor/rssaggregator/service/impl/UserServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.egor.rssaggregator.service.impl; | ||
|
||
import com.egor.rssaggregator.service.UserService; | ||
|
||
public class UserServiceImpl implements UserService { | ||
} |