Skip to content

Commit

Permalink
Merge pull request #258 from FashionWeek-Runway/feature/issue-257
Browse files Browse the repository at this point in the history
관리자 페이지 일부구현 (#257)
  • Loading branch information
imenuuu authored May 5, 2024
2 parents 4d352e2 + 047529e commit 9ab5448
Show file tree
Hide file tree
Showing 24 changed files with 354 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .ebextensions-dev/00-makeFiles.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ files:
group: webapp
content: |
kill `ps -ef | grep runway-dev-api | awk '{print $2}'`
java -Dspring.profiles.active=local -Dfile.encoding=UTF-8 -jar /var/app/current/runway-dev-api.jar
java -Dspring.profiles.active=local -Dfile.encoding=UTF-8 -jar /var/app/current/runway-dev-api.jar
1 change: 1 addition & 0 deletions .platform/nginx/conf.d/01_client_size.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
client_max_body_size 30M;
3 changes: 1 addition & 2 deletions .platform/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

client_max_body_size 100m;


log_format main '$remote_addr - $remote_user [$time_local] "$request" '
Expand Down Expand Up @@ -61,4 +60,4 @@ http {
# Include the Elastic Beanstalk generated locations
include conf.d/elasticbeanstalk/healthd.conf;
}
}
}
17 changes: 16 additions & 1 deletion src/main/java/com/example/runway/config/RedisConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.example.runway.config;

import io.lettuce.core.ClientOptions;
import io.lettuce.core.SocketOptions;
import lombok.extern.slf4j.Slf4j;
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -30,6 +33,7 @@

@Configuration
@EnableRedisRepositories
@Slf4j
public class RedisConfig {
private final Environment environment;

Expand All @@ -40,6 +44,9 @@ public class RedisConfig {
@Value("${spring.redis.port}")
private int port;

@Value("${spring.profiles.active}")
private String profile;

public RedisConfig(Environment environment) {
this.environment = environment;
}
Expand All @@ -57,7 +64,15 @@ public RedisConnectionFactory redisConnectionFactory() {
.connectTimeout(Duration.ofMillis(1000L)).build())
.build())
.commandTimeout(Duration.ofSeconds(1000L)).build();
return new LettuceConnectionFactory(clusterConfiguration, clientConfiguration);
log.info(profile);
if(profile.equals("prod")){
log.info("Prod profile");
return new LettuceConnectionFactory(clusterConfiguration, clientConfiguration);
}
else {
log.info("Dev profile");
return new LettuceConnectionFactory(host, port);
}
}

@Bean
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/com/example/runway/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import org.springframework.web.cors.CorsUtils;

@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
Expand Down Expand Up @@ -67,15 +67,19 @@ protected void configure(HttpSecurity httpSecurity) throws Exception {

.and()
.authorizeRequests()
.antMatchers("/swagger-resources/**").permitAll()
.requestMatchers(CorsUtils::isPreFlightRequest).permitAll()

.antMatchers("/swagger-resources/**").permitAll()
.antMatchers("/swagger-ui/**").permitAll()
.antMatchers("/webjars/**").permitAll()
.antMatchers("/v3/api-docs").permitAll()
.antMatchers("/test/img").permitAll()
.antMatchers("/login/**").permitAll()
.antMatchers("/health").permitAll()
.antMatchers("/admin").hasAnyRole("ADMIN")
.anyRequest().authenticated()
.antMatchers("/admin/user/logIn").permitAll()

.anyRequest().authenticated()

.and()
.apply(new JwtSecurityConfig(tokenProvider));
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/com/example/runway/config/WebConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.example.runway.config;

import java.util.concurrent.TimeUnit;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.CacheControl;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins(
"http://localhost:3000",
"http://localhost:8080",
"http://localhost:9000"
)
// 모든 HTTP Method를 허용한다.
.allowedMethods("*", "PUT", "POST", "DELETE", "OPTIONS", "PATCH", "GET")
// HTTP 요청의 Header에 어떤 값이든 들어갈 수 있도록 허용한다.
.allowedHeaders("*")
.exposedHeaders("Set-Cookie")
// 자격증명 사용을 허용한다.
// 해당 옵션 사용시 allowedOrigins를 * (전체)로 설정할 수 없다.
.allowCredentials(true);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public enum CommonResponseStatus {
USERS_EXISTS_SOCIAL_ID(BAD_REQUEST,"U024","중복된 소셜 ID 입니다."),

LIMIT_CERTIFICATE_SMS(BAD_REQUEST,"U025","해당 번호는 인증 횟수를 초과 하였습니다. 10분뒤에 시도해주세요"),
NOT_ADMIN(BAD_REQUEST,"U026","관리자만 접근 가능합니다."),

NOT_CORRECT_CONFIRM_NUM(BAD_REQUEST,"U026","인증번호가 일치하지 않습니다."),

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/example/runway/constants/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
public final class Constants {
public static final String kakao="KAKAO";
public static final String apple="APPLE";
public static final String FIRST_TIME = "T00:00:00";
public static final String LAST_TIME = "T23:59:59";
public static final List<String> CATEGORY=new ArrayList<>(){
{
add("페미닌");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,5 @@ public CommonResponse<String> scrapWebSite(@PathVariable Long storeId){
return CommonResponse.onSuccess("성공");
}

//@Operation(summary = "삭제")

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.example.runway.controller;

import javax.validation.constraints.Min;

import org.springframework.web.bind.annotation.GetMapping;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.runway.common.CommonResponse;
import com.example.runway.dto.PageResponse;
import com.example.runway.dto.user.UserReq;
import com.example.runway.dto.user.UserRes;
import com.example.runway.service.admin.auth.AdminAuthService;

import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/users")
public class AdminUserController {
private final AdminAuthService adminAuthService;

@PostMapping("/logIn")
public CommonResponse<UserRes.Token> logIn(@RequestBody UserReq.LoginUserInfo loginUserInfo) {
return CommonResponse.onSuccess(adminAuthService.logIn(loginUserInfo));
}

@GetMapping("/info")
public CommonResponse<UserRes.DashBoardDto> getUserDto(){
return CommonResponse.onSuccess(adminAuthService.getUserDto());
}

@GetMapping("")
public CommonResponse<PageResponse<UserRes.UserInfoDto>> getUserInfo(
@Parameter(description = "페이지", example = "0") @RequestParam(required = true) @Min(value = 0) Integer page,
@Parameter(description = "페이지 사이즈", example = "10") @RequestParam(required = true) Integer size){

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ public CommonResponse<UserRes.SignUp> signup(@ModelAttribute UserReq.SignupUser
log.info("post-signup");
log.info("api = signup 01-01");

System.out.println(signupUser.getCategoryList());

if(signupUser.getCategoryList()==null) throw new BadRequestException(CATEGORY_EMPTY_USERS);
if(signupUser.getPassword()==null) throw new BadRequestException(USERS_EMPTY_USER_PASSWORD);
if(signupUser.getPhone()==null) throw new BadRequestException(USERS_EMPTY_USER_ID);
Expand Down
33 changes: 12 additions & 21 deletions src/main/java/com/example/runway/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,32 +75,15 @@ public CommonResponse<String> logOut(@AuthenticationPrincipal User user){
log.info("api = logout 02-02");
//탈취된 토큰인지 검증
Long userId = user.getId();

//헤더에서 토큰 가져오기
String accessToken = tokenProvider.getJwt();
//jwt 에서 로그아웃 처리 & 오류처리 &

tokenProvider.logOut(userId,accessToken);
//TODO : FCM 설정 시 메소드 주석 삭제
//logInService.deleteFcmToken(userId);

userService.deleteFcmToken(user);
String result="로그아웃 성공";
return CommonResponse.onSuccess(result);
}

/*
// 토큰이 유효하다는 가정 하
// 만약 토큰이 만료되었다면 재발급 요청
@ApiOperation(value = "02-03 유저 위치 저장 👤", notes = "위치 저장 API")
@ResponseBody
@PostMapping("/location")
public CommonResponse<String> postUserLocation(@AuthenticationPrincipal User user, @RequestBody UserReq.UserLocation userLocation){
log.info("post-location");
log.info("api = post-location 02-03");
userService.postUserLocation(user,userLocation);
return CommonResponse.onSuccess("위치 정보 저장 성공");
}
*/

@ApiOperation(value = "02-03 마이페이지 조회(사장님 여부까지 포함) 👤 FRAME MY",notes = "마이페이지 조회")
@GetMapping("/")
Expand Down Expand Up @@ -129,7 +112,7 @@ public CommonResponse<UserRes.PatchUserInfo> getUserProfile(@AuthenticationPrinc

@ApiOperation(value = "02-05 프로필 편집 👤 FRAME MY",notes = "이미지 파일 변경할 경우 multipart 에 넣어주시고, 이미지 변경 안할 시 multipart null 값으로 보내주세영 아이디는 기존 아이디값+변경할 아이디값 둘중 하나 보내시면 됩니다")
@PatchMapping("/profile")
public CommonResponse<UserRes.ModifyUser> modifyUserProfile(@ModelAttribute UserReq.ModifyProfile modifyProfile,@AuthenticationPrincipal User user) throws IOException {
public CommonResponse<UserRes.ModifyUser> modifyUserProfile(@ModelAttribute UserReq.ModifyProfile modifyProfile, @AuthenticationPrincipal User user) throws IOException {
UserRes.ModifyUser modifyUser=userService.modifyUserProfile(user,modifyProfile);
return CommonResponse.onSuccess(modifyUser);
}
Expand Down Expand Up @@ -268,4 +251,12 @@ public CommonResponse<String> unActiveAppleUser(@AuthenticationPrincipal User us
authService.revoke(appleCode.getCode());
return CommonResponse.onSuccess("회원 탈퇴 완료");
}


@ApiOperation(value = "02-20 FCM 토큰 등록👤 ",notes = "FCM token 등록")
@PatchMapping("/fcm")
public CommonResponse<String> postFcmToken(@AuthenticationPrincipal User user, @RequestBody UserReq.FcmToken fcmToken ){
userService.postFcmToken(user, fcmToken);
return CommonResponse.onSuccess("회원 탈퇴 완료");
}
}
9 changes: 9 additions & 0 deletions src/main/java/com/example/runway/convertor/UserConvertor.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,13 @@ public static UserRes.SettingInfo SettingInfo(boolean kakao, boolean apple, Stri
public static Social SyncSocial(String socialId, Long userId, String social) {
return Social.builder().socialId(socialId).userId(userId).type(social).build();
}

public static UserRes.DashBoardDto ConvertUserSignUpInfo(Long oneDayUser, Long weekUser, Long monthUser, Long totalUser) {
return UserRes.DashBoardDto.builder()
.totalUserCnt(totalUser)
.oneDayUserCnt(oneDayUser)
.weekUserCnt(weekUser)
.monthUserCnt(monthUser)
.build();
}
}
4 changes: 1 addition & 3 deletions src/main/java/com/example/runway/domain/BaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,4 @@ public class BaseEntity {
@Column(name = "updated_at")
private LocalDateTime updatedAt;

}
// test
// test2
}
10 changes: 10 additions & 0 deletions src/main/java/com/example/runway/domain/enums/Category.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.runway.domain.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
@Getter
public enum Category {
미니멀, 캐주얼, 시티보이, 스트릿, 빈티지, 페미닌
}
10 changes: 10 additions & 0 deletions src/main/java/com/example/runway/dto/user/UserReq.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,14 @@ public static class AppleCode {
@ApiModelProperty(notes ="19 애플코드", required = true, example = "runway8925!")
private String code;
}

@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "02-20 FCM 토큰 저장 API Request🔑")
public static class FcmToken {
private String fcmToken;
}
}
21 changes: 21 additions & 0 deletions src/main/java/com/example/runway/dto/user/UserRes.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,25 @@ public static class ModifyUser {
private List<String> categoryList;

}


@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class DashBoardDto {
private Long totalUserCnt;
private Long oneDayUserCnt;
private Long weekUserCnt;
private Long monthUserCnt;
}

@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public static class UserInfoDto {
}
}
6 changes: 0 additions & 6 deletions src/main/java/com/example/runway/jwt/TokenProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,6 @@ public Authentication getAuthentication(String token) {
Long userId=claims.getBody().get("userId",Long.class);

Optional<User> users=userRepository.findById(userId);
String userName = users.get().getUsername();

System.out.println(users.get().getAuthorities());



return new UsernamePasswordAuthenticationToken(users.get(),"",users.get().getAuthorities());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.security.core.userdetails.UserDetails;

import java.time.LocalDateTime;
import java.util.Optional;


Expand Down Expand Up @@ -37,4 +38,8 @@ public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findByUsernameAndSocial(String valueOf, String kakao);

boolean existsByNickname(String nickname);

Long countBy();

Long countByCreatedAtGreaterThanAndCreatedAtLessThan(LocalDateTime parse, LocalDateTime parse1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.runway.service.admin.auth;

import com.example.runway.dto.user.UserReq;
import com.example.runway.dto.user.UserRes;

public interface AdminAuthService {
UserRes.Token logIn(UserReq.LoginUserInfo loginUserInfo);

UserRes.DashBoardDto getUserDto();
}
Loading

0 comments on commit 9ab5448

Please sign in to comment.