-
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
27 changed files
with
277 additions
and
81 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
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/ru/itmo/filmhub/config/DefaultConfigurationProperties.kt
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,11 @@ | ||
package ru.itmo.filmhub.config | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
import org.springframework.boot.context.properties.ConstructorBinding | ||
import java.util.UUID | ||
|
||
@ConstructorBinding | ||
@ConfigurationProperties("default") | ||
data class DefaultConfigurationProperties( | ||
val defaultSubscriptionId: UUID, | ||
) |
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
37 changes: 18 additions & 19 deletions
37
src/main/kotlin/ru/itmo/filmhub/controller/AuthenticationController.kt
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 |
---|---|---|
@@ -1,30 +1,29 @@ | ||
package ru.itmo.filmhub.controller | ||
|
||
import org.springframework.http.HttpStatus | ||
//import org.springframework.security.core.Authentication | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.security.core.Authentication | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.ResponseStatus | ||
import org.springframework.web.bind.annotation.RestController | ||
import ru.itmo.filmhub.model.request.UserRegisterRequest | ||
import ru.itmo.filmhub.model.entity.User | ||
import ru.itmo.filmhub.messages.UserRegisterRequest | ||
import ru.itmo.filmhub.service.UserService | ||
import ru.itmo.filmhub.service.TokenService | ||
|
||
@RestController | ||
@RequestMapping("/user") | ||
class AuthenticationController { | ||
class AuthenticationController( | ||
private val userService: UserService, | ||
private val tokenService: TokenService, | ||
) { | ||
@PostMapping("/register") | ||
fun register( | ||
@RequestBody userRegisterRequest: UserRegisterRequest, | ||
): ResponseEntity<User> = ResponseEntity.status(200).body(userService.addUser(userRegisterRequest)) | ||
|
||
// @PostMapping("/register") | ||
// @ResponseStatus(HttpStatus.NO_CONTENT) | ||
// suspend fun register( | ||
// @RequestBody userRegisterRequest: UserRegisterRequest, | ||
// ) { | ||
// throw NotImplementedError() | ||
// } | ||
// | ||
// @PostMapping("/auth") | ||
// suspend fun auth( | ||
// authentication: Authentication, | ||
// ): String { | ||
// throw NotImplementedError() | ||
// } | ||
@PostMapping("/auth") | ||
fun auth( | ||
authentication: Authentication, | ||
): ResponseEntity<String> = ResponseEntity.status(200).body(tokenService.generateToken(authentication)) | ||
} |
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 |
---|---|---|
@@ -1,13 +1,14 @@ | ||
package ru.itmo.filmhub.controller | ||
|
||
import org.springframework.http.ResponseEntity | ||
import org.springframework.security.core.Authentication | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
class PingController { | ||
@GetMapping("/ping") | ||
fun ping(): ResponseEntity<String> { | ||
fun ping(auth: Authentication): ResponseEntity<String> { | ||
return ResponseEntity.status(200).body("pong") | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/kotlin/ru/itmo/filmhub/controller/ReviewController.kt
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,29 @@ | ||
package ru.itmo.filmhub.controller | ||
|
||
import org.springframework.http.ResponseEntity | ||
import org.springframework.security.core.Authentication | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.bind.annotation.RestController | ||
import ru.itmo.filmhub.messages.AddReviewRequest | ||
import ru.itmo.filmhub.service.ReviewService | ||
import java.util.* | ||
|
||
@RestController("/reviews") | ||
class ReviewController( | ||
private val reviewService: ReviewService, | ||
) { | ||
@PostMapping("/{movie_id}") | ||
fun addReview( | ||
@RequestBody addReviewRequest: AddReviewRequest, | ||
@PathVariable(name = "movie_id", required = true) movieId: UUID, | ||
authentication: Authentication, | ||
) = ResponseEntity.status(200).body(reviewService.addReviewToMovie(addReviewRequest, authentication.name, movieId)) | ||
|
||
@GetMapping("/{movie_id}") | ||
fun findReviewsByMovieId( | ||
@PathVariable(name = "movie_id", required = true) movieId: UUID, | ||
) = ResponseEntity.status(200).body(reviewService.findReviewsByMovieId(movieId)) | ||
} |
23 changes: 13 additions & 10 deletions
23
src/main/kotlin/ru/itmo/filmhub/controller/SubscriptionController.kt
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 |
---|---|---|
@@ -1,29 +1,32 @@ | ||
package ru.itmo.filmhub.controller | ||
|
||
import org.springframework.http.ResponseEntity | ||
import org.springframework.security.core.Authentication | ||
import org.springframework.web.bind.annotation.* | ||
import ru.itmo.filmhub.model.entity.Subscription | ||
import ru.itmo.filmhub.model.entity.User | ||
import ru.itmo.filmhub.service.SubscriptionService | ||
import java.util.* | ||
|
||
@RestController | ||
@RequestMapping() | ||
@RequestMapping("/subscriptions") | ||
class SubscriptionController( | ||
private val service: SubscriptionService, | ||
) { | ||
|
||
@PostMapping("/users/{user_id}/subscriptions/{subscription_id}") | ||
@PostMapping("/{subscription_id}") | ||
fun saveSubscriptionForUser( | ||
@PathVariable(name = "user_id", required = true) userId: UUID, | ||
@PathVariable(name = "subscription_id", required = true) subscriptionId: UUID, | ||
): ResponseEntity<User> { | ||
return ResponseEntity.status(200).body(service.saveSubscriptionForUser(userId, subscriptionId)) | ||
} | ||
authentication: Authentication | ||
): ResponseEntity<User> = | ||
ResponseEntity.status(200).body(service.saveSubscriptionForUser(authentication.name, subscriptionId)) | ||
|
||
@GetMapping("/subscriptions") | ||
fun getAllSubscriptions(): ResponseEntity<List<Subscription>> { | ||
return ResponseEntity.status(200).body(service.getAllSubscriptions()) | ||
} | ||
@GetMapping("/user") | ||
fun getUserSubscription( | ||
authentication: Authentication | ||
) = ResponseEntity.status(200).body(service.getSubscriptionByUsername(authentication.name)) | ||
|
||
@GetMapping | ||
fun getAllSubscriptions(): ResponseEntity<List<Subscription>> = | ||
ResponseEntity.status(200).body(service.getAllSubscriptions()) | ||
} |
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,6 @@ | ||
package ru.itmo.filmhub.messages | ||
|
||
data class AddReviewRequest( | ||
val text: String, | ||
val rating: Int, | ||
) |
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/ru/itmo/filmhub/messages/UserRegisterRequest.kt
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,6 @@ | ||
package ru.itmo.filmhub.messages | ||
|
||
data class UserRegisterRequest( | ||
val login: String, | ||
val password: String, | ||
) |
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
22 changes: 22 additions & 0 deletions
22
src/main/kotlin/ru/itmo/filmhub/model/entity/UserAuthority.kt
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,22 @@ | ||
package ru.itmo.filmhub.model.entity | ||
|
||
import javax.persistence.Entity | ||
import javax.persistence.GeneratedValue | ||
import javax.persistence.GenerationType | ||
import javax.persistence.Id | ||
import javax.persistence.JoinColumn | ||
import javax.persistence.ManyToOne | ||
import javax.persistence.Table | ||
|
||
@Table(name = "authorities") | ||
@Entity | ||
data class UserAuthority( | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
val id: Int? = null, | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "username", referencedColumnName = "username") | ||
val user: User? = null, | ||
val authority: String? = null, | ||
) |
9 changes: 0 additions & 9 deletions
9
src/main/kotlin/ru/itmo/filmhub/model/request/UserRegisterRequest.kt
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/ru/itmo/filmhub/repository/ReviewRepository.kt
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 |
---|---|---|
@@ -1,10 +1,20 @@ | ||
package ru.itmo.filmhub.repository | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
import org.springframework.data.jpa.repository.Query | ||
import org.springframework.stereotype.Repository | ||
import ru.itmo.filmhub.model.entity.Review | ||
import java.util.UUID | ||
|
||
@Repository | ||
interface ReviewRepository : JpaRepository<Review, UUID> { | ||
|
||
@Query( | ||
""" | ||
SELECT * FROM reviews | ||
WHERE movie_id = :movieId | ||
""", | ||
nativeQuery = true | ||
) | ||
fun findAllByMovieId(movieId: UUID): List<Review> | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/ru/itmo/filmhub/repository/SubscriptionRepository.kt
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 |
---|---|---|
@@ -1,10 +1,21 @@ | ||
package ru.itmo.filmhub.repository | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
import org.springframework.data.jpa.repository.Query | ||
import org.springframework.stereotype.Repository | ||
import ru.itmo.filmhub.model.entity.Subscription | ||
import java.util.UUID | ||
|
||
@Repository | ||
interface SubscriptionRepository : JpaRepository<Subscription, UUID> { | ||
|
||
@Query( | ||
""" | ||
SELECT * FROM subscriptions | ||
RIGHT JOIN users u on subscriptions.id = u.subscription_id | ||
WHERE u.username = :username | ||
""", | ||
nativeQuery = true | ||
) | ||
fun findByUsername(username: String): Subscription | ||
} |
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,28 @@ | ||
package ru.itmo.filmhub.service | ||
|
||
import org.springframework.stereotype.Service | ||
import ru.itmo.filmhub.model.entity.Review | ||
import ru.itmo.filmhub.messages.AddReviewRequest | ||
import ru.itmo.filmhub.repository.ReviewRepository | ||
import java.util.UUID | ||
|
||
@Service | ||
class ReviewService( | ||
private val reviewRepository: ReviewRepository, | ||
private val movieService: MovieService, | ||
private val userService: UserService, | ||
) { | ||
fun findReviewsByMovieId(movieId: UUID): List<Review> = | ||
reviewRepository.findAllByMovieId(movieId) | ||
|
||
fun addReviewToMovie(addReviewRequest: AddReviewRequest, username: String, movieId: UUID): Review = | ||
reviewRepository.save( | ||
Review( | ||
text = addReviewRequest.text, | ||
movie = movieService.getMovieById(movieId), | ||
rating = addReviewRequest.rating, | ||
author = userService.findUserByUsername(username) | ||
) | ||
) | ||
|
||
} |
Oops, something went wrong.