Added UserProfile endpoint (also moved stuff around)

This commit is contained in:
2026-04-18 20:11:51 -04:00
parent 22991b6a30
commit 6b73952ee0
15 changed files with 107 additions and 13 deletions

View File

@@ -28,14 +28,14 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-webmvc' implementation 'org.springframework.boot:spring-boot-starter-webmvc'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:3.0.3'
implementation 'org.springframework.boot:spring-boot-starter-websocket' implementation 'org.springframework.boot:spring-boot-starter-websocket'
implementation 'org.springframework.boot:spring-boot-h2console'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:3.0.3'
//implementation 'org.springframework.boot:spring-boot-starter-security' //implementation 'org.springframework.boot:spring-boot-starter-security'
//implementation 'org.springframework.boot:spring-boot-starter-security-oauth2-resource-server' //implementation 'org.springframework.boot:spring-boot-starter-security-oauth2-resource-server'
compileOnly 'org.projectlombok:lombok' compileOnly 'org.projectlombok:lombok'
runtimeOnly 'org.postgresql:postgresql' runtimeOnly 'org.postgresql:postgresql'
runtimeOnly 'com.h2database:h2:2.4.240' runtimeOnly 'com.h2database:h2:2.4.240'
implementation 'org.springframework.boot:spring-boot-h2console'
annotationProcessor 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-data-jpa-test' testImplementation 'org.springframework.boot:spring-boot-starter-data-jpa-test'
testImplementation 'org.springframework.boot:spring-boot-starter-webmvc-test' testImplementation 'org.springframework.boot:spring-boot-starter-webmvc-test'

View File

@@ -0,0 +1,31 @@
package net.kpuig.concord.backend.controllers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import net.kpuig.concord.backend.datamodels.userprofile.GetAllUserProfilesResponse;
import net.kpuig.concord.backend.datamodels.userprofile.GetUserProfileResponse;
import net.kpuig.concord.backend.services.UserProfileService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;
@RestController
@RequestMapping("/user-profile")
public class UserProfileController {
@Autowired
private UserProfileService userProfileService;
@GetMapping("/")
public GetAllUserProfilesResponse getAllUserProfiles() {
return userProfileService.getAllUserProfiles();
}
@GetMapping("/{id}")
public GetUserProfileResponse getMethodName(@RequestParam String id) {
return userProfileService.getUserProfile(id);
}
}

View File

@@ -1,4 +1,4 @@
package net.kpuig.concord.backend.datamodels; package net.kpuig.concord.backend.datamodels.channel;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
@@ -6,7 +6,7 @@ import jakarta.persistence.GenerationType;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne; import jakarta.persistence.ManyToOne;
import lombok.Data; import lombok.Data;
import net.kpuig.concord.backend.datamodels.enums.ChannelType; import net.kpuig.concord.backend.datamodels.server.Server;
@Data @Data
@Entity(name = "channel") @Entity(name = "channel")

View File

