Class accountController
java.lang.Object
vn.edu.uit.csbu.software_design.software_design_backend.account.accountController
@RestController
@CrossOrigin(origins="*")
@RequestMapping("/api/account")
public class accountController
extends Object
REST controller for managing user accounts.
Provides endpoints for account creation, login, retrieval, updates, and deletion.
Handles security validations and communicates with the
accountService.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<String> createAccount(accountRequest account) Registers a new account.org.springframework.http.ResponseEntity<accountResponseDTO> Deletes the authenticated user's account.org.springframework.http.ResponseEntity<accountModel> findAccount(String name) Retrieves account information by name.org.springframework.http.ResponseEntity<String> follow(String streamId, accountRequest account) Adds or removes a stream from the user's following list.org.springframework.http.ResponseEntity<accountResponseDTO> getFollowerCount(String token) This Java function retrieves the follower count for a user account using the provided authorization token.org.springframework.http.ResponseEntity<accountResponseDTO> getFollowing(String token) Retrieves the stream key for the authenticated user.org.springframework.http.ResponseEntity<accountResponseDTO> getStreamKey(String token) Retrieves the stream key for the authenticated user.org.springframework.http.ResponseEntity<accountResponseDTO> login(accountRequest account) Authenticates a user and generates a login token.org.springframework.http.ResponseEntity<accountResponseDTO> update(String token, String type, accountRequest account) Updates user account information based on the specified type parameter.
-
Constructor Details
-
accountController
public accountController()
-
-
Method Details
-
findAccount
@GetMapping("") public org.springframework.http.ResponseEntity<accountModel> findAccount(@RequestParam String name) Retrieves account information by name.- Parameters:
name- the name of the account to retrieve (must not contain SQL injection patterns)- Returns:
- Response Entity containing the account information or a 404 status if not found
-
createAccount
@PostMapping("/register") public org.springframework.http.ResponseEntity<String> createAccount(@RequestBody accountRequest account) throws NoSuchAlgorithmException Registers a new account.- Parameters:
account- the request body containing account details, including username and password (must not contain SQL injection patterns)- Returns:
- Response Entity with a success message or an error response if validation fails
- Throws:
NoSuchAlgorithmException- if a required hashing algorithm is unavailable
-
login
@PostMapping("/login") public org.springframework.http.ResponseEntity<accountResponseDTO> login(@RequestBody accountRequest account) throws NoSuchAlgorithmException Authenticates a user and generates a login token.- Parameters:
account- the request body containing account credentials (username and password)- Returns:
- Response Entity containing the login response or an error if authentication fails
- Throws:
NoSuchAlgorithmException- if a required hashing algorithm is unavailable
-
getFollowing
@GetMapping("/auth/following") public org.springframework.http.ResponseEntity<accountResponseDTO> getFollowing(@RequestHeader("Authorization") String token) throws NoSuchAlgorithmException Retrieves the stream key for the authenticated user.- Parameters:
token- the authorization token provided in the request header- Returns:
- Response Entity containing the list of following accounts or an error response if unauthorized
- Throws:
NoSuchAlgorithmException- if a required hashing algorithm is unavailable
-
getFollowerCount
@GetMapping("/auth/follower") public org.springframework.http.ResponseEntity<accountResponseDTO> getFollowerCount(@RequestHeader("Authorization") String token) throws NoSuchAlgorithmException This Java function retrieves the follower count for a user account using the provided authorization token.- Parameters:
token- The `token` parameter in the `getFollowerCount` method is a string that represents the authorization token passed in the request header. This token is used for authentication and authorization purposes to ensure that the user making the request is allowed to access the follower count information.- Returns:
- The method `getFollowerCount` in the controller class is returning a `ResponseEntity` object containing an `accountResponseDTO` object.
- Throws:
NoSuchAlgorithmException- the no such algorithm exception
-
getStreamKey
@GetMapping("/auth/streamkey") public org.springframework.http.ResponseEntity<accountResponseDTO> getStreamKey(@RequestHeader("Authorization") String token) throws NoSuchAlgorithmException Retrieves the stream key for the authenticated user.- Parameters:
token- the authorization token provided in the request header- Returns:
- Response Entity containing the stream key or an error response if unauthorized
- Throws:
NoSuchAlgorithmException- if a required hashing algorithm is unavailable
-
update
@PutMapping("/auth/update/{type}") public org.springframework.http.ResponseEntity<accountResponseDTO> update(@RequestHeader("Authorization") String token, @PathVariable String type, @RequestBody accountRequest account) throws NoSuchAlgorithmException Updates user account information based on the specified type parameter.- Parameters:
token- the authorization token provided in the request headertype- the type of update to perform (e.g., "streamkey", "title", "description", etc.)account- the request body containing the data for the update (must not contain SQL injection patterns)- Returns:
- Response Entity with the status of the update operation
- Throws:
NoSuchAlgorithmException- if a required hashing algorithm is unavailable
-
follow
@PutMapping("/auth/follow/streamId") public org.springframework.http.ResponseEntity<String> follow(@PathVariable String streamId, @RequestBody accountRequest account) throws NoSuchAlgorithmException Adds or removes a stream from the user's following list.- Parameters:
streamId- the ID of the stream to follow or unfollowaccount- the request body containing the user's credentials (username and password) (must not contain SQL injection patterns)- Returns:
- Response Entity with the status of the follow or unfollow operation
- Throws:
NoSuchAlgorithmException- if a required hashing algorithm is unavailable
-
delete
@DeleteMapping("/auth/delete") public org.springframework.http.ResponseEntity<accountResponseDTO> delete(@RequestHeader("Authorization") String token) throws NoSuchAlgorithmException Deletes the authenticated user's account.- Parameters:
token- the authorization token provided in the request header- Returns:
- Response Entity with the status of the account deletion operation
- Throws:
NoSuchAlgorithmException- if a required hashing algorithm is unavailable
-