-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from Informatik-Projekt-Kurs/IPK-107-Implement…
…-GraphQL Ipk 107 implement graph ql
- Loading branch information
Showing
8 changed files
with
129 additions
and
46 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
33 changes: 33 additions & 0 deletions
33
src/main/java/com/MeetMate/experiments/TestController.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,33 @@ | ||
package com.MeetMate.experiments; | ||
|
||
import com.MeetMate.user.User; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.graphql.data.method.annotation.Argument; | ||
import org.springframework.graphql.data.method.annotation.MutationMapping; | ||
import org.springframework.graphql.data.method.annotation.QueryMapping; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
|
||
@Controller | ||
@RequiredArgsConstructor | ||
public class TestController { | ||
|
||
private final TestService testService; | ||
|
||
@QueryMapping | ||
public User getUsers(@Argument Long id) { | ||
return testService.getUsers(id); | ||
} | ||
|
||
@MutationMapping | ||
public ResponseEntity<?> UpdateUser(@Argument String name, @Argument String email, @Argument String password) { | ||
testService.updateUser(name, email, password); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
@MutationMapping | ||
public ResponseEntity<?> CreateUser(@Argument String name, @Argument String email, @Argument String password) { | ||
testService.createUser(name, email, password); | ||
return ResponseEntity.status(201).build(); | ||
} | ||
} |
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,40 @@ | ||
package com.MeetMate.experiments; | ||
|
||
import com.MeetMate.user.User; | ||
import com.MeetMate.user.UserRepository; | ||
import jakarta.persistence.EntityNotFoundException; | ||
import jakarta.transaction.Transactional; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class TestService { | ||
|
||
private final UserRepository userRepository; | ||
|
||
public User getUsers(long id) { | ||
return userRepository.findUserById(id) | ||
.orElseThrow(() -> new IllegalStateException("User not found")); | ||
} | ||
|
||
@Transactional | ||
public void updateUser(String name, String email, String password) { | ||
User user = | ||
userRepository | ||
.findUserByEmail(email) | ||
.orElseThrow(() -> new EntityNotFoundException("User does not exist.")); | ||
|
||
if (password != null) user.setPassword(password); | ||
if (name != null) user.setName(name); | ||
} | ||
|
||
public void createUser(String name, String email, String password) { | ||
User user = new User(); | ||
user.setName(name); | ||
user.setEmail(email); | ||
user.setPassword(password); | ||
userRepository.save(user); | ||
} | ||
} |
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
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
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,17 @@ | ||
#graphqls for graphql scema | ||
|
||
type Query { | ||
getUsers(id: ID!): User | ||
} | ||
|
||
type Mutation { | ||
updateUser(name: String, email: String!, password: String): String | ||
createUser(name: String!, email: String!, password: String!): String | ||
} | ||
|
||
type User { | ||
id: ID | ||
name: String | ||
email: String | ||
password: String | ||
} |