-
Notifications
You must be signed in to change notification settings - Fork 50
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 #128 from Lixuhuilll/Refactor-RatingUser
重构评分系统
- Loading branch information
Showing
15 changed files
with
537 additions
and
175 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
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
23 changes: 23 additions & 0 deletions
23
src/main/java/plus/maa/backend/repository/RatingRepository.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,23 @@ | ||
package plus.maa.backend.repository; | ||
|
||
import org.springframework.data.mongodb.repository.MongoRepository; | ||
import org.springframework.stereotype.Repository; | ||
import plus.maa.backend.repository.entity.Rating; | ||
import plus.maa.backend.service.model.RatingType; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* @author lixuhuilll | ||
* Date 2023-08-20 12:06 | ||
*/ | ||
|
||
@Repository | ||
public interface RatingRepository extends MongoRepository<Rating, String> { | ||
Optional<Rating> findByTypeAndKeyAndUserId(Rating.KeyType type, String key, String userId); | ||
|
||
long countByTypeAndKeyAndRating(Rating.KeyType type, String key, RatingType rating); | ||
|
||
long countByTypeAndKey(Rating.KeyType type, String key); | ||
} | ||
|
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
49 changes: 49 additions & 0 deletions
49
src/main/java/plus/maa/backend/repository/entity/Rating.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,49 @@ | ||
package plus.maa.backend.repository.entity; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.experimental.Accessors; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.mongodb.core.index.CompoundIndex; | ||
import org.springframework.data.mongodb.core.index.CompoundIndexes; | ||
import org.springframework.data.mongodb.core.mapping.Document; | ||
import plus.maa.backend.service.model.RatingType; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
/** | ||
* @author lixuhuilll | ||
* Date 2023-08-20 11:20 | ||
*/ | ||
|
||
@Data | ||
@Accessors(chain = true) | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Document(collection = "maa_rating") | ||
// 复合索引 | ||
@CompoundIndexes({ | ||
// 一个用户对一个对象只能有一种评级 | ||
@CompoundIndex(name = "idx_rating", def = "{'type': 1, 'key': 1, 'userId': 1}", unique = true) | ||
}) | ||
public class Rating { | ||
@Id | ||
private String id; | ||
|
||
// 下面三个字段组成复合索引,一个用户对一个对象只能有一种评级 | ||
@NotNull | ||
private KeyType type; // 评级的类型,如作业(copilot)、评论(comment) | ||
@NotNull | ||
private String key; // 被评级对象的唯一标识,如作业id、评论id | ||
@NotNull | ||
private String userId; // 评级的用户id | ||
|
||
private RatingType rating; // 评级,如 "Like"、"Dislike"、"None" | ||
private LocalDateTime rateTime; // 评级时间 | ||
|
||
public enum KeyType { | ||
COPILOT, COMMENT | ||
} | ||
} |
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
Oops, something went wrong.