-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
325 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
server/application-server/src/main/java/de/tum/in/www1/hephaestus/chat/ChatController.java
This file was deleted.
Oops, something went wrong.
42 changes: 0 additions & 42 deletions
42
server/application-server/src/main/java/de/tum/in/www1/hephaestus/chat/ChatRepository.java
This file was deleted.
Oops, something went wrong.
44 changes: 0 additions & 44 deletions
44
server/application-server/src/main/java/de/tum/in/www1/hephaestus/chat/ChatService.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...er/application-server/src/main/java/de/tum/in/www1/hephaestus/chat/SessionController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package de.tum.in.www1.hephaestus.chat; | ||
|
||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
|
||
import java.util.Optional; | ||
|
||
import de.tum.in.www1.hephaestus.gitprovider.user.User; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
@RestController | ||
@RequestMapping("/session") | ||
public class SessionController { | ||
|
||
private final SessionService sessionService; | ||
|
||
public SessionController(SessionService sessionService) { | ||
this.sessionService = sessionService; | ||
} | ||
|
||
@PostMapping | ||
public ResponseEntity<SessionDTO> createSession(@RequestBody User user) { | ||
SessionDTO session = sessionService.createSession(user); | ||
return ResponseEntity.ok(session); | ||
} | ||
|
||
@GetMapping("/session/{sessionId}") | ||
public ResponseEntity<SessionDTO> getSession(@PathVariable Long sessionId) { | ||
Optional<SessionDTO> session = sessionService.findSessionById(sessionId); | ||
return ResponseEntity.ok(session.get()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...er/application-server/src/main/java/de/tum/in/www1/hephaestus/chat/SessionRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package de.tum.in.www1.hephaestus.chat; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import java.util.Optional; | ||
import jakarta.persistence.EntityNotFoundException; | ||
import jakarta.validation.constraints.NotNull; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface SessionRepository extends JpaRepository<Session, Long> { | ||
|
||
@Query(""" | ||
SELECT s | ||
FROM Session s | ||
LEFT JOIN FETCH s.messages m | ||
WHERE s.id = :sessionId | ||
""") | ||
Optional<Session> findByIdWithMessages(@Param("sessionId") long sessionId); | ||
|
||
@Query(""" | ||
SELECT s | ||
FROM Session s | ||
LEFT JOIN FETCH s.messages m | ||
LEFT JOIN FETCH m.content c | ||
WHERE s.id = :sessionId | ||
""") | ||
Session findByIdWithMessagesAndContents(@Param("sessionId") long sessionId); | ||
|
||
private Session getValueElseThrow(Optional<Session> optional, long sessionId) { | ||
return optional.orElseThrow(() -> | ||
new EntityNotFoundException("Session entity with id " + sessionId + " was not found.") | ||
); | ||
} | ||
|
||
@NotNull | ||
default Session findByIdWithMessagesElseThrow(long sessionId) throws EntityNotFoundException { | ||
return getValueElseThrow(findByIdWithMessages(sessionId), sessionId); | ||
} | ||
} |
Oops, something went wrong.