@@ -1,4 +1,4 @@
package net.kpuig.concord.backend.datamodels.enums; package net.kpuig.concord.backend.datamodels.channel;
public enum ChannelType { public enum ChannelType {
TEXT_CHANNEL, TEXT_CHANNEL,

View File

@@ -1,4 +1,4 @@
package net.kpuig.concord.backend.datamodels; package net.kpuig.concord.backend.datamodels.message;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
@@ -6,6 +6,8 @@ import jakarta.persistence.GenerationType;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.ManyToOne; import jakarta.persistence.ManyToOne;
import lombok.Data; import lombok.Data;
import net.kpuig.concord.backend.datamodels.channel.Channel;
import net.kpuig.concord.backend.datamodels.userprofile.UserProfile;
@Data @Data
@Entity(name = "message") @Entity(name = "message")

View File

@@ -1,4 +1,4 @@
package net.kpuig.concord.backend.datamodels; package net.kpuig.concord.backend.datamodels.server;
import java.net.URL; import java.net.URL;

View File

@@ -0,0 +1,10 @@
package net.kpuig.concord.backend.datamodels.userprofile;
import java.util.List;
import lombok.Data;
@Data
public class GetAllUserProfilesResponse {
private List<GetUserProfileResponse> userProfiles;
}

View File

@@ -0,0 +1,9 @@
package net.kpuig.concord.backend.datamodels.userprofile;
import lombok.Data;
@Data
public class GetUserProfileResponse {
private Long id;
private String username;
}

View File

@@ -1,4 +1,4 @@
package net.kpuig.concord.backend.datamodels; package net.kpuig.concord.backend.datamodels.userprofile;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;

View File

@@ -3,7 +3,7 @@ package net.kpuig.concord.backend.repositories;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import net.kpuig.concord.backend.datamodels.Channel; import net.kpuig.concord.backend.datamodels.channel.Channel;
@Repository @Repository
public interface ChannelRepository extends JpaRepository<Channel, Long> { public interface ChannelRepository extends JpaRepository<Channel, Long> {

View File

@@ -3,7 +3,7 @@ package net.kpuig.concord.backend.repositories;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import net.kpuig.concord.backend.datamodels.Message; import net.kpuig.concord.backend.datamodels.message.Message;
@Repository @Repository
public interface MessageRepository extends JpaRepository<Message, Long> { public interface MessageRepository extends JpaRepository<Message, Long> {

View File

@@ -3,7 +3,7 @@ package net.kpuig.concord.backend.repositories;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import net.kpuig.concord.backend.datamodels.Server; import net.kpuig.concord.backend.datamodels.server.Server;
@Repository @Repository
public interface ServerRepository extends JpaRepository<Server, Long> { public interface ServerRepository extends JpaRepository<Server, Long> {

View File

@@ -1,9 +1,11 @@
package net.kpuig.concord.backend.repositories; package net.kpuig.concord.backend.repositories;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import net.kpuig.concord.backend.datamodels.UserProfile; import net.kpuig.concord.backend.datamodels.userprofile.UserProfile;
@Repository @Repository
public interface UserProfileRepository extends JpaRepository<UserProfile, Long> { public interface UserProfileRepository extends JpaRepository<UserProfile, Long> {

View File

@@ -0,0 +1,36 @@
package net.kpuig.concord.backend.services;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import net.kpuig.concord.backend.datamodels.userprofile.GetAllUserProfilesResponse;
import net.kpuig.concord.backend.datamodels.userprofile.GetUserProfileResponse;
import net.kpuig.concord.backend.repositories.UserProfileRepository;
@Service
public class UserProfileService {
@Autowired
private UserProfileRepository userProfileRepository;
public GetAllUserProfilesResponse getAllUserProfiles() {
GetAllUserProfilesResponse response = new GetAllUserProfilesResponse();
response.setUserProfiles(userProfileRepository.findAll().stream().map(userProfile -> {
GetUserProfileResponse userProfileResponse = new GetUserProfileResponse();
userProfileResponse.setId(userProfile.getId());
userProfileResponse.setUsername(userProfile.getUsername());
return userProfileResponse;
}).toList());
return response;
}
public GetUserProfileResponse getUserProfile(String id) {
GetUserProfileResponse response = new GetUserProfileResponse();
userProfileRepository.findById(Long.parseLong(id)).ifPresent(userProfile -> {
response.setId(userProfile.getId());
response.setUsername(userProfile.getUsername());
});
return response;
}
}

View File

@@ -8,4 +8,8 @@ spring.datasource.password=password
spring.jpa.hibernate.ddl-auto=update spring.jpa.hibernate.ddl-auto=update
logging.level.org.springframework=INFO logging.level.org.springframework=INFO
logging.level.com.example=DEBUG logging.level.com.example=DEBUG
server.port=8080 server.port=8080
springdoc.api-docs.enabled=true
springdoc.api-docs.path=/v3/api-docs
springdoc.swagger-ui.enabled=true
springdoc.swagger-ui.path=/swagger