Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/rest endpoints #18

Merged
merged 41 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
bebc8f1
#1: WIP
Sep 26, 2024
dd90240
#1: Added user entity and quote entity
Sep 28, 2024
1b6ad2c
#1: Updated linting
Sep 28, 2024
8c1d71d
#1: Updated linting
Sep 28, 2024
141f54a
#1: Updated linting
Sep 28, 2024
666bf21
#1: Updated linting
Sep 28, 2024
05ea5a6
#1: Updated linting
Sep 28, 2024
f60a7bf
#1: Fixed linting issues
Sep 28, 2024
fd6c7d2
#1: Fixed linting issues
Sep 28, 2024
7023347
#1: Fixed linting issues
Sep 28, 2024
414b900
#1: Fixed linting issues
Sep 28, 2024
f6f42b4
#1: Added test db to workflows
Sep 28, 2024
211e57d
#1: WIP
Sep 28, 2024
d610b82
#1: WIP
Sep 28, 2024
fec8b37
#1: Fixed warning
Sep 28, 2024
5da608d
transfer changes for #1 between my devices
dotnomi Oct 22, 2024
f8fef23
#1: Changed banner
dotnomi Oct 30, 2024
94acf08
#5: Added role rest end points
dotnomi Oct 30, 2024
d590d67
#4: Added user rest end points
dotnomi Oct 30, 2024
c81c9f0
#3: Added quote rest end points
dotnomi Oct 30, 2024
6e6338c
#1: Added reaction repository test
dotnomi Oct 30, 2024
c0276f1
#1: Changed readme
dotnomi Oct 30, 2024
ae66a6d
#1: Added response dtos
dotnomi Oct 30, 2024
d198d09
#3: Implemented quote service
dotnomi Oct 30, 2024
c8c071a
#3: Implemented quote service
dotnomi Oct 30, 2024
48008a7
#4: Implemented user service
dotnomi Oct 30, 2024
632b356
#5: Implemented role service
dotnomi Oct 30, 2024
7bd0ca8
#1: Added database migration
dotnomi Oct 30, 2024
b1d2c78
#1: Finished database migration and implemented email encryption
dotnomi Oct 31, 2024
a282d9f
Merge branch 'main' of https://github.com/quotly-eu/quotly-backend in…
dotnomi Nov 1, 2024
6aaa65d
#4: Implemented user endpoints
dotnomi Nov 1, 2024
86bc6e9
#4: Removed options
dotnomi Nov 1, 2024
4980e01
#4: Changed linting
dotnomi Nov 1, 2024
8c6094f
#4: Fixed linting problems
dotnomi Nov 1, 2024
29eb9a4
#4: Fixed linting problems
dotnomi Nov 1, 2024
8c7e9ee
#4: Fixed linting problems
dotnomi Nov 1, 2024
7dc48fb
#4: Fixed db issues
dotnomi Nov 1, 2024
ea623e3
#4: Fixed db issues
dotnomi Nov 1, 2024
c2e7fb3
#4: Fixed db issues
dotnomi Nov 1, 2024
9c017d4
#4: Fixed db issues
dotnomi Nov 1, 2024
0d0188a
#4: Fixed db issues
dotnomi Nov 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/linters/sun_checks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
<!-- See https://checkstyle.org/checks/coding/index.html -->
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="HiddenField"/>
<!--module name="HiddenField"/-->
<module name="IllegalInstantiation"/>
<module name="InnerAssignment"/>
<module name="MagicNumber"/>
Expand All @@ -175,8 +175,8 @@
<!-- Miscellaneous other checks. -->
<!-- See https://checkstyle.org/checks/misc/index.html -->
<module name="ArrayTypeStyle"/>
<module name="FinalParameters"/>
<module name="TodoComment"/>
<!--module name="FinalParameters"/-->
<!--module name="TodoComment"/-->
<module name="UpperEll"/>

<!-- https://checkstyle.org/filters/suppressionxpathfilter.html -->
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
DATABASE_PASSWORD: ${{ secrets.TEST_DATABASE_PASSWORD }}
run: |
chmod +x mvnw
./mvnw test
./mvnw test -Dquarkus.profile=test
EliteArtz marked this conversation as resolved.
Show resolved Hide resolved

build_and_push_docker_image:
runs-on: self-hosted
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Quarkus documentation: <https://quarkus.io/>

## Branch naming guidelines

> **Feature Branch:** ```feature/<ticket-id>``` Example: ```feature/#123```
> **Feature Branch:** ```feature/<short ticket description>``` Example: ```feature/rainbow-rest-endpoints```
>
> **Bugfix Branch:** ```bugfix/<ticket-id>``` Example: ```bugfix/#123```
> **Bugfix Branch:** ```bugfix/<short ticket description>``` Example: ```bugfix/rainbow-rest-endpoints```

## Commit guidelines

Expand Down
44 changes: 29 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>eu.quotly</groupId>
<artifactId>backend</artifactId>
Expand Down Expand Up @@ -31,6 +30,7 @@
</dependencyManagement>

<dependencies>
<!-- Rest Api -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
Expand All @@ -39,17 +39,41 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jsonb</artifactId>
</dependency>

<!-- Database -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-health</artifactId>
<artifactId>quarkus-hibernate-orm-panache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-panache</artifactId>
<artifactId>quarkus-jdbc-mariadb</artifactId>
</dependency>

<!-- Flyway (Database migration) -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-mariadb</artifactId>
<artifactId>quarkus-flyway</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-mysql</artifactId>
</dependency>

<!-- Swagger (API documentation) -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-swagger-ui</artifactId>
</dependency>

<!-- Miscellaneous -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-health</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand All @@ -70,16 +94,6 @@
<artifactId>lombok</artifactId>
<version>1.18.30</version>
</dependency>

