Skip to content

Commit

Permalink
Merge pull request #80 from 28th-meetup/eckrin/fixup
Browse files Browse the repository at this point in the history
feat: 이벤트 관련 기능 추가
  • Loading branch information
eckrin authored May 7, 2024
2 parents 5c5021e + 7bdcb45 commit a28a6af
Show file tree
Hide file tree
Showing 38 changed files with 873 additions and 18 deletions.
Binary file modified .DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
//spring security
implementation 'org.springframework.boot:spring-boot-starter-security'
// spring batch
implementation 'org.springframework.boot:spring-boot-starter-batch'
//aop
implementation 'org.springframework.boot:spring-boot-starter-aop'
//jwt
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
implementation 'io.jsonwebtoken:jjwt-impl:0.11.5'
Expand All @@ -61,6 +65,8 @@ dependencies {
//lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor 'org.projectlombok:lombok'
//queryDsl
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
annotationProcessor 'com.querydsl:querydsl-apt:5.0.0:jakarta'
Expand All @@ -74,6 +80,8 @@ dependencies {
testImplementation 'org.springframework.boot:spring-boot-starter-test'
//firebase
implementation 'com.google.firebase:firebase-admin:9.1.1'
// test h2 database
testRuntimeOnly 'com.h2database:h2'
}

tasks.named('test') {
Expand Down
Binary file modified src/.DS_Store
Binary file not shown.
64 changes: 64 additions & 0 deletions src/main/generated/com/kusitms/jipbap/event/aop/QEventLog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.kusitms.jipbap.event.aop;

import static com.querydsl.core.types.PathMetadataFactory.*;

import com.querydsl.core.types.dsl.*;

import com.querydsl.core.types.PathMetadata;
import javax.annotation.processing.Generated;
import com.querydsl.core.types.Path;
import com.querydsl.core.types.dsl.PathInits;


/**
* QEventLog is a Querydsl query type for EventLog
*/
@Generated("com.querydsl.codegen.DefaultEntitySerializer")
public class QEventLog extends EntityPathBase<EventLog> {

private static final long serialVersionUID = 1535997623L;

private static final PathInits INITS = PathInits.DIRECT2;

public static final QEventLog eventLog = new QEventLog("eventLog");

public final com.kusitms.jipbap.common.entity.QDateEntity _super = new com.kusitms.jipbap.common.entity.QDateEntity(this);

public final EnumPath<Action> action = createEnum("action", Action.class);

//inherited
public final DateTimePath<java.time.LocalDateTime> createdAt = _super.createdAt;

public final com.kusitms.jipbap.event.model.entity.QEvent event;

public final NumberPath<Long> id = createNumber("id", Long.class);

//inherited
public final DateTimePath<java.time.LocalDateTime> updatedAt = _super.updatedAt;

public final com.kusitms.jipbap.user.model.entity.QUser user;

public QEventLog(String variable) {
this(EventLog.class, forVariable(variable), INITS);
}

public QEventLog(Path<? extends EventLog> path) {
this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS));
}

public QEventLog(PathMetadata metadata) {
this(metadata, PathInits.getFor(metadata, INITS));
}

public QEventLog(PathMetadata metadata, PathInits inits) {
this(EventLog.class, metadata, inits);
}

public QEventLog(Class<? extends EventLog> type, PathMetadata metadata, PathInits inits) {
super(type, metadata, inits);
this.event = inits.isInitialized("event") ? new com.kusitms.jipbap.event.model.entity.QEvent(forProperty("event"), inits.get("event")) : null;
this.user = inits.isInitialized("user") ? new com.kusitms.jipbap.user.model.entity.QUser(forProperty("user"), inits.get("user")) : null;
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.kusitms.jipbap.event.model.entity;

import static com.querydsl.core.types.PathMetadataFactory.*;

import com.querydsl.core.types.dsl.*;

import com.querydsl.core.types.PathMetadata;
import javax.annotation.processing.Generated;
import com.querydsl.core.types.Path;
import com.querydsl.core.types.dsl.PathInits;


/**
* QEvent is a Querydsl query type for Event
*/
@Generated("com.querydsl.codegen.DefaultEntitySerializer")
public class QEvent extends EntityPathBase<Event> {

private static final long serialVersionUID = -778155915L;

private static final PathInits INITS = PathInits.DIRECT2;

public static final QEvent event = new QEvent("event");

public final com.kusitms.jipbap.common.entity.QDateEntity _super = new com.kusitms.jipbap.common.entity.QDateEntity(this);

public final com.kusitms.jipbap.user.model.entity.QUser admin;

public final NumberPath<Long> amount = createNumber("amount", Long.class);

//inherited
public final DateTimePath<java.time.LocalDateTime> createdAt = _super.createdAt;

public final StringPath description = createString("description");

public final NumberPath<Long> id = createNumber("id", Long.class);

public final StringPath title = createString("title");

//inherited
public final DateTimePath<java.time.LocalDateTime> updatedAt = _super.updatedAt;

public QEvent(String variable) {
this(Event.class, forVariable(variable), INITS);
}

public QEvent(Path<? extends Event> path) {
this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS));
}

public QEvent(PathMetadata metadata) {
this(metadata, PathInits.getFor(metadata, INITS));
}

public QEvent(PathMetadata metadata, PathInits inits) {
this(Event.class, metadata, inits);
}

public QEvent(Class<? extends Event> type, PathMetadata metadata, PathInits inits) {
super(type, metadata, inits);
this.admin = inits.isInitialized("admin") ? new com.kusitms.jipbap.user.model.entity.QUser(forProperty("admin"), inits.get("admin")) : null;
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.kusitms.jipbap.event.model.entity;

import static com.querydsl.core.types.PathMetadataFactory.*;

import com.querydsl.core.types.dsl.*;

import com.querydsl.core.types.PathMetadata;
import javax.annotation.processing.Generated;
import com.querydsl.core.types.Path;
import com.querydsl.core.types.dsl.PathInits;


/**
* QEventUser is a Querydsl query type for EventUser
*/
@Generated("com.querydsl.codegen.DefaultEntitySerializer")
public class QEventUser extends EntityPathBase<EventUser> {

private static final long serialVersionUID = -808229408L;

private static final PathInits INITS = PathInits.DIRECT2;

public static final QEventUser eventUser = new QEventUser("eventUser");

public final com.kusitms.jipbap.common.entity.QDateEntity _super = new com.kusitms.jipbap.common.entity.QDateEntity(this);

//inherited
public final DateTimePath<java.time.LocalDateTime> createdAt = _super.createdAt;

public final QEvent event;

public final NumberPath<Long> id = createNumber("id", Long.class);

//inherited
public final DateTimePath<java.time.LocalDateTime> updatedAt = _super.updatedAt;

public final com.kusitms.jipbap.user.model.entity.QUser user;

public QEventUser(String variable) {
this(EventUser.class, forVariable(variable), INITS);
}

public QEventUser(Path<? extends EventUser> path) {
this(path.getType(), path.getMetadata(), PathInits.getFor(path.getMetadata(), INITS));
}

public QEventUser(PathMetadata metadata) {
this(metadata, PathInits.getFor(metadata, INITS));
}

public QEventUser(PathMetadata metadata, PathInits inits) {
this(EventUser.class, metadata, inits);
}

public QEventUser(Class<? extends EventUser> type, PathMetadata metadata, PathInits inits) {
super(type, metadata, inits);
this.event = inits.isInitialized("event") ? new QEvent(forProperty("event"), inits.get("event")) : null;
this.user = inits.isInitialized("user") ? new com.kusitms.jipbap.user.model.entity.QUser(forProperty("user"), inits.get("user")) : null;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,11 @@ public CommonResponse<String> checkNicknameIsDuplicate(@RequestBody NicknameVali
return new CommonResponse<>(authService.checkNicknameIsDuplicate(dto.getNickname()));
}

@Operation(summary = "(테스트용 임시) 관리자 등록")
@PostMapping("/admin/signup")
@ResponseStatus(HttpStatus.OK)
public CommonResponse<String> adminSignUp(@RequestBody Long id) {
return new CommonResponse<>(authService.createTmpAdmin(id));
}

}
21 changes: 20 additions & 1 deletion src/main/java/com/kusitms/jipbap/auth/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import com.kusitms.jipbap.auth.exception.*;
import com.kusitms.jipbap.security.jwt.JwtTokenProvider;
import com.kusitms.jipbap.security.jwt.TokenInfo;
import com.kusitms.jipbap.user.exception.UserNotFoundException;
import com.kusitms.jipbap.user.model.entity.CountryPhoneCode;
import com.kusitms.jipbap.user.model.entity.Role;
import com.kusitms.jipbap.user.model.entity.User;
import com.kusitms.jipbap.user.repository.UserRepository;
import com.kusitms.jipbap.user.exception.UserNotFoundException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
Expand Down Expand Up @@ -167,4 +167,23 @@ public String checkNicknameIsDuplicate(String nickname){
if(userRepository.existsByUsername(nickname)) throw new UsernameExistsException("이미 존재하는 닉네임입니다.");
return "사용 가능한 닉네임입니다.";
}

@Transactional
public String createTmpAdmin(Long id) {
if(userRepository.existsByEmail("admin"+id+"@email.com")) throw new EmailExistsException("이미 존재하는 어드민 이메일 id입니다");
User user = userRepository.save(
User.builder()
.id(null)
.email("admin"+id+"@email.com")
.password(passwordEncoder.encode("qwe123"))
.username("admin"+System.currentTimeMillis())
.countryPhoneCode(null)
.phoneNum(null)
.role(Role.ROLE_ADMIN)
.refreshToken(null)
.oauth(INAPP)
.build()
);
return user.getEmail();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public enum ErrorCode {
UNAUTHORIZED_ACCESS_ERROR(false, HttpStatus.BAD_REQUEST.value(), "해당 주문에 접근할 권한이 없습니다."),
ORDER_STATUS_ALREADY_EXISTS_ERROR(false, HttpStatus.BAD_REQUEST.value(), "이미 해당 주문 상태입니다."),
ALREADY_EXISTS_REVIEW_ERROR(false, HttpStatus.BAD_REQUEST.value(), "이미 리뷰를 작성한 주문입니다."),

//event
EVENT_NOT_EXISTS_ERROR(false, HttpStatus.BAD_REQUEST.value(), "존재하지 않는 이벤트입니다."),
EVENT_EXHAUST_ERROR(false, HttpStatus.BAD_REQUEST.value(), "이벤트 쿠폰이 모두 소진되었습니다."),
ALREADY_EXISTS_USER_EVENT_ERROR(false, HttpStatus.BAD_REQUEST.value(), "이미 이벤트 쿠폰을 발급한 유저입니다."),
;

private Boolean isSuccess;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.authorizeHttpRequests(authorize ->
authorize
.requestMatchers(HttpMethod.OPTIONS, "/**").permitAll() //cors
.requestMatchers("/auth/**").permitAll() // 로그인 필요 X
.requestMatchers("/test/**").permitAll() // anonymousUser 테스트
.requestMatchers(HttpMethod.PUT, "/event").hasRole("ADMIN")
.requestMatchers(HttpMethod.POST, "/event").hasAuthority("USER") // ROLE_로 시작하지 않기 떄문에 hasAuthority함수 사용
.anyRequest().authenticated()
)
.addFilterAfter(new JwtAuthenticationFilter(tokenProvider), UsernamePasswordAuthenticationFilter.class)
Expand All @@ -63,7 +67,6 @@ public WebSecurityCustomizer webSecurityCustomizer() {
"/swagger-ui/**",
"/swagger/**",
"/error",
"/auth/**",
"/ws/**", //ws://localhost:8080/ws/chat
"/ws-stomp/**",
"/addresses/**"
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/kusitms/jipbap/event/aop/Action.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.kusitms.jipbap.event.aop;

public enum Action {
REGISTER, ENTER
}
33 changes: 33 additions & 0 deletions src/main/java/com/kusitms/jipbap/event/aop/EventLog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.kusitms.jipbap.event.aop;

import com.kusitms.jipbap.common.entity.DateEntity;
import com.kusitms.jipbap.event.model.entity.Event;
import com.kusitms.jipbap.user.model.entity.User;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Table(name = "tb_eventlog")
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class EventLog extends DateEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne
@JoinColumn(name = "event_id")
private Event event;

@ManyToOne
@JoinColumn(name = "user_id")
private User user;

@Enumerated(EnumType.STRING)
private Action action; // REGISTER, ENTER

}
Loading

0 comments on commit a28a6af

Please sign in to comment.