I’m working on a personal project just to improve my full stack skills. What I’m trying to create is a backend API that when called would send out an email to a ‘admin’ user to prompt them to approve the register request. I’m quite frankly having a very hard time to find resources online. Here is my code where I’m wanting to create the call
@PostMapping(value = "/registerSendRequest", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> registerRequest(@RequestBody Map<String, String> info) {
Optional<UserInfo> possibleUser = userService.check(info.get("username"));
AlreadyExistsResponse response;
if (possibleUser.isPresent()) {
response = new AlreadyExistsResponse(true);
return new ResponseEntity<>(response, HttpStatus.OK);
} else {
response = new AlreadyExistsResponse(false);
return new ResponseEntity<>(response, HttpStatus.OK);
}
}
And here is what my build.gradle file looks like
plugins {
id 'java'
id 'org.springframework.boot' version '3.2.2'
id 'io.spring.dependency-management' version '1.1.4'
}
group = 'com.project'
version = '0.0.1-SNAPSHOT'
java {
sourceCompatibility = '17'
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'mysql:mysql-connector-java:8.0.33'
implementation 'org.projectlombok:lombok'
implementation('org.springframework.boot:spring-boot-starter-mail')
compileOnly 'org.springframework:spring-context-support'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'mysql:mysql-connector-java'
runtimeOnly 'org.apache.activemq:artemis-jakarta-server'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
Also my application.yml file
server:
port: 8080
spring:
mail:
properties:
"[mail.smtp.connectiontimeout]": 5000
"[mail.smtp.timeout]": 3000
"[mail.smtp.writetimeout]": 5000
application:
name: book-service
h2:
console:
enabled: true
settings:
web-allow-others: true
path: /h2-console
datasource:
url: ${DB_URL}
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
hibernate:
ddl-auto: update
show-sql: true
Any help would be greatly appreciated! Also if you have any general advice as well based on what you can currently see that would be much appreciated as well! Take care!
One thing I’m really struggling with is what actual springboot dependencies to use and work with. I don’t know if its lack of experience, but the springboot and gradle documentation seems really janky and difficult to read a lot of the time. Especially with debugging gradle runs. I’ve tried using a couple dependencies that I think are no longer valid and are causing my application to fail a ./gradlew build or gradle build. And most stack overflow or git posts I’ve found are years out of date and no longer apply
Jackson Kirkpatrick is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.