<!-- Swagger -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-swagger-ui</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/eu/quotly/config/ErrorCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package eu.quotly.config;

public enum ErrorCode {
DATE_PARSING_ERROR(40100L),
USER_NOT_FOUND(40010L),
QUOTE_NOT_FOUND(40020L),
COMMENT_NOT_FOUND(40030L),
REACTION_NOT_FOUND(40040L),
INVALID_PAGE_INDEX_OR_SIZE(40101L);

private final Long code;

ErrorCode(Long code) {
this.code = code;
}

public Long getValue() {
return code;
}
}
20 changes: 20 additions & 0 deletions src/main/java/eu/quotly/config/QuotlyConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package eu.quotly.config;

import io.quarkus.runtime.annotations.StaticInitSafe;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

@StaticInitSafe
@ApplicationScoped
public class QuotlyConfig {
@Inject
QuotlyProperties quotlyProperties;

public String getVersion() {
return quotlyProperties.version();
}

public Boolean isEmailEncryptionEnabled() {
return quotlyProperties.emailEncryption();
}
}
11 changes: 11 additions & 0 deletions src/main/java/eu/quotly/config/QuotlyProperties.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package eu.quotly.config;

import io.quarkus.runtime.annotations.StaticInitSafe;
import io.smallrye.config.ConfigMapping;

@StaticInitSafe
@ConfigMapping(prefix = "quotly")
public interface QuotlyProperties {
String version();
Boolean emailEncryption();
}
12 changes: 12 additions & 0 deletions src/main/java/eu/quotly/config/ResponseStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package eu.quotly.config;

@SuppressWarnings("unused")
public enum ResponseStatus {
SUCCESS,
ERROR,
UNKNOWN;

public String getName() {
return this.name().toLowerCase();
}
}
33 changes: 33 additions & 0 deletions src/main/java/eu/quotly/dto/ErrorResponseDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package eu.quotly.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import eu.quotly.config.ErrorCode;
import eu.quotly.config.ResponseStatus;
import jakarta.json.bind.annotation.JsonbPropertyOrder;

@JsonbPropertyOrder({"status", "errorCode"})
@JsonInclude(JsonInclude.Include.NON_NULL)
public record ErrorResponseDto(String status, Long errorCode) {
public static class Builder {
private String status;
private Long errorCode;

public Builder withResponseStatus(ResponseStatus status) {
if (status != null) {
this.status = status.getName();
}
return this;
}

public Builder withErrorCode(ErrorCode errorCode) {
if (errorCode != null) {
this.errorCode = errorCode.getValue();
}
return this;
}

public ErrorResponseDto build() {
return new ErrorResponseDto(status, errorCode);
}
}
}
30 changes: 30 additions & 0 deletions src/main/java/eu/quotly/dto/ResponseDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package eu.quotly.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import eu.quotly.config.ResponseStatus;
import jakarta.json.bind.annotation.JsonbPropertyOrder;

@JsonbPropertyOrder({"status", "data"})
@JsonInclude(JsonInclude.Include.NON_NULL)
public record ResponseDto(String status, Object data) {
public static class Builder {
private String status;
private Object data;

public Builder withResponseStatus(ResponseStatus status) {
if (status != null) {
this.status = status.getName();
}
return this;
}

public Builder withData(Object data) {
this.data = data;
return this;
}

public ResponseDto build() {
return new ResponseDto(status, data);
}
}
}
16 changes: 16 additions & 0 deletions src/main/java/eu/quotly/dto/UserDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package eu.quotly.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import jakarta.json.bind.annotation.JsonbPropertyOrder;

import java.time.LocalDateTime;

@JsonbPropertyOrder({"discordId", "displayName", "emailAddress", "creationTime"})
@JsonInclude(JsonInclude.Include.NON_NULL)
public record UserDto(
String discordId,
String displayName,
String emailAddress,
LocalDateTime creationTime
) {
}
77 changes: 77 additions & 0 deletions src/main/java/eu/quotly/entity/CommentEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package eu.quotly.entity;

import eu.quotly.Constants;
import io.quarkus.hibernate.orm.panache.PanacheEntityBase;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.SequenceGenerator;
import jakarta.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;

@Entity
@Data
@NoArgsConstructor
@Table(name = "quote_comments", schema = "quotly")
@EqualsAndHashCode(callSuper = true)
public class CommentEntity extends PanacheEntityBase {
@Id
@Column(name = "comment_id", nullable = false, updatable = false)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "quote_comments_seq")
@SequenceGenerator(name = "quote_comments_seq", sequenceName = "quote_comments_sequence", allocationSize = 1)
private Long commentId;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false)
private UserEntity user;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "quote_id", nullable = false)
private QuoteEntity quote;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parent", referencedColumnName = "comment_id")
private CommentEntity parentComment;

@OneToMany(mappedBy = "parentComment", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
private List<CommentEntity> childComments;

@Column(name = "comment", length = Constants.DB_EXTRA_LARGE_STRING_LENGTH)
private String comment;

@Column(name = "created_at", updatable = false)
private LocalDateTime creationTime = LocalDateTime.now();

@Column(name = "updated_at")
private LocalDateTime modificationTime;

@Column(name = "deleted_at")
private LocalDateTime deletionTime;

@Override
public String toString() {
return "CommentEntity {"
+ "commentId=" + commentId
+ ", userId=" + user.getUserId()
+ ", quoteId=" + quote.getQuoteId()
+ ", parentCommentId=" + parentComment.getCommentId()
+ ", childCount=" + (childComments != null ? childComments.size() : 0)
+ ", comment=" + comment
+ ", creationTime=" + creationTime
+ ", modificationTime=" + modificationTime
+ ", deletionTime=" + deletionTime
+ "}";
}
}
Loading