From 6eb5796fc195d8a64be620f8e168d8a7cce6800d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Mon, 11 Nov 2024 16:40:30 +0900 Subject: [PATCH 01/51] add :: Rank.java --- .../domaserver/domain/rank/entity/Rank.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/main/java/com/example/domaserver/domain/rank/entity/Rank.java diff --git a/src/main/java/com/example/domaserver/domain/rank/entity/Rank.java b/src/main/java/com/example/domaserver/domain/rank/entity/Rank.java new file mode 100644 index 0000000..e1d40e7 --- /dev/null +++ b/src/main/java/com/example/domaserver/domain/rank/entity/Rank.java @@ -0,0 +1,31 @@ +package com.example.domaserver.domain.rank.entity; + +import com.example.domaserver.domain.user.entity.User; +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Getter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class Rank { + + @Id + @GeneratedValue(strategy =GenerationType.IDENTITY) + private Long RankId; + private int PenaltyPoints; + private double RankScore; + + @ManyToOne + @JoinColumn(name = "user_id") + private User user; + + public Rank(Long rankId, Double rankScore) { + RankId = rankId; + RankScore = rankScore; + } +} From 1e8da19f803f2d76971d670acb6704c4872b79c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Mon, 11 Nov 2024 16:41:20 +0900 Subject: [PATCH 02/51] add :: RankController.java --- .../rank/presentation/RankController.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/main/java/com/example/domaserver/domain/rank/presentation/RankController.java diff --git a/src/main/java/com/example/domaserver/domain/rank/presentation/RankController.java b/src/main/java/com/example/domaserver/domain/rank/presentation/RankController.java new file mode 100644 index 0000000..8d858a9 --- /dev/null +++ b/src/main/java/com/example/domaserver/domain/rank/presentation/RankController.java @@ -0,0 +1,46 @@ +package com.example.domaserver.domain.rank.presentation; + + +import com.example.domaserver.domain.rank.entity.Rank; +import com.example.domaserver.domain.rank.service.RankService; +import com.example.domaserver.domain.user.entity.User; +import com.example.domaserver.domain.user.service.UserService; +import com.example.domaserver.global.security.jwt.JwtService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequestMapping("/home") +public class RankController { + private final RankService rankService; + private final UserService userService; + private final JwtService jwtService; + + @Autowired + public RankController(RankService rankService, UserService userService, JwtService jwtService) { + this.rankService = rankService; + this.userService = userService; + this.jwtService = jwtService; + } + + @GetMapping("/rank") + public ResponseEntity> getRanks() { + List topRanks = rankService.getTopRanking(25); + return ResponseEntity.ok(topRanks); + } + + @GetMapping("/my-rank") + public ResponseEntity getMyRank(@RequestHeader("Authorization") String token) { + User user = jwtService.getUserFromToken(token.substring(7)); + Long rank = rankService.getRanking(user); + return ResponseEntity.ok(rank); + } + + +} From 7dce3ef63a6820b00e7d46745e062c39c149c726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Mon, 11 Nov 2024 16:42:02 +0900 Subject: [PATCH 03/51] add :: RankResponse.java --- .../presentation/dto/response/RankResponse.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/com/example/domaserver/domain/rank/presentation/dto/response/RankResponse.java diff --git a/src/main/java/com/example/domaserver/domain/rank/presentation/dto/response/RankResponse.java b/src/main/java/com/example/domaserver/domain/rank/presentation/dto/response/RankResponse.java new file mode 100644 index 0000000..6296953 --- /dev/null +++ b/src/main/java/com/example/domaserver/domain/rank/presentation/dto/response/RankResponse.java @@ -0,0 +1,16 @@ +package com.example.domaserver.domain.rank.presentation.dto.response; + +import lombok.Builder; +import lombok.Getter; + +import java.util.UUID; + +@Builder +@Getter +public class RankResponse { + private UUID Id; + private String name; + private String profileImageUrl; + private int penaltyPoints; + private double RankScore; +} From 0ef14a46613b6ce0b982fbdda7fc1c1720d1562d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Mon, 11 Nov 2024 16:42:25 +0900 Subject: [PATCH 04/51] add :: RankServiceImpl.java --- .../rank/service/impl/RankServiceImpl.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/main/java/com/example/domaserver/domain/rank/service/impl/RankServiceImpl.java diff --git a/src/main/java/com/example/domaserver/domain/rank/service/impl/RankServiceImpl.java b/src/main/java/com/example/domaserver/domain/rank/service/impl/RankServiceImpl.java new file mode 100644 index 0000000..d0e38f1 --- /dev/null +++ b/src/main/java/com/example/domaserver/domain/rank/service/impl/RankServiceImpl.java @@ -0,0 +1,52 @@ +package com.example.domaserver.domain.rank.service.impl; + +import com.example.domaserver.domain.rank.entity.Rank; +import com.example.domaserver.domain.rank.service.RankService; +import com.example.domaserver.domain.user.entity.User; +import com.example.domaserver.global.annotation.ServiceWithTransaction; +import jakarta.transaction.Transactional; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.ZSetOperations; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + + +@ServiceWithTransaction +public class RankServiceImpl implements RankService { + + private static final String RANK_KEY = "USER_RANKING"; + + private final RedisTemplate redisTemplate; + + public RankServiceImpl(@Qualifier("redisTemplate") RedisTemplate redisTemplate) { + this.redisTemplate = redisTemplate; + } + + @Transactional + public Long getRanking(User user) { + Long rank = redisTemplate.opsForZSet().rank(RANK_KEY, user.getId()); + return (rank != null) ? rank + 1 : null; + } + + @Transactional + public void updateRank(Rank rank) { + redisTemplate.opsForZSet().add(RANK_KEY, rank.getUser().getId(), rank.getPenaltyPoints()); + } + + @Transactional + public List getTopRanking(int topN) { + Set> rankedUsers = + redisTemplate.opsForZSet().reverseRangeWithScores(RANK_KEY, 0, topN - 1); + + List userRanks = new ArrayList<>(); + for (ZSetOperations.TypedTuple entry : rankedUsers) { + Long RankId = entry.getValue(); + Double RankScore = entry.getScore(); + userRanks.add(new Rank(RankId, RankScore)); + } + return userRanks; + } + +} From 91ac7c2eb7e704d62ffc6f88650ead61126ffebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Mon, 11 Nov 2024 16:42:43 +0900 Subject: [PATCH 05/51] add :: RankService.java --- .../domaserver/domain/rank/service/RankService.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/main/java/com/example/domaserver/domain/rank/service/RankService.java diff --git a/src/main/java/com/example/domaserver/domain/rank/service/RankService.java b/src/main/java/com/example/domaserver/domain/rank/service/RankService.java new file mode 100644 index 0000000..6e3f501 --- /dev/null +++ b/src/main/java/com/example/domaserver/domain/rank/service/RankService.java @@ -0,0 +1,11 @@ +package com.example.domaserver.domain.rank.service; + +import com.example.domaserver.domain.rank.entity.Rank; +import com.example.domaserver.domain.user.entity.User; +import java.util.List; + +public interface RankService { + Long getRanking(User user); + void updateRank(Rank rank); + List getTopRanking(int topN); +} From 210b0d07efb7c436b144b7b72b3e4d28e8ffd38b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Mon, 11 Nov 2024 16:43:56 +0900 Subject: [PATCH 06/51] add :: RedisConfig.java --- .../domain/rank/config/RedisConfig.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main/java/com/example/domaserver/domain/rank/config/RedisConfig.java diff --git a/src/main/java/com/example/domaserver/domain/rank/config/RedisConfig.java b/src/main/java/com/example/domaserver/domain/rank/config/RedisConfig.java new file mode 100644 index 0000000..7dd6e41 --- /dev/null +++ b/src/main/java/com/example/domaserver/domain/rank/config/RedisConfig.java @@ -0,0 +1,23 @@ +package com.example.domaserver.domain.rank.config; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; +import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; + +@EnableRedisRepositories +@Configuration +public class RedisConfig { + @Value("${spring.redis.host}") + private String redisHost; + + @Value("${spring.redis.port}") + private int redisPort; + + @Bean + public RedisConnectionFactory redisConnectionFactory() { + return new LettuceConnectionFactory(redisHost, redisPort); + } +} From 7855b496880ffe811a1b4af4e08850822ba89392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Mon, 11 Nov 2024 16:44:19 +0900 Subject: [PATCH 07/51] add :: JwtService.java --- .../global/security/jwt/JwtService.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/main/java/com/example/domaserver/global/security/jwt/JwtService.java diff --git a/src/main/java/com/example/domaserver/global/security/jwt/JwtService.java b/src/main/java/com/example/domaserver/global/security/jwt/JwtService.java new file mode 100644 index 0000000..d05e71c --- /dev/null +++ b/src/main/java/com/example/domaserver/global/security/jwt/JwtService.java @@ -0,0 +1,62 @@ +package com.example.domaserver.global.security.jwt; + + +import com.example.domaserver.domain.user.entity.User; +import com.example.domaserver.domain.user.service.UserService; +import io.jsonwebtoken.Claims; +import io.jsonwebtoken.Jwts; +import lombok.extern.slf4j.Slf4j; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.stereotype.Service; +import org.springframework.beans.factory.annotation.Value; + +import java.util.Date; +import java.util.function.Function; + +@Service +@Slf4j +public class JwtService { + + private final UserService userService; + + @Value("${jwt.secret}") + private String secretKey; + + public JwtService(UserService userService) { + this.userService = userService; + } + + public String extractUsername(String token) { + return extractClaim(token, Claims::getSubject); + } + + public T extractClaim(String token, Function claimsResolver) { + final Claims claims = extractAllClaims(token); + return claimsResolver.apply(claims); + } + + private Claims extractAllClaims(String token) { + return Jwts.parser() + .setSigningKey(secretKey) + .parseClaimsJws(token) + .getBody(); + } + + public boolean isTokenValid(String token, UserDetails userDetails) { + final String username = extractUsername(token); + return (username.equals(userDetails.getUsername()) && !isTokenExpired(token)); + } + + private boolean isTokenExpired(String token) { + return extractExpiration(token).before(new Date()); + } + + public Date extractExpiration(String token) { + return extractClaim(token, Claims::getExpiration); + } + + public User getUserFromToken(String token) { + String username = extractUsername(token); + return userService.findByUsername(username); + } +} From bc65f7af2900182c3519bd5103de7426e2e2fef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Mon, 11 Nov 2024 16:47:28 +0900 Subject: [PATCH 08/51] add :: UserServiceImpl.java --- .../user/service/impl/UserServiceImpl.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/java/com/example/domaserver/domain/user/service/impl/UserServiceImpl.java diff --git a/src/main/java/com/example/domaserver/domain/user/service/impl/UserServiceImpl.java b/src/main/java/com/example/domaserver/domain/user/service/impl/UserServiceImpl.java new file mode 100644 index 0000000..dd76b5e --- /dev/null +++ b/src/main/java/com/example/domaserver/domain/user/service/impl/UserServiceImpl.java @@ -0,0 +1,34 @@ +package com.example.domaserver.domain.user.service.impl; + +import com.example.domaserver.domain.user.entity.User; +import com.example.domaserver.domain.user.repository.UserRepository; +import com.example.domaserver.domain.user.service.UserService; +import com.example.domaserver.global.annotation.ServiceWithTransaction; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.userdetails.UsernameNotFoundException; + +import java.util.UUID; + +@ServiceWithTransaction +public class UserServiceImpl implements UserService { + + private final UserRepository userRepository; + + @Autowired + public UserServiceImpl(UserRepository userRepository) { + this.userRepository = userRepository; + } + + @Override + public User findByUsername(String username) { + return userRepository.findByUsername(username) + .orElseThrow(() -> new UsernameNotFoundException("User not found with username: " + username)); + } + + @Override + public User findById(UUID id) { + return userRepository.findById(id) + .orElseThrow(() -> new UsernameNotFoundException("User not found with id: " + id)); + } + +} From a2f9ec8a4f8c359d1eac8217433a8c573e2682b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Mon, 11 Nov 2024 20:21:15 +0900 Subject: [PATCH 09/51] add :: UserService.java --- .../domaserver/domain/user/service/UserService.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/main/java/com/example/domaserver/domain/user/service/UserService.java diff --git a/src/main/java/com/example/domaserver/domain/user/service/UserService.java b/src/main/java/com/example/domaserver/domain/user/service/UserService.java new file mode 100644 index 0000000..ceaabac --- /dev/null +++ b/src/main/java/com/example/domaserver/domain/user/service/UserService.java @@ -0,0 +1,10 @@ +package com.example.domaserver.domain.user.service; + +import com.example.domaserver.domain.user.entity.User; + +import java.util.UUID; + +public interface UserService { + User findByUsername(String name); + User findById(UUID id); +} From f2740262468c47969415adba1089f92e765009ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Mon, 11 Nov 2024 20:21:40 +0900 Subject: [PATCH 10/51] modify :: User.java --- .../java/com/example/domaserver/domain/user/entity/User.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/example/domaserver/domain/user/entity/User.java b/src/main/java/com/example/domaserver/domain/user/entity/User.java index 2ebb17e..08a7082 100644 --- a/src/main/java/com/example/domaserver/domain/user/entity/User.java +++ b/src/main/java/com/example/domaserver/domain/user/entity/User.java @@ -17,10 +17,9 @@ public class User { @Id @GeneratedValue(generator = "UUID4") private UUID id; - private String name; - private String email; + private int penaltyPoint; @Embedded private StudentNum studentNum; From 4cce7749e9b6c8fd6bffaa2eca158469bb61be26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Mon, 11 Nov 2024 20:21:53 +0900 Subject: [PATCH 11/51] modify :: UserRepository.java --- .../domaserver/domain/user/repository/UserRepository.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/example/domaserver/domain/user/repository/UserRepository.java b/src/main/java/com/example/domaserver/domain/user/repository/UserRepository.java index 01f917c..954d069 100644 --- a/src/main/java/com/example/domaserver/domain/user/repository/UserRepository.java +++ b/src/main/java/com/example/domaserver/domain/user/repository/UserRepository.java @@ -8,4 +8,5 @@ public interface UserRepository extends JpaRepository { Optional findByEmail(String email); + Optional findByUsername(String Username); } From 07e3606a08746deb1308ea025119b658675363c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Mon, 11 Nov 2024 20:22:08 +0900 Subject: [PATCH 12/51] modify :: build.gradle --- build.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.gradle b/build.gradle index ba5dfc5..7dfae56 100644 --- a/build.gradle +++ b/build.gradle @@ -43,6 +43,8 @@ dependencies { //redis implementation ("org.springframework.boot:spring-boot-starter-data-redis") + implementation ("org.springframework.boot:spring-boot-starter-data-redis:2.3.1.RELEASE") + // aws implementation("org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE") From a42a331767d2fc8fa287e78157818c700dd001ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Mon, 11 Nov 2024 20:22:25 +0900 Subject: [PATCH 13/51] modify :: application.yml --- src/main/resources/application.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 89f9ffc..717b008 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,4 +1,8 @@ server: + redis: + port: 6739 + host: localhost + port: 8090 servlet: context-path: / @@ -33,9 +37,9 @@ spring: port: ${REDIS_PORT} jwt: - secret: ${JWT_SECRET} + secret: "your_secret_key_here" gauth: clientId: ${GAUTH_CLIENT} clientSecret: ${GAUTH_SECRET} - redirectUri: ${GAUTH_REDIRECT_URI} \ No newline at end of file + redirectUri: ${GAUTH_REDIRECT_URI} From 14e7af45c8e90b82802366f31bcb22299b55b023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Thu, 14 Nov 2024 19:50:14 +0900 Subject: [PATCH 14/51] add :: GetTopRankingServiceImpl.java --- .../impl/GetTopRankingServiceImpl.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/main/java/com/example/domaserver/domain/rank/service/impl/GetTopRankingServiceImpl.java diff --git a/src/main/java/com/example/domaserver/domain/rank/service/impl/GetTopRankingServiceImpl.java b/src/main/java/com/example/domaserver/domain/rank/service/impl/GetTopRankingServiceImpl.java new file mode 100644 index 0000000..3aaebe8 --- /dev/null +++ b/src/main/java/com/example/domaserver/domain/rank/service/impl/GetTopRankingServiceImpl.java @@ -0,0 +1,41 @@ +package com.example.domaserver.domain.rank.service.impl; + +import com.example.domaserver.domain.rank.entity.Rank; +import com.example.domaserver.domain.rank.service.GetTopRankingService; +import com.example.domaserver.global.annotation.ServiceWithReadOnlyTransactional; +import com.example.domaserver.global.annotation.ServiceWithTransaction; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.core.ZSetOperations; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + + +@ServiceWithTransaction +@ServiceWithReadOnlyTransactional +public class GetTopRankingServiceImpl implements GetTopRankingService { + + private static final String GET_TOP_RANKING = "getTopRanking"; + + private final RedisTemplate redisTemplate; + + public GetTopRankingServiceImpl(RedisTemplate redisTemplate) { + this.redisTemplate = redisTemplate; + } + + public List getTopRanking(int topN) { + Set> rankedUsers = + redisTemplate.opsForZSet().reverseRange(GET_TOP_RANKING, 0, topN - 1); + + List userRanks = new ArrayList<>(); + for (ZSetOperations.TypedTuple entry : rankedUsers) { + Long RankId = entry.getValue(); + Double RankScore = entry.getScore(); + userRanks.add(new Rank(RankId, RankScore)); + } + + return userRanks; + } + +} From 823fdf7092433c356c3622949bb3060c51048a66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Thu, 14 Nov 2024 19:50:42 +0900 Subject: [PATCH 15/51] add :: GetTopRankingService.java --- .../domain/rank/service/GetTopRankingService.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/main/java/com/example/domaserver/domain/rank/service/GetTopRankingService.java diff --git a/src/main/java/com/example/domaserver/domain/rank/service/GetTopRankingService.java b/src/main/java/com/example/domaserver/domain/rank/service/GetTopRankingService.java new file mode 100644 index 0000000..f6fdd84 --- /dev/null +++ b/src/main/java/com/example/domaserver/domain/rank/service/GetTopRankingService.java @@ -0,0 +1,9 @@ +package com.example.domaserver.domain.rank.service; + +import com.example.domaserver.domain.rank.entity.Rank; + +import java.util.List; + +public interface GetTopRankingService { + List getTopRanking(int topN); +} From 2b1dd70d98908b5cd3d6bffed253650320a17c6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Thu, 14 Nov 2024 19:51:12 +0900 Subject: [PATCH 16/51] add :: GetRankingServiceImpl.java --- .../service/impl/GetRankingServiceImpl.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/java/com/example/domaserver/domain/rank/service/impl/GetRankingServiceImpl.java diff --git a/src/main/java/com/example/domaserver/domain/rank/service/impl/GetRankingServiceImpl.java b/src/main/java/com/example/domaserver/domain/rank/service/impl/GetRankingServiceImpl.java new file mode 100644 index 0000000..dd68b09 --- /dev/null +++ b/src/main/java/com/example/domaserver/domain/rank/service/impl/GetRankingServiceImpl.java @@ -0,0 +1,27 @@ +package com.example.domaserver.domain.rank.service.impl; + +import com.example.domaserver.domain.rank.service.GetRankingService; +import com.example.domaserver.domain.user.entity.User; +import com.example.domaserver.global.annotation.ServiceWithReadOnlyTransactional; +import com.example.domaserver.global.annotation.ServiceWithTransaction; +import org.springframework.data.redis.core.RedisTemplate; + + +@ServiceWithTransaction +@ServiceWithReadOnlyTransactional +public class GetRankingServiceImpl implements GetRankingService { + + private static final String GET_RANKING = "getRank"; + + private final RedisTemplate redisTemplate; + + public GetRankingServiceImpl(RedisTemplate redisTemplate) { + this.redisTemplate = redisTemplate; + } + + public Long getRanking(User user) { + Long rank = redisTemplate.opsForZSet().rank(GET_RANKING, user.getId()); + return (rank != null) ? rank + 1 : null; + } + +} From 1f93210b5fe6938a2f3e70d6ce2f61317901123a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Thu, 14 Nov 2024 19:51:32 +0900 Subject: [PATCH 17/51] add :: GetRankingService.java --- .../domaserver/domain/rank/service/GetRankingService.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/java/com/example/domaserver/domain/rank/service/GetRankingService.java diff --git a/src/main/java/com/example/domaserver/domain/rank/service/GetRankingService.java b/src/main/java/com/example/domaserver/domain/rank/service/GetRankingService.java new file mode 100644 index 0000000..f5fa15b --- /dev/null +++ b/src/main/java/com/example/domaserver/domain/rank/service/GetRankingService.java @@ -0,0 +1,7 @@ +package com.example.domaserver.domain.rank.service; + +import com.example.domaserver.domain.user.entity.User; + +public interface GetRankingService { + Long getRanking(User user); +} From c2caf7c8fbe7e4b52eeae9fc58eaa1b0e77a8c07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Thu, 14 Nov 2024 19:51:55 +0900 Subject: [PATCH 18/51] add :: UpdateRankingServiceImpl.java --- .../impl/UpdateRankingServiceImpl.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/main/java/com/example/domaserver/domain/rank/service/impl/UpdateRankingServiceImpl.java diff --git a/src/main/java/com/example/domaserver/domain/rank/service/impl/UpdateRankingServiceImpl.java b/src/main/java/com/example/domaserver/domain/rank/service/impl/UpdateRankingServiceImpl.java new file mode 100644 index 0000000..4f468d4 --- /dev/null +++ b/src/main/java/com/example/domaserver/domain/rank/service/impl/UpdateRankingServiceImpl.java @@ -0,0 +1,25 @@ +package com.example.domaserver.domain.rank.service.impl; + +import com.example.domaserver.domain.rank.entity.Rank; +import com.example.domaserver.domain.rank.service.UpdateRankingService; +import com.example.domaserver.global.annotation.ServiceWithReadOnlyTransactional; +import com.example.domaserver.global.annotation.ServiceWithTransaction; +import org.springframework.data.redis.core.RedisTemplate; + + +@ServiceWithTransaction +public class UpdateRankingServiceImpl implements UpdateRankingService { + + private static final String UPDATE_RANKING = "update ranking set rank=rank+1 where rank=?"; + + private final RedisTemplate redisTemplate; + + public UpdateRankingServiceImpl(RedisTemplate redisTemplate) { + this.redisTemplate = redisTemplate; + } + + public void updateRanking(Rank rank) { + redisTemplate.opsForSet().add(UPDATE_RANKING, rank.getUser().getId(), rank.getPenaltyPoints()); + } + +} From 2fc1e70e69f48872a519b341b8b6b50f651200b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Thu, 14 Nov 2024 19:52:10 +0900 Subject: [PATCH 19/51] add :: UpdateRankingService.java --- .../domain/rank/service/UpdateRankingService.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/java/com/example/domaserver/domain/rank/service/UpdateRankingService.java diff --git a/src/main/java/com/example/domaserver/domain/rank/service/UpdateRankingService.java b/src/main/java/com/example/domaserver/domain/rank/service/UpdateRankingService.java new file mode 100644 index 0000000..0f29221 --- /dev/null +++ b/src/main/java/com/example/domaserver/domain/rank/service/UpdateRankingService.java @@ -0,0 +1,7 @@ +package com.example.domaserver.domain.rank.service; + +import com.example.domaserver.domain.rank.entity.Rank; + +public interface UpdateRankingService { + void updateRanking(Rank rank); +} From 6e642a9d6c7e111f16dbe40cbbf552a40468c602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Thu, 14 Nov 2024 19:52:43 +0900 Subject: [PATCH 20/51] modify :: RankController.java --- .../rank/presentation/RankController.java | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/example/domaserver/domain/rank/presentation/RankController.java b/src/main/java/com/example/domaserver/domain/rank/presentation/RankController.java index 8d858a9..3e3fb98 100644 --- a/src/main/java/com/example/domaserver/domain/rank/presentation/RankController.java +++ b/src/main/java/com/example/domaserver/domain/rank/presentation/RankController.java @@ -2,11 +2,13 @@ import com.example.domaserver.domain.rank.entity.Rank; -import com.example.domaserver.domain.rank.service.RankService; +import com.example.domaserver.domain.rank.service.GetRankingService; +import com.example.domaserver.domain.rank.service.GetTopRankingService; +import com.example.domaserver.domain.rank.service.UpdateRankingService; import com.example.domaserver.domain.user.entity.User; import com.example.domaserver.domain.user.service.UserService; import com.example.domaserver.global.security.jwt.JwtService; -import org.springframework.beans.factory.annotation.Autowired; +import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestHeader; @@ -15,32 +17,28 @@ import java.util.List; +@RequiredArgsConstructor @RestController @RequestMapping("/home") public class RankController { - private final RankService rankService; + + private final GetRankingService getRankingService; + private final GetTopRankingService getTopRankingService; + private final UpdateRankingService updateRankingService; private final UserService userService; private final JwtService jwtService; - @Autowired - public RankController(RankService rankService, UserService userService, JwtService jwtService) { - this.rankService = rankService; - this.userService = userService; - this.jwtService = jwtService; - } - @GetMapping("/rank") public ResponseEntity> getRanks() { - List topRanks = rankService.getTopRanking(25); + List topRanks = getTopRankingService.getTopRanking(25); return ResponseEntity.ok(topRanks); } @GetMapping("/my-rank") public ResponseEntity getMyRank(@RequestHeader("Authorization") String token) { User user = jwtService.getUserFromToken(token.substring(7)); - Long rank = rankService.getRanking(user); + Long rank = getRankingService.getRanking(user); return ResponseEntity.ok(rank); } - } From 58546449e1e7e0f1151a02bc8ff0831ba439238f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Thu, 14 Nov 2024 19:54:09 +0900 Subject: [PATCH 21/51] modify :: UserServiceImpl.java --- .../domain/user/service/impl/UserServiceImpl.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/example/domaserver/domain/user/service/impl/UserServiceImpl.java b/src/main/java/com/example/domaserver/domain/user/service/impl/UserServiceImpl.java index dd76b5e..14505df 100644 --- a/src/main/java/com/example/domaserver/domain/user/service/impl/UserServiceImpl.java +++ b/src/main/java/com/example/domaserver/domain/user/service/impl/UserServiceImpl.java @@ -4,21 +4,17 @@ import com.example.domaserver.domain.user.repository.UserRepository; import com.example.domaserver.domain.user.service.UserService; import com.example.domaserver.global.annotation.ServiceWithTransaction; -import org.springframework.beans.factory.annotation.Autowired; +import lombok.RequiredArgsConstructor; import org.springframework.security.core.userdetails.UsernameNotFoundException; import java.util.UUID; +@RequiredArgsConstructor @ServiceWithTransaction public class UserServiceImpl implements UserService { private final UserRepository userRepository; - @Autowired - public UserServiceImpl(UserRepository userRepository) { - this.userRepository = userRepository; - } - @Override public User findByUsername(String username) { return userRepository.findByUsername(username) From 08478b207f08caf5b2c206e5af3a58e1874674e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Thu, 14 Nov 2024 19:54:42 +0900 Subject: [PATCH 22/51] delete :: RankServiceImpl.java --- .../rank/service/impl/RankServiceImpl.java | 52 ------------------- 1 file changed, 52 deletions(-) delete mode 100644 src/main/java/com/example/domaserver/domain/rank/service/impl/RankServiceImpl.java diff --git a/src/main/java/com/example/domaserver/domain/rank/service/impl/RankServiceImpl.java b/src/main/java/com/example/domaserver/domain/rank/service/impl/RankServiceImpl.java deleted file mode 100644 index d0e38f1..0000000 --- a/src/main/java/com/example/domaserver/domain/rank/service/impl/RankServiceImpl.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.example.domaserver.domain.rank.service.impl; - -import com.example.domaserver.domain.rank.entity.Rank; -import com.example.domaserver.domain.rank.service.RankService; -import com.example.domaserver.domain.user.entity.User; -import com.example.domaserver.global.annotation.ServiceWithTransaction; -import jakarta.transaction.Transactional; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.core.ZSetOperations; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - - -@ServiceWithTransaction -public class RankServiceImpl implements RankService { - - private static final String RANK_KEY = "USER_RANKING"; - - private final RedisTemplate redisTemplate; - - public RankServiceImpl(@Qualifier("redisTemplate") RedisTemplate redisTemplate) { - this.redisTemplate = redisTemplate; - } - - @Transactional - public Long getRanking(User user) { - Long rank = redisTemplate.opsForZSet().rank(RANK_KEY, user.getId()); - return (rank != null) ? rank + 1 : null; - } - - @Transactional - public void updateRank(Rank rank) { - redisTemplate.opsForZSet().add(RANK_KEY, rank.getUser().getId(), rank.getPenaltyPoints()); - } - - @Transactional - public List getTopRanking(int topN) { - Set> rankedUsers = - redisTemplate.opsForZSet().reverseRangeWithScores(RANK_KEY, 0, topN - 1); - - List userRanks = new ArrayList<>(); - for (ZSetOperations.TypedTuple entry : rankedUsers) { - Long RankId = entry.getValue(); - Double RankScore = entry.getScore(); - userRanks.add(new Rank(RankId, RankScore)); - } - return userRanks; - } - -} From 6481c65a890cf1366c439e9c1c7a473cca5548cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Thu, 14 Nov 2024 19:54:56 +0900 Subject: [PATCH 23/51] delete :: RankService.java --- .../domaserver/domain/rank/service/RankService.java | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 src/main/java/com/example/domaserver/domain/rank/service/RankService.java diff --git a/src/main/java/com/example/domaserver/domain/rank/service/RankService.java b/src/main/java/com/example/domaserver/domain/rank/service/RankService.java deleted file mode 100644 index 6e3f501..0000000 --- a/src/main/java/com/example/domaserver/domain/rank/service/RankService.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.example.domaserver.domain.rank.service; - -import com.example.domaserver.domain.rank.entity.Rank; -import com.example.domaserver.domain.user.entity.User; -import java.util.List; - -public interface RankService { - Long getRanking(User user); - void updateRank(Rank rank); - List getTopRanking(int topN); -} From 35e0844fb34906f0c752c9b230e1f11fec789458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Thu, 14 Nov 2024 19:55:14 +0900 Subject: [PATCH 24/51] delete :: RedisConfig.java --- .../domain/rank/config/RedisConfig.java | 23 ------------------- 1 file changed, 23 deletions(-) delete mode 100644 src/main/java/com/example/domaserver/domain/rank/config/RedisConfig.java diff --git a/src/main/java/com/example/domaserver/domain/rank/config/RedisConfig.java b/src/main/java/com/example/domaserver/domain/rank/config/RedisConfig.java deleted file mode 100644 index 7dd6e41..0000000 --- a/src/main/java/com/example/domaserver/domain/rank/config/RedisConfig.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.example.domaserver.domain.rank.config; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.data.redis.connection.RedisConnectionFactory; -import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; -import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; - -@EnableRedisRepositories -@Configuration -public class RedisConfig { - @Value("${spring.redis.host}") - private String redisHost; - - @Value("${spring.redis.port}") - private int redisPort; - - @Bean - public RedisConnectionFactory redisConnectionFactory() { - return new LettuceConnectionFactory(redisHost, redisPort); - } -} From 7e202beaf5680fe04e2fe8a7909d3253a4144cd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Tue, 19 Nov 2024 20:00:53 +0900 Subject: [PATCH 25/51] modify :: GetRankingServiceImpl.java --- .../domain/rank/service/impl/GetRankingServiceImpl.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/example/domaserver/domain/rank/service/impl/GetRankingServiceImpl.java b/src/main/java/com/example/domaserver/domain/rank/service/impl/GetRankingServiceImpl.java index dd68b09..97d9724 100644 --- a/src/main/java/com/example/domaserver/domain/rank/service/impl/GetRankingServiceImpl.java +++ b/src/main/java/com/example/domaserver/domain/rank/service/impl/GetRankingServiceImpl.java @@ -3,22 +3,17 @@ import com.example.domaserver.domain.rank.service.GetRankingService; import com.example.domaserver.domain.user.entity.User; import com.example.domaserver.global.annotation.ServiceWithReadOnlyTransactional; -import com.example.domaserver.global.annotation.ServiceWithTransaction; +import lombok.RequiredArgsConstructor; import org.springframework.data.redis.core.RedisTemplate; - -@ServiceWithTransaction @ServiceWithReadOnlyTransactional +@RequiredArgsConstructor public class GetRankingServiceImpl implements GetRankingService { private static final String GET_RANKING = "getRank"; private final RedisTemplate redisTemplate; - public GetRankingServiceImpl(RedisTemplate redisTemplate) { - this.redisTemplate = redisTemplate; - } - public Long getRanking(User user) { Long rank = redisTemplate.opsForZSet().rank(GET_RANKING, user.getId()); return (rank != null) ? rank + 1 : null; From 593a11ef8acaf4ee8fe333e7cf3abf9ecd9cce8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Tue, 19 Nov 2024 20:01:12 +0900 Subject: [PATCH 26/51] modify :: GetTopRankingServiceImpl.java --- .../rank/service/impl/GetTopRankingServiceImpl.java | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/example/domaserver/domain/rank/service/impl/GetTopRankingServiceImpl.java b/src/main/java/com/example/domaserver/domain/rank/service/impl/GetTopRankingServiceImpl.java index 3aaebe8..e8ecf9a 100644 --- a/src/main/java/com/example/domaserver/domain/rank/service/impl/GetTopRankingServiceImpl.java +++ b/src/main/java/com/example/domaserver/domain/rank/service/impl/GetTopRankingServiceImpl.java @@ -3,7 +3,7 @@ import com.example.domaserver.domain.rank.entity.Rank; import com.example.domaserver.domain.rank.service.GetTopRankingService; import com.example.domaserver.global.annotation.ServiceWithReadOnlyTransactional; -import com.example.domaserver.global.annotation.ServiceWithTransaction; +import lombok.RequiredArgsConstructor; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.ZSetOperations; @@ -11,19 +11,14 @@ import java.util.List; import java.util.Set; - -@ServiceWithTransaction @ServiceWithReadOnlyTransactional +@RequiredArgsConstructor public class GetTopRankingServiceImpl implements GetTopRankingService { private static final String GET_TOP_RANKING = "getTopRanking"; private final RedisTemplate redisTemplate; - public GetTopRankingServiceImpl(RedisTemplate redisTemplate) { - this.redisTemplate = redisTemplate; - } - public List getTopRanking(int topN) { Set> rankedUsers = redisTemplate.opsForZSet().reverseRange(GET_TOP_RANKING, 0, topN - 1); From 75819788f58be02726a594146473e6899646dec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Tue, 19 Nov 2024 20:01:31 +0900 Subject: [PATCH 27/51] modify :: UpdateRankingServiceImpl.java --- .../domain/rank/service/impl/UpdateRankingServiceImpl.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/example/domaserver/domain/rank/service/impl/UpdateRankingServiceImpl.java b/src/main/java/com/example/domaserver/domain/rank/service/impl/UpdateRankingServiceImpl.java index 4f468d4..25aee58 100644 --- a/src/main/java/com/example/domaserver/domain/rank/service/impl/UpdateRankingServiceImpl.java +++ b/src/main/java/com/example/domaserver/domain/rank/service/impl/UpdateRankingServiceImpl.java @@ -2,22 +2,19 @@ import com.example.domaserver.domain.rank.entity.Rank; import com.example.domaserver.domain.rank.service.UpdateRankingService; -import com.example.domaserver.global.annotation.ServiceWithReadOnlyTransactional; import com.example.domaserver.global.annotation.ServiceWithTransaction; +import lombok.RequiredArgsConstructor; import org.springframework.data.redis.core.RedisTemplate; @ServiceWithTransaction +@RequiredArgsConstructor public class UpdateRankingServiceImpl implements UpdateRankingService { private static final String UPDATE_RANKING = "update ranking set rank=rank+1 where rank=?"; private final RedisTemplate redisTemplate; - public UpdateRankingServiceImpl(RedisTemplate redisTemplate) { - this.redisTemplate = redisTemplate; - } - public void updateRanking(Rank rank) { redisTemplate.opsForSet().add(UPDATE_RANKING, rank.getUser().getId(), rank.getPenaltyPoints()); } From ea0e18e32113c72aa4392c51406019afe6a5048b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Thu, 21 Nov 2024 20:34:27 +0900 Subject: [PATCH 28/51] modify :: User.java --- .../java/com/example/domaserver/domain/user/entity/User.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/example/domaserver/domain/user/entity/User.java b/src/main/java/com/example/domaserver/domain/user/entity/User.java index 127e947..53abf0b 100644 --- a/src/main/java/com/example/domaserver/domain/user/entity/User.java +++ b/src/main/java/com/example/domaserver/domain/user/entity/User.java @@ -16,6 +16,7 @@ public class User { private UUID id; private String name; private String email; + private String profileImageUrl; private int penaltyPoint; @Embedded @@ -23,6 +24,4 @@ public class User { @Enumerated(EnumType.STRING) private Authority authority; - - } From 994ac4611493ec7d5486263f2709553144afd5d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Thu, 21 Nov 2024 20:34:44 +0900 Subject: [PATCH 29/51] modify :: RankResponse.java --- .../domain/rank/presentation/dto/response/RankResponse.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/example/domaserver/domain/rank/presentation/dto/response/RankResponse.java b/src/main/java/com/example/domaserver/domain/rank/presentation/dto/response/RankResponse.java index 6296953..6d9a1b0 100644 --- a/src/main/java/com/example/domaserver/domain/rank/presentation/dto/response/RankResponse.java +++ b/src/main/java/com/example/domaserver/domain/rank/presentation/dto/response/RankResponse.java @@ -10,7 +10,6 @@ public class RankResponse { private UUID Id; private String name; - private String profileImageUrl; private int penaltyPoints; private double RankScore; } From 039cbd7bebbeaf4572986a3c65a2a448cbcfa56f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Thu, 21 Nov 2024 23:10:40 +0900 Subject: [PATCH 30/51] Revert "modify :: User.java" This reverts commit ea0e18e32113c72aa4392c51406019afe6a5048b. --- .../java/com/example/domaserver/domain/user/entity/User.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/domaserver/domain/user/entity/User.java b/src/main/java/com/example/domaserver/domain/user/entity/User.java index 53abf0b..127e947 100644 --- a/src/main/java/com/example/domaserver/domain/user/entity/User.java +++ b/src/main/java/com/example/domaserver/domain/user/entity/User.java @@ -16,7 +16,6 @@ public class User { private UUID id; private String name; private String email; - private String profileImageUrl; private int penaltyPoint; @Embedded @@ -24,4 +23,6 @@ public class User { @Enumerated(EnumType.STRING) private Authority authority; + + } From e8c46cd79a718f91a707fb6ea2d773e2bc3d588d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Thu, 21 Nov 2024 23:14:15 +0900 Subject: [PATCH 31/51] Revert "modify :: RankResponse.java" This reverts commit 994ac4611493ec7d5486263f2709553144afd5d2. --- .../domain/rank/presentation/dto/response/RankResponse.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/example/domaserver/domain/rank/presentation/dto/response/RankResponse.java b/src/main/java/com/example/domaserver/domain/rank/presentation/dto/response/RankResponse.java index 6d9a1b0..6296953 100644 --- a/src/main/java/com/example/domaserver/domain/rank/presentation/dto/response/RankResponse.java +++ b/src/main/java/com/example/domaserver/domain/rank/presentation/dto/response/RankResponse.java @@ -10,6 +10,7 @@ public class RankResponse { private UUID Id; private String name; + private String profileImageUrl; private int penaltyPoints; private double RankScore; } From 137867c8434c649733c31957d55b43376996c76e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Wed, 5 Mar 2025 20:35:41 +0900 Subject: [PATCH 32/51] add :: AlreadExistsException.java --- .../domain/user/exception/AlreadExistsException.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/java/com/example/domaserver/domain/user/exception/AlreadExistsException.java diff --git a/src/main/java/com/example/domaserver/domain/user/exception/AlreadExistsException.java b/src/main/java/com/example/domaserver/domain/user/exception/AlreadExistsException.java new file mode 100644 index 0000000..d5cca8d --- /dev/null +++ b/src/main/java/com/example/domaserver/domain/user/exception/AlreadExistsException.java @@ -0,0 +1,7 @@ +package com.example.domaserver.domain.user.exception; + +public class AlreadExistsException extends RuntimeException { + public AlreadExistsException(String message) { + super(message); + } +} From 9d0d536b01ed4e4f9d97e1c1b9e91856685a1060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Mon, 24 Mar 2025 20:50:14 +0900 Subject: [PATCH 33/51] modify :: User.java --- .../com/example/domaserver/domain/user/entity/User.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/example/domaserver/domain/user/entity/User.java b/src/main/java/com/example/domaserver/domain/user/entity/User.java index 127e947..071706d 100644 --- a/src/main/java/com/example/domaserver/domain/user/entity/User.java +++ b/src/main/java/com/example/domaserver/domain/user/entity/User.java @@ -13,16 +13,16 @@ public class User { @Id @GeneratedValue(generator = "UUID4") + @Column(length = 36) private UUID id; - private String name; + + private String username; private String email; - private int penaltyPoint; + private String password; @Embedded private StudentNum studentNum; @Enumerated(EnumType.STRING) private Authority authority; - - } From d20d3571f0924fecdf97edeb89ad5c08a677d4df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Mon, 24 Mar 2025 20:50:38 +0900 Subject: [PATCH 34/51] modify :: UserRepository.java --- .../domaserver/domain/user/repository/UserRepository.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/domaserver/domain/user/repository/UserRepository.java b/src/main/java/com/example/domaserver/domain/user/repository/UserRepository.java index 954d069..27b2d67 100644 --- a/src/main/java/com/example/domaserver/domain/user/repository/UserRepository.java +++ b/src/main/java/com/example/domaserver/domain/user/repository/UserRepository.java @@ -2,11 +2,13 @@ import com.example.domaserver.domain.user.entity.User; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; import java.util.Optional; import java.util.UUID; +@Repository public interface UserRepository extends JpaRepository { Optional findByEmail(String email); - Optional findByUsername(String Username); + Optional findByUsername(String username); } From 38a561146d042499a94cc47b062af0388a1a1f12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Mon, 24 Mar 2025 21:01:58 +0900 Subject: [PATCH 35/51] modify :: UserServiceImpl.java --- .../domain/user/service/impl/UserServiceImpl.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/example/domaserver/domain/user/service/impl/UserServiceImpl.java b/src/main/java/com/example/domaserver/domain/user/service/impl/UserServiceImpl.java index 14505df..237770e 100644 --- a/src/main/java/com/example/domaserver/domain/user/service/impl/UserServiceImpl.java +++ b/src/main/java/com/example/domaserver/domain/user/service/impl/UserServiceImpl.java @@ -1,6 +1,7 @@ package com.example.domaserver.domain.user.service.impl; import com.example.domaserver.domain.user.entity.User; +import com.example.domaserver.domain.user.exception.NotFoundException; import com.example.domaserver.domain.user.repository.UserRepository; import com.example.domaserver.domain.user.service.UserService; import com.example.domaserver.global.annotation.ServiceWithTransaction; @@ -16,15 +17,15 @@ public class UserServiceImpl implements UserService { private final UserRepository userRepository; @Override - public User findByUsername(String username) { - return userRepository.findByUsername(username) - .orElseThrow(() -> new UsernameNotFoundException("User not found with username: " + username)); + public User findByUsername(String name) { + return userRepository.findByUsername(name) + .orElseThrow(() -> new NotFoundException("User not found with username: " + name)); } @Override public User findById(UUID id) { return userRepository.findById(id) - .orElseThrow(() -> new UsernameNotFoundException("User not found with id: " + id)); + .orElseThrow(() -> new NotFoundException("User not found with id: " + id)); } } From cced1e3c454efbef827be7f2d7ceaab1997e6c71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Mon, 24 Mar 2025 21:02:52 +0900 Subject: [PATCH 36/51] add :: InvalidUserExeption.java --- .../domain/user/exception/InvalidUserExeption.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/java/com/example/domaserver/domain/user/exception/InvalidUserExeption.java diff --git a/src/main/java/com/example/domaserver/domain/user/exception/InvalidUserExeption.java b/src/main/java/com/example/domaserver/domain/user/exception/InvalidUserExeption.java new file mode 100644 index 0000000..3502aa9 --- /dev/null +++ b/src/main/java/com/example/domaserver/domain/user/exception/InvalidUserExeption.java @@ -0,0 +1,7 @@ +package com.example.domaserver.domain.user.exception; + +public class InvalidUserExeption extends RuntimeException { + public InvalidUserExeption(String message) { + super(message); + } +} From 23201152d88a762e0a70c30129ecc61ed01f8916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Tue, 25 Mar 2025 08:14:57 +0900 Subject: [PATCH 37/51] modify :: NotFoundException.java feat :: User --- .../domain/user/exception/NotFoundException.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/java/com/example/domaserver/domain/user/exception/NotFoundException.java diff --git a/src/main/java/com/example/domaserver/domain/user/exception/NotFoundException.java b/src/main/java/com/example/domaserver/domain/user/exception/NotFoundException.java new file mode 100644 index 0000000..b7e6c9c --- /dev/null +++ b/src/main/java/com/example/domaserver/domain/user/exception/NotFoundException.java @@ -0,0 +1,7 @@ +package com.example.domaserver.domain.user.exception; + +public class NotFoundException extends RuntimeException { + public NotFoundException(String message) { + super(message); + } +} From 760ee5a2bbba2a3d333eaf376a80daa4e1161b09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Tue, 25 Mar 2025 08:15:35 +0900 Subject: [PATCH 38/51] modify :: Rank.java --- .../domaserver/domain/rank/entity/Rank.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/example/domaserver/domain/rank/entity/Rank.java b/src/main/java/com/example/domaserver/domain/rank/entity/Rank.java index e1d40e7..96b574b 100644 --- a/src/main/java/com/example/domaserver/domain/rank/entity/Rank.java +++ b/src/main/java/com/example/domaserver/domain/rank/entity/Rank.java @@ -8,24 +8,26 @@ import lombok.NoArgsConstructor; @Entity +@Table(name = "rank_table") @Getter @Builder @NoArgsConstructor @AllArgsConstructor public class Rank { - @Id - @GeneratedValue(strategy =GenerationType.IDENTITY) - private Long RankId; - private int PenaltyPoints; - private double RankScore; + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long rankId; + + private int penaltyPoints; + private double rankScore; @ManyToOne - @JoinColumn(name = "user_id") + @JoinColumn(name = "user_id", columnDefinition = "CHAR(36)") private User user; - public Rank(Long rankId, Double rankScore) { - RankId = rankId; - RankScore = rankScore; + public Rank(Long rankId, User user, Double rankScore) { + this.rankId = rankId; + this.user = user; + this.rankScore = rankScore; } } From fcda4901ed182839e364b09328817b4fac32734b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Tue, 25 Mar 2025 08:17:33 +0900 Subject: [PATCH 39/51] modify :: GetRankingServiceImpl.java --- .../domain/rank/service/impl/GetRankingServiceImpl.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/com/example/domaserver/domain/rank/service/impl/GetRankingServiceImpl.java b/src/main/java/com/example/domaserver/domain/rank/service/impl/GetRankingServiceImpl.java index 97d9724..c444a81 100644 --- a/src/main/java/com/example/domaserver/domain/rank/service/impl/GetRankingServiceImpl.java +++ b/src/main/java/com/example/domaserver/domain/rank/service/impl/GetRankingServiceImpl.java @@ -9,14 +9,12 @@ @ServiceWithReadOnlyTransactional @RequiredArgsConstructor public class GetRankingServiceImpl implements GetRankingService { - private static final String GET_RANKING = "getRank"; private final RedisTemplate redisTemplate; public Long getRanking(User user) { - Long rank = redisTemplate.opsForZSet().rank(GET_RANKING, user.getId()); + Long rank = redisTemplate.opsForZSet().reverseRank(GET_RANKING, user.getId().toString()); return (rank != null) ? rank + 1 : null; } - } From 4ef693c10859e80c2c0a9c8621c2b2d23e746835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Tue, 25 Mar 2025 08:20:37 +0900 Subject: [PATCH 40/51] update :: GetTopRankingServiceImpl.java --- .../impl/GetTopRankingServiceImpl.java | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/example/domaserver/domain/rank/service/impl/GetTopRankingServiceImpl.java b/src/main/java/com/example/domaserver/domain/rank/service/impl/GetTopRankingServiceImpl.java index e8ecf9a..7af3efe 100644 --- a/src/main/java/com/example/domaserver/domain/rank/service/impl/GetTopRankingServiceImpl.java +++ b/src/main/java/com/example/domaserver/domain/rank/service/impl/GetTopRankingServiceImpl.java @@ -2,6 +2,8 @@ import com.example.domaserver.domain.rank.entity.Rank; import com.example.domaserver.domain.rank.service.GetTopRankingService; +import com.example.domaserver.domain.user.entity.User; +import com.example.domaserver.domain.user.repository.UserRepository; import com.example.domaserver.global.annotation.ServiceWithReadOnlyTransactional; import lombok.RequiredArgsConstructor; import org.springframework.data.redis.core.RedisTemplate; @@ -9,28 +11,41 @@ import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Set; +import java.util.UUID; +import java.util.stream.Collectors; @ServiceWithReadOnlyTransactional @RequiredArgsConstructor public class GetTopRankingServiceImpl implements GetTopRankingService { - private static final String GET_TOP_RANKING = "getTopRanking"; private final RedisTemplate redisTemplate; + private final UserRepository userRepository; public List getTopRanking(int topN) { - Set> rankedUsers = - redisTemplate.opsForZSet().reverseRange(GET_TOP_RANKING, 0, topN - 1); + Set> rankedUsers = + redisTemplate.opsForZSet().reverseRangeWithScores(GET_TOP_RANKING, 0, topN - 1); + + List userIds = rankedUsers.stream() + .map(entry -> UUID.fromString(entry.getValue())) + .collect(Collectors.toList()); + + Map userMap = userRepository.findAllById(userIds).stream() + .collect(Collectors.toMap(User::getId, user -> user)); List userRanks = new ArrayList<>(); - for (ZSetOperations.TypedTuple entry : rankedUsers) { - Long RankId = entry.getValue(); - Double RankScore = entry.getScore(); - userRanks.add(new Rank(RankId, RankScore)); + for (ZSetOperations.TypedTuple entry : rankedUsers) { + UUID userId = UUID.fromString(entry.getValue()); + Double rankScore = entry.getScore(); + User user = userMap.get(userId); + + if (user != null) { + userRanks.add(new Rank(null, user, rankScore)); + } } return userRanks; } - } From f273c54db0507a6491a60033f2586f672deba7c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Tue, 25 Mar 2025 08:21:17 +0900 Subject: [PATCH 41/51] modify :: UpdateRankingServiceImpl.java --- .../domain/rank/service/impl/UpdateRankingServiceImpl.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/com/example/domaserver/domain/rank/service/impl/UpdateRankingServiceImpl.java b/src/main/java/com/example/domaserver/domain/rank/service/impl/UpdateRankingServiceImpl.java index 25aee58..19cf47a 100644 --- a/src/main/java/com/example/domaserver/domain/rank/service/impl/UpdateRankingServiceImpl.java +++ b/src/main/java/com/example/domaserver/domain/rank/service/impl/UpdateRankingServiceImpl.java @@ -10,13 +10,11 @@ @ServiceWithTransaction @RequiredArgsConstructor public class UpdateRankingServiceImpl implements UpdateRankingService { - private static final String UPDATE_RANKING = "update ranking set rank=rank+1 where rank=?"; private final RedisTemplate redisTemplate; public void updateRanking(Rank rank) { - redisTemplate.opsForSet().add(UPDATE_RANKING, rank.getUser().getId(), rank.getPenaltyPoints()); + redisTemplate.opsForZSet().add(UPDATE_RANKING, rank.getUser().getId().toString(), rank.getPenaltyPoints()); } - } From c9b7627f24e8bf6d8334b6c93d6e1d551e22f756 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Tue, 25 Mar 2025 08:28:38 +0900 Subject: [PATCH 42/51] update :: RankController.java feat :: Rank --- .../rank/presentation/RankController.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/example/domaserver/domain/rank/presentation/RankController.java b/src/main/java/com/example/domaserver/domain/rank/presentation/RankController.java index 3e3fb98..460bdc2 100644 --- a/src/main/java/com/example/domaserver/domain/rank/presentation/RankController.java +++ b/src/main/java/com/example/domaserver/domain/rank/presentation/RankController.java @@ -1,7 +1,7 @@ package com.example.domaserver.domain.rank.presentation; - import com.example.domaserver.domain.rank.entity.Rank; +import com.example.domaserver.domain.rank.presentation.dto.response.RankResponse; import com.example.domaserver.domain.rank.service.GetRankingService; import com.example.domaserver.domain.rank.service.GetTopRankingService; import com.example.domaserver.domain.rank.service.UpdateRankingService; @@ -16,12 +16,12 @@ import org.springframework.web.bind.annotation.RestController; import java.util.List; +import java.util.stream.Collectors; @RequiredArgsConstructor @RestController @RequestMapping("/home") public class RankController { - private final GetRankingService getRankingService; private final GetTopRankingService getTopRankingService; private final UpdateRankingService updateRankingService; @@ -29,9 +29,9 @@ public class RankController { private final JwtService jwtService; @GetMapping("/rank") - public ResponseEntity> getRanks() { + public ResponseEntity> getRanks() { List topRanks = getTopRankingService.getTopRanking(25); - return ResponseEntity.ok(topRanks); + return ResponseEntity.ok(toRankResponses(topRanks)); } @GetMapping("/my-rank") @@ -41,4 +41,18 @@ public ResponseEntity getMyRank(@RequestHeader("Authorization") String tok return ResponseEntity.ok(rank); } + private List toRankResponses(List ranks) { + return ranks.stream() + .map(this::toRankResponse) + .collect(Collectors.toList()); + } + + private RankResponse toRankResponse(Rank rank) { + return RankResponse.builder() + .Id(rank.getUser().getId()) + .name(rank.getUser().getUsername()) + .penaltyPoints(rank.getPenaltyPoints()) + .RankScore(rank.getRankScore()) + .build(); + } } From dd82968502ff78b579780110a6949be1dcb67d99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Tue, 25 Mar 2025 08:30:34 +0900 Subject: [PATCH 43/51] modify :: application.yml feat :: DB --- src/main/resources/application.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 717b008..8262fd9 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -13,7 +13,7 @@ server: spring: datasource: - driver-class-name: com.mysql.cj.jdbc.Driver + driver-class-name: org.mariadb.jdbc.Driver url: ${DB_URL} username: ${DB_USERNAME} password: ${DB_PASSWORD} @@ -37,9 +37,10 @@ spring: port: ${REDIS_PORT} jwt: - secret: "your_secret_key_here" + secret: ${JWT_KEY} gauth: clientId: ${GAUTH_CLIENT} clientSecret: ${GAUTH_SECRET} redirectUri: ${GAUTH_REDIRECT_URI} + From 6aab0e533b9a7064fc856ccecab37e2d97d73553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Tue, 25 Mar 2025 12:07:12 +0900 Subject: [PATCH 44/51] modify :: UserNotFoundException.java --- .../domain/user/exception/UserNotFoundException.java | 10 ++++++++++ .../example/domaserver/global/exception/ErrorCode.java | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/example/domaserver/domain/user/exception/UserNotFoundException.java diff --git a/src/main/java/com/example/domaserver/domain/user/exception/UserNotFoundException.java b/src/main/java/com/example/domaserver/domain/user/exception/UserNotFoundException.java new file mode 100644 index 0000000..aecd425 --- /dev/null +++ b/src/main/java/com/example/domaserver/domain/user/exception/UserNotFoundException.java @@ -0,0 +1,10 @@ +package com.example.domaserver.domain.user.exception; + +import com.example.domaserver.global.exception.CustomException; +import com.example.domaserver.global.exception.ErrorCode; + +public class UserNotFoundException extends CustomException { + public UserNotFoundException() { + super(ErrorCode.MEMBER_NOT_FOUND); + } +} \ No newline at end of file diff --git a/src/main/java/com/example/domaserver/global/exception/ErrorCode.java b/src/main/java/com/example/domaserver/global/exception/ErrorCode.java index 5ad8568..50bb817 100644 --- a/src/main/java/com/example/domaserver/global/exception/ErrorCode.java +++ b/src/main/java/com/example/domaserver/global/exception/ErrorCode.java @@ -7,13 +7,17 @@ @Getter public enum ErrorCode { - MEMBER_NOT_FOUND(404, "유저를 찾을 수 없습니다"), + MEMBER_NOT_FOUND(404, "해당 ID의 유저를 찾을 수 없습니다."), + MEMBER_NOT_FOUND_BY_USERNAME(404, "해당 이름의 유저를 찾을 수 없습니다."), EXPIRED_TOKEN(401, "토큰이 만료되었습니다."), INVALID_TOKEN_TYPE(401, "유효하지 않은 토큰 타입입니다."), INVALID_TOKEN(401, "유효하지 않은 토큰입니다."), EXPIRED_REFRESH_TOKEN(401, "만료된 리프레쉬 토큰입니다."), + EMAIL_ALREADY_EXISTS(409, "이미 존재하는 이메일입니다."), + PASSWORD_MISMATCH(401, "비밀번호가 일치하지 않습니다."), + INTERNAL_SERVER_ERROR(500, "예기치 못한 서버 에러"); private final int httpStatus; From 85db00e872ffc630c260e049529c6d880db60157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Tue, 25 Mar 2025 12:07:36 +0900 Subject: [PATCH 45/51] modify :: UsernameNotFoundException.java --- .../user/exception/UsernameNotFoundException.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/main/java/com/example/domaserver/domain/user/exception/UsernameNotFoundException.java diff --git a/src/main/java/com/example/domaserver/domain/user/exception/UsernameNotFoundException.java b/src/main/java/com/example/domaserver/domain/user/exception/UsernameNotFoundException.java new file mode 100644 index 0000000..7a28c90 --- /dev/null +++ b/src/main/java/com/example/domaserver/domain/user/exception/UsernameNotFoundException.java @@ -0,0 +1,10 @@ +package com.example.domaserver.domain.user.exception; + +import com.example.domaserver.global.exception.CustomException; +import com.example.domaserver.global.exception.ErrorCode; + +public class UsernameNotFoundException extends CustomException { + public UsernameNotFoundException() { + super(ErrorCode.MEMBER_NOT_FOUND_BY_USERNAME); + } +} \ No newline at end of file From 22c8f80f3cc63021bfdef2d8b8d46506c74cf160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Tue, 25 Mar 2025 12:08:01 +0900 Subject: [PATCH 46/51] modify :: UserServiceImpl.java --- .../domain/user/service/impl/UserServiceImpl.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/example/domaserver/domain/user/service/impl/UserServiceImpl.java b/src/main/java/com/example/domaserver/domain/user/service/impl/UserServiceImpl.java index 237770e..cf058ec 100644 --- a/src/main/java/com/example/domaserver/domain/user/service/impl/UserServiceImpl.java +++ b/src/main/java/com/example/domaserver/domain/user/service/impl/UserServiceImpl.java @@ -1,12 +1,12 @@ package com.example.domaserver.domain.user.service.impl; import com.example.domaserver.domain.user.entity.User; -import com.example.domaserver.domain.user.exception.NotFoundException; +import com.example.domaserver.domain.user.exception.UserNotFoundException; +import com.example.domaserver.domain.user.exception.UsernameNotFoundException; import com.example.domaserver.domain.user.repository.UserRepository; import com.example.domaserver.domain.user.service.UserService; import com.example.domaserver.global.annotation.ServiceWithTransaction; import lombok.RequiredArgsConstructor; -import org.springframework.security.core.userdetails.UsernameNotFoundException; import java.util.UUID; @@ -19,13 +19,12 @@ public class UserServiceImpl implements UserService { @Override public User findByUsername(String name) { return userRepository.findByUsername(name) - .orElseThrow(() -> new NotFoundException("User not found with username: " + name)); + .orElseThrow(UsernameNotFoundException::new); } @Override public User findById(UUID id) { return userRepository.findById(id) - .orElseThrow(() -> new NotFoundException("User not found with id: " + id)); + .orElseThrow(UserNotFoundException::new); } - } From 3b16536c4b735f9f7e1dc4e32ed68a78a23d5487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Tue, 25 Mar 2025 16:45:17 +0900 Subject: [PATCH 47/51] delete :: NotFoundException.java --- .../domain/user/exception/NotFoundException.java | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 src/main/java/com/example/domaserver/domain/user/exception/NotFoundException.java diff --git a/src/main/java/com/example/domaserver/domain/user/exception/NotFoundException.java b/src/main/java/com/example/domaserver/domain/user/exception/NotFoundException.java deleted file mode 100644 index b7e6c9c..0000000 --- a/src/main/java/com/example/domaserver/domain/user/exception/NotFoundException.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.example.domaserver.domain.user.exception; - -public class NotFoundException extends RuntimeException { - public NotFoundException(String message) { - super(message); - } -} From 601722cb00cd4146008bbdc5158600310ef0b075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Thu, 3 Apr 2025 20:24:34 +0900 Subject: [PATCH 48/51] modify :: application.yml --- src/main/resources/application.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 717b008..b44f80f 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -3,7 +3,7 @@ server: port: 6739 host: localhost - port: 8090 + port: 8080 servlet: context-path: / encoding: @@ -13,7 +13,7 @@ server: spring: datasource: - driver-class-name: com.mysql.cj.jdbc.Driver + driver-class-name: org.mariadb.jdbc.Driver url: ${DB_URL} username: ${DB_USERNAME} password: ${DB_PASSWORD} From 39b309517119978a7f3fcf21d2a65cfc2a2e7388 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Thu, 3 Apr 2025 20:30:43 +0900 Subject: [PATCH 49/51] modify :: UserServiceImpl.java --- .../domain/user/service/impl/UserServiceImpl.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/example/domaserver/domain/user/service/impl/UserServiceImpl.java b/src/main/java/com/example/domaserver/domain/user/service/impl/UserServiceImpl.java index 237770e..6dc5faf 100644 --- a/src/main/java/com/example/domaserver/domain/user/service/impl/UserServiceImpl.java +++ b/src/main/java/com/example/domaserver/domain/user/service/impl/UserServiceImpl.java @@ -2,11 +2,12 @@ import com.example.domaserver.domain.user.entity.User; import com.example.domaserver.domain.user.exception.NotFoundException; +import com.example.domaserver.domain.user.exception.UserNotFoundException; +import com.example.domaserver.domain.user.exception.UsernameNotFoundException; import com.example.domaserver.domain.user.repository.UserRepository; import com.example.domaserver.domain.user.service.UserService; import com.example.domaserver.global.annotation.ServiceWithTransaction; import lombok.RequiredArgsConstructor; -import org.springframework.security.core.userdetails.UsernameNotFoundException; import java.util.UUID; @@ -19,13 +20,12 @@ public class UserServiceImpl implements UserService { @Override public User findByUsername(String name) { return userRepository.findByUsername(name) - .orElseThrow(() -> new NotFoundException("User not found with username: " + name)); + .orElseThrow(() -> new NotFoundException("User not found with username " + name)); } @Override public User findById(UUID id) { return userRepository.findById(id) - .orElseThrow(() -> new NotFoundException("User not found with id: " + id)); + .orElseThrow(() -> new NotFoundException("User not found with id " + id)); } - } From 3297aab20c53a8a2493cc8ae1976041f83755e54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Thu, 3 Apr 2025 20:32:33 +0900 Subject: [PATCH 50/51] modify :: NotFoundException.java --- .../domaserver/domain/user/exception/NotFoundException.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/example/domaserver/domain/user/exception/NotFoundException.java b/src/main/java/com/example/domaserver/domain/user/exception/NotFoundException.java index b7e6c9c..a1fdcfb 100644 --- a/src/main/java/com/example/domaserver/domain/user/exception/NotFoundException.java +++ b/src/main/java/com/example/domaserver/domain/user/exception/NotFoundException.java @@ -4,4 +4,4 @@ public class NotFoundException extends RuntimeException { public NotFoundException(String message) { super(message); } -} +} \ No newline at end of file From a6517ef0a1ad24beceae28ba93c54e5c016543a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=ED=95=9C=EC=A3=BC?= Date: Thu, 3 Apr 2025 20:58:38 +0900 Subject: [PATCH 51/51] modify :: application.yml --- src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 43d5379..06d7c20 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -37,7 +37,7 @@ spring: port: ${REDIS_PORT} jwt: - secret: ${JWT_KEY} + secret: "your_secret_key_here" gauth: clientId: ${GAUTH_CLIENT}