Added UserProfile endpoint (also moved stuff around)
This commit is contained in:
@@ -28,14 +28,14 @@ dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-actuator'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||
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-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-oauth2-resource-server'
|
||||
compileOnly 'org.projectlombok:lombok'
|
||||
runtimeOnly 'org.postgresql:postgresql'
|
||||
runtimeOnly 'com.h2database:h2:2.4.240'
|
||||
implementation 'org.springframework.boot:spring-boot-h2console'
|
||||
annotationProcessor 'org.projectlombok:lombok'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-data-jpa-test'
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-webmvc-test'
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.kpuig.concord.backend.datamodels;
|
||||
package net.kpuig.concord.backend.datamodels.channel;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
@@ -6,7 +6,7 @@ import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import lombok.Data;
|
||||
import net.kpuig.concord.backend.datamodels.enums.ChannelType;
|
||||
import net.kpuig.concord.backend.datamodels.server.Server;
|
||||
|
||||
@Data
|
||||
@Entity(name = "channel")
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.kpuig.concord.backend.datamodels.enums;
|
||||
package net.kpuig.concord.backend.datamodels.channel;
|
||||
|
||||
public enum ChannelType {
|
||||
TEXT_CHANNEL,
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.kpuig.concord.backend.datamodels;
|
||||
package net.kpuig.concord.backend.datamodels.message;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
@@ -6,6 +6,8 @@ import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import lombok.Data;
|
||||
import net.kpuig.concord.backend.datamodels.channel.Channel;
|
||||
import net.kpuig.concord.backend.datamodels.userprofile.UserProfile;
|
||||
|
||||
@Data
|
||||
@Entity(name = "message")
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.kpuig.concord.backend.datamodels;
|
||||
package net.kpuig.concord.backend.datamodels.server;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package net.kpuig.concord.backend.datamodels.userprofile;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class GetUserProfileResponse {
|
||||
private Long id;
|
||||
private String username;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.kpuig.concord.backend.datamodels;
|
||||
package net.kpuig.concord.backend.datamodels.userprofile;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
@@ -3,7 +3,7 @@ package net.kpuig.concord.backend.repositories;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import net.kpuig.concord.backend.datamodels.Channel;
|
||||
import net.kpuig.concord.backend.datamodels.channel.Channel;
|
||||
|
||||
@Repository
|
||||
public interface ChannelRepository extends JpaRepository<Channel, Long> {
|
||||
|
||||
@@ -3,7 +3,7 @@ package net.kpuig.concord.backend.repositories;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import net.kpuig.concord.backend.datamodels.Message;
|
||||
import net.kpuig.concord.backend.datamodels.message.Message;
|
||||
|
||||
@Repository
|
||||
public interface MessageRepository extends JpaRepository<Message, Long> {
|
||||
|
||||
@@ -3,7 +3,7 @@ package net.kpuig.concord.backend.repositories;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import net.kpuig.concord.backend.datamodels.Server;
|
||||
import net.kpuig.concord.backend.datamodels.server.Server;
|
||||
|
||||
@Repository
|
||||
public interface ServerRepository extends JpaRepository<Server, Long> {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package net.kpuig.concord.backend.repositories;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import net.kpuig.concord.backend.datamodels.UserProfile;
|
||||
import net.kpuig.concord.backend.datamodels.userprofile.UserProfile;
|
||||
|
||||
@Repository
|
||||
public interface UserProfileRepository extends JpaRepository<UserProfile, Long> {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -8,4 +8,8 @@ spring.datasource.password=password
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
logging.level.org.springframework=INFO
|
||||
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
|
||||
Reference in New Issue
Block a user