First commit

This commit is contained in:
2024-02-08 17:21:44 +01:00
commit d7f12f8e80
28 changed files with 1132 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
package dev.rsems.feedreader;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@EnableJpaRepositories("dev.rsems.feedreader.repo")
@EntityScan("dev.rsems.feedreader.model")
@SpringBootApplication
public class FeedreaderWebApplication {
public static void main(String[] args) {
SpringApplication.run(FeedreaderWebApplication.class, args);
}
}

View File

@@ -0,0 +1,23 @@
package dev.rsems.feedreader;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.web.SecurityFilterChain;
@Configuration
@EnableWebSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests(expressionInterceptUrlRegistry ->
expressionInterceptUrlRegistry
.anyRequest()
.permitAll())
.csrf(AbstractHttpConfigurer::disable);
return http.build();
}
}

View File

@@ -0,0 +1,13 @@
package dev.rsems.feedreader;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
public class ServletInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(FeedreaderWebApplication.class);
}
}

View File

@@ -0,0 +1,18 @@
package dev.rsems.feedreader;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class SimpleController {
@Value("${spring.application.name}")
String appName;
@GetMapping("/")
public String homePage(Model model) {
model.addAttribute("appName", appName);
return "home";
}
}

View File

@@ -0,0 +1,24 @@
package dev.rsems.feedreader.exception;
public class FeedIdMismatchException extends RuntimeException {
public FeedIdMismatchException() {
}
public FeedIdMismatchException(String message) {
super(message);
}
public FeedIdMismatchException(String message, Throwable cause) {
super(message, cause);
}
public FeedIdMismatchException(Throwable cause) {
super(cause);
}
public FeedIdMismatchException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}

View File

@@ -0,0 +1,24 @@
package dev.rsems.feedreader.exception;
public class FeedNotFoundException extends RuntimeException {
public FeedNotFoundException() {
}
public FeedNotFoundException(String message) {
super(message);
}
public FeedNotFoundException(String message, Throwable cause) {
super(message, cause);
}
public FeedNotFoundException(Throwable cause) {
super(cause);
}
public FeedNotFoundException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}

View File

@@ -0,0 +1,43 @@
package dev.rsems.feedreader.model;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.proxy.HibernateProxy;
import java.util.Objects;
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity(name = "feed")
public class Feed {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", nullable = false)
private Long id;
@Column(nullable = false)
private String name;
@Column(nullable = false)
private String url;
@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();
}
}

View File

@@ -0,0 +1,49 @@
package dev.rsems.feedreader.model;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.proxy.HibernateProxy;
import java.util.Objects;
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity(name = "user")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", nullable = false)
private Long id;
@Column
private String username;
@Column
private String password;
@Column
private String realname;
@Column
private Integer roleid;
@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;
User user = (User) o;
return getId() != null && Objects.equals(getId(), user.getId());
}
@Override
public final int hashCode() {
return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode();
}
}

View File

@@ -0,0 +1,51 @@
package dev.rsems.feedreader.model;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.proxy.HibernateProxy;
import java.util.Objects;
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity(name = "userfeed")
public class UserFeed {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", nullable = false)
private Long id;
@ManyToOne
@JoinColumn(name = "user_id")
private User user;
@ManyToOne
@JoinColumn(name = "feed_id")
private Feed feed;
@Column
private Boolean visible;
@Column
private String filter;
@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;
UserFeed userFeed = (UserFeed) o;
return getId() != null && Objects.equals(getId(), userFeed.getId());
}
@Override
public final int hashCode() {
return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode();
}
}

View File

@@ -0,0 +1,11 @@
package dev.rsems.feedreader.repo;
import dev.rsems.feedreader.model.Feed;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
public interface FeedRepository extends CrudRepository<Feed, Long> {
List<Feed> findByName(String name);
}

View File

@@ -0,0 +1,8 @@
package dev.rsems.feedreader.repo;
import dev.rsems.feedreader.model.UserFeed;
import org.springframework.data.repository.CrudRepository;
public interface UserFeedRepository extends CrudRepository<UserFeed, Long> {
}

View File

@@ -0,0 +1,11 @@
package dev.rsems.feedreader.repo;
import dev.rsems.feedreader.model.User;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
public interface UserRepository extends CrudRepository<User, Long> {
List<User> findByUsername(String username);
}