Skip to content

Commit

Permalink
fix error and add CacheDevController (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanmomo committed May 20, 2024
1 parent e570a92 commit dfef458
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions deploy/docker-compose-backend-app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ services:
- CRON_DIS=
ports:
- '8080:8080'
- '127.0.0.1:9093:9093'
volumes:
- ./logs:/logs
restart: always
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public BaseResponse createMember(@Valid @RequestBody Member member, @RequestPara

@PutMapping("/update")
public BaseResponse updateMemberByAddress(@RequestParam String address, @RequestBody MemberVo member, HttpServletRequest request) {
this.memberService.nickNameExists(member.getNickName());
// this.memberService.nickNameExists(member.getNickName());

Optional<Member> memberData = memberRepository.findByAddress(address);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;

import java.util.Map;
import java.util.concurrent.TimeUnit;

public class AccessTokenCacheService {
private static final Cache<String, String> ACCESS_TOKEN_CACHE = CacheBuilder.newBuilder()
.expireAfterWrite(6, TimeUnit.MINUTES)
.build();

public static void addGitHubAccessToken(String username, String accessToken){
ACCESS_TOKEN_CACHE.put(gitHubAccessTokenKey(username),accessToken);
public static void addGitHubAccessToken(String username, String accessToken) {
ACCESS_TOKEN_CACHE.put(gitHubAccessTokenKey(username), accessToken);
}
public static String getGitHubAccessToken(String username){

public static String getGitHubAccessToken(String username) {
return ACCESS_TOKEN_CACHE.getIfPresent(gitHubAccessTokenKey(username));
}

private static String gitHubAccessTokenKey(String username){
public static Map<String, String> listAll() {
return ACCESS_TOKEN_CACHE.asMap();
}

private static String gitHubAccessTokenKey(String username) {
return String.format("%s_GITHUB_ACCESS_TOKEN", username);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.dl.officialsite.oauth2.controller;


import com.dl.officialsite.common.base.BaseResponse;
import com.dl.officialsite.oauth2.AccessTokenCacheService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Profile;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@Profile({"dev", "local"})
public class CacheDevController {

@GetMapping("cache/list")
public BaseResponse listAll(){
return BaseResponse.successWithData(AccessTokenCacheService.listAll());
}
@GetMapping("cache/add")
public BaseResponse add(@RequestParam String key,@RequestParam String value){
AccessTokenCacheService.addGitHubAccessToken(key,value);
return BaseResponse.success();
}

}

0 comments on commit dfef458

Please sign in to comment.