Skip to content

Commit f641692

Browse files
authored
Merge branch 'main' into replace-ignore-where-with-true
2 parents cf4418b + 897de98 commit f641692

File tree

66 files changed

+674
-450
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+674
-450
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,4 @@ build
4242
node_modules/
4343

4444
.graphqlconfig
45+
.application.log*

backend/src/main/java/club/devcord/devmarkt/auth/OwnApplicationDirective.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818

1919
import club.devcord.devmarkt.auth.error.UnauthorizedError;
2020
import club.devcord.devmarkt.entities.auth.User;
21-
import club.devcord.devmarkt.responses.Applications;
21+
import club.devcord.devmarkt.responses.Failure;
22+
import club.devcord.devmarkt.responses.failure.application.ErrorCode;
2223
import club.devcord.devmarkt.services.ApplicationService;
2324
import graphql.execution.DataFetcherResult;
2425
import graphql.schema.DataFetcher;
@@ -71,7 +72,7 @@ public GraphQLFieldDefinition onField(
7172
return fieldBooleanReturn
7273
? false
7374
: DataFetcherResult.newResult()
74-
.data(Applications.notFound(value))
75+
.data(new Failure<>(ErrorCode.NOT_FOUND))
7576
.build();
7677
};
7778

backend/src/main/java/club/devcord/devmarkt/graphql/GraphQLFactory.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,14 @@ private Class<?> resolverClass(GraphQLResolver<?> resolver) {
105105
private void registerTypes(SchemaParserBuilder builder, BeanContext context) {
106106
context.getBeanDefinitions(Qualifiers.byStereotype(GraphQLType.class))
107107
.forEach(beanDefinition -> {
108-
var type = beanDefinition.stringValue(GraphQLType.class).orElseThrow();
108+
var type = beanDefinition.stringValue(GraphQLType.class);
109109
var beanType = beanDefinition.getBeanType();
110-
builder.dictionary(type, beanType);
111-
LOGGER.info("GraphQL Type {} mapped to class {}.", type, beanType);
110+
111+
var typeName = type.isEmpty()
112+
? beanType.getSimpleName()
113+
: type.get();
114+
builder.dictionary(typeName, beanType);
115+
LOGGER.info("GraphQL Type {} mapped to class {}.", typeName, beanType);
112116
});
113117
}
114118

backend/src/main/java/club/devcord/devmarkt/graphql/GraphQLType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@
2424
@Retention(RetentionPolicy.RUNTIME)
2525
public @interface GraphQLType {
2626

27-
String value();
27+
String value() default "";
2828
}

backend/src/main/java/club/devcord/devmarkt/logging/LoggingUtil.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,21 @@
1919
import club.devcord.devmarkt.responses.Failure;
2020
import club.devcord.devmarkt.responses.Response;
2121
import club.devcord.devmarkt.responses.Success;
22+
import club.devcord.devmarkt.responses.failure.Error;
23+
import java.util.Arrays;
2224

2325
public class LoggingUtil {
2426

2527
private LoggingUtil() {
2628

2729
}
2830

29-
public static String responseStatus(Response response) {
30-
if (response instanceof Failure fail) {
31-
return fail.errorCode();
31+
public static <T> String responseStatus(Response<T> response) {
32+
if (response instanceof Failure<T> fail) {
33+
return Arrays.toString(fail.errors()
34+
.stream()
35+
.map(Error::code)
36+
.toArray());
3237
} else if (response instanceof Success) {
3338
return "success";
3439
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2022 Contributors to the Devmarkt-Backend project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package club.devcord.devmarkt.qa;
18+
19+
import io.micronaut.context.annotation.Requires;
20+
import io.micronaut.http.annotation.Controller;
21+
import io.micronaut.http.annotation.Post;
22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
24+
25+
@Controller("qa")
26+
@Requires(env = "qa")
27+
public class DatabaseSeedingController {
28+
29+
private static final Logger LOGGER = LoggerFactory.getLogger(DatabaseSeedingController.class);
30+
private final QaDatabaseSeeding qaDatabaseSeeding;
31+
32+
public DatabaseSeedingController(QaDatabaseSeeding qaDatabaseSeeding) {
33+
this.qaDatabaseSeeding = qaDatabaseSeeding;
34+
}
35+
36+
@Post("seedDatabase")
37+
public void seedDatabase() {
38+
LOGGER.info("requested database seeding");
39+
qaDatabaseSeeding.reseedDatabase();
40+
}
41+
42+
}

backend/src/main/java/club/devcord/devmarkt/QaDatabaseSeeding.java renamed to backend/src/main/java/club/devcord/devmarkt/qa/QaDatabaseSeeding.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package club.devcord.devmarkt;
17+
package club.devcord.devmarkt.qa;
1818

1919
import club.devcord.devmarkt.auth.Role;
2020
import club.devcord.devmarkt.entities.application.Answer;
@@ -30,8 +30,11 @@
3030
import io.micronaut.context.annotation.Requires;
3131
import io.micronaut.context.event.ApplicationEventListener;
3232
import io.micronaut.runtime.event.ApplicationStartupEvent;
33+
import io.micronaut.transaction.exceptions.TransactionSystemException;
34+
import io.micronaut.transaction.jdbc.DataSourceTransactionManager;
3335
import jakarta.inject.Singleton;
3436
import java.util.List;
37+
import org.flywaydb.core.Flyway;
3538
import org.slf4j.Logger;
3639
import org.slf4j.LoggerFactory;
3740

@@ -45,6 +48,10 @@ public class QaDatabaseSeeding implements ApplicationEventListener<ApplicationSt
4548
private final UserRepo userRepo;
4649
private final ApplicationRepo applicationRepo;
4750

51+
private final DataSourceTransactionManager dataSourceTransactionManager;
52+
53+
private final Flyway flyway;
54+
4855
private Template devSearched;
4956
private Template devOffered;
5057
private Template emptyTemplate;
@@ -54,14 +61,35 @@ public class QaDatabaseSeeding implements ApplicationEventListener<ApplicationSt
5461
private User secondUserUser;
5562

5663
public QaDatabaseSeeding(TemplateRepo templateRepo,
57-
UserRepo userRepo, ApplicationRepo applicationRepo) {
64+
UserRepo userRepo, ApplicationRepo applicationRepo,
65+
DataSourceTransactionManager dataSourceTransactionManager, Flyway flyway) {
5866
this.templateRepo = templateRepo;
5967
this.userRepo = userRepo;
6068
this.applicationRepo = applicationRepo;
69+
this.dataSourceTransactionManager = dataSourceTransactionManager;
70+
this.flyway = flyway;
6171
}
6272

6373
@Override
6474
public void onApplicationEvent(ApplicationStartupEvent event) {
75+
seed();
76+
}
77+
78+
public void reseedDatabase() {
79+
LOGGER.info("Reseeding database");
80+
try {
81+
flyway.clean();
82+
flyway.migrate();
83+
seed();
84+
} catch (TransactionSystemException e) {
85+
LOGGER.info("TransactionSystemException occurred, might be have something to do with prepared statement caching."
86+
+ "Retrying...");
87+
// As this is only used for qa tests, this should be fine to avoid errors with caching (retrying solves them usually here)
88+
reseedDatabase();
89+
}
90+
}
91+
92+
private void seed() {
6593
LOGGER.info("Starting database seeding");
6694
seedTemplates();
6795
seedUsers();

backend/src/main/java/club/devcord/devmarkt/responses/Applications.java

Lines changed: 0 additions & 78 deletions
This file was deleted.

backend/src/main/java/club/devcord/devmarkt/responses/Failure.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,26 @@
1717
package club.devcord.devmarkt.responses;
1818

1919
import club.devcord.devmarkt.graphql.GraphQLType;
20+
import club.devcord.devmarkt.responses.failure.Error;
21+
import club.devcord.devmarkt.responses.failure.ErrorCode;
22+
import club.devcord.devmarkt.responses.failure.ErrorData;
23+
import java.util.Collection;
24+
import java.util.Collections;
2025

21-
@GraphQLType("Failure")
26+
@GraphQLType
2227
public record Failure<T>(
23-
String errorCode,
24-
String message
28+
Collection<Error<T>> errors
2529
) implements Response<T> {
2630

31+
public Failure(ErrorCode<T> code) {
32+
this(code, (ErrorData<T>) null);
33+
}
34+
public Failure(ErrorCode<T> code, ErrorData<T> data) {
35+
this(Collections.singletonList(new Error<>(code, data)));
36+
}
37+
38+
public Failure(ErrorCode<T> code, Collection<ErrorData<T>> data) {
39+
this(data.stream().map(eD -> new Error<>(code, eD)).toList());
40+
}
41+
2742
}

backend/src/main/java/club/devcord/devmarkt/responses/Users.java

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)