first commit

This commit is contained in:
heyethereum
2024-06-17 16:47:30 +08:00
commit 29e0958635
13 changed files with 637 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
package com.safeqr.app;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SafeQrAppApplication {
public static void main(String[] args) {
SpringApplication.run(SafeQrAppApplication.class, args);
}
}

View File

@@ -0,0 +1,22 @@
package com.safeqr.app.user.controller;
import com.safeqr.app.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/v1")
public class UserController {
@Autowired
UserService userService;
@GetMapping(value = "/version", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> version() {
System.out.println(userService.getUserByEmail());
return ResponseEntity.ok("SafeQR v1.0.0");
}
}

View File

@@ -0,0 +1,26 @@
package com.safeqr.app.user.entity;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.*;
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Entity
@Table(name="user", schema = "safeqr")
public class UserEntity {
@Id
private String id;
private String cognitoId;
private String firstname;
private String lastname;
private String email;
private String source;
private String password;
private String salt;
}

View File

@@ -0,0 +1,10 @@
package com.safeqr.app.user.repository;
import com.safeqr.app.user.entity.UserEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface UserRepository extends JpaRepository<UserEntity, String> {
UserEntity findByEmail(String email);
}

View File

@@ -0,0 +1,23 @@
package com.safeqr.app.user.service;
import com.safeqr.app.user.entity.UserEntity;
import com.safeqr.app.user.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserService {
@Autowired
private UserRepository userRepository;
public String getUserByEmail() {
// Retrieve the user by email
UserEntity retrievedUser = userRepository.findByEmail("test.user@example.com");
if (retrievedUser != null) {
return "User found: " + retrievedUser.getFirstname() + " " + retrievedUser.getLastname();
}
return "User not found";
}
}