Skip to content
This repository has been archived by the owner on Jan 20, 2025. It is now read-only.

Commit

Permalink
Merge pull request #201 from themoment-team/develop
Browse files Browse the repository at this point in the history
Develop - 2021. Sep. 21
  • Loading branch information
siwony authored Sep 21, 2021
2 parents 29137d1 + 10ba872 commit 9c223fc
Show file tree
Hide file tree
Showing 34 changed files with 336 additions and 372 deletions.
27 changes: 3 additions & 24 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ plugins {
id 'java'
id 'org.springframework.boot' version '2.4.2'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id "com.ewerk.gradle.plugins.querydsl" version '1.0.10'
id 'jacoco'
}

Expand Down Expand Up @@ -59,10 +58,6 @@ dependencies {
runtimeOnly 'com.h2database:h2'
runtimeOnly 'mysql:mysql-connector-java'

// QueryDSL
compileOnly 'com.querydsl:querydsl-jpa'
compileOnly 'com.querydsl:querydsl-apt'

testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'org.junit.jupiter:junit-jupiter-params'
Expand Down Expand Up @@ -96,9 +91,9 @@ jacoco {

jacocoTestReport {
reports {
html.enabled true
csv.enabled false
xml.enabled false
html.required = true
csv.required = false
xml.required = false
}
afterEvaluate {
classDirectories.from = files(classDirectories.files.collect {
Expand Down Expand Up @@ -137,20 +132,4 @@ jacocoTestCoverageVerification {

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

def querydslDir = "$buildDir/generated/querydsl"

querydsl {
jpa = true
querydslSourcesDir = querydslDir
}
sourceSets {
main.java.srcDir querydslDir
}
configurations {
querydsl.extendsFrom compileClasspath
}
compileQuerydsl {
options.annotationProcessorPath = configurations.querydsl
}
29 changes: 13 additions & 16 deletions src/main/java/com/moment/the/admin/AdminDomain.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.moment.the.admin;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
Expand All @@ -15,23 +12,23 @@
import java.util.List;
import java.util.stream.Collectors;

@Entity
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity @Table(name = "admin")
@Getter @Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor
public class AdminDomain implements UserDetails {

@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "admin_id")
private Long adminIdx;

@Column(name = "name")
private String adminName;

@Column(name = "email")
private String adminId;
private String email;

@Column(name = "name")
private String name;

@Column(name = "password")
private String adminPwd;
private String password;

@ElementCollection(fetch = FetchType.EAGER)
@Builder.Default
Expand All @@ -46,13 +43,13 @@ public Collection<? extends GrantedAuthority> getAuthorities() {
@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
@Override
public String getPassword() {
return this.adminPwd;
return this.password;
}

@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
@Override
public String getUsername() {
return this.adminId;
return this.email;
}

@JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class AdminController {

@PostMapping("/login")
public SingleResult<Map<String, String>> login(@Valid @RequestBody SignInDto signInDto) throws Exception {
return responseService.getSingleResult(adminService.loginUser(signInDto.getAdminId(), signInDto.getAdminPwd()));
return responseService.getSingleResult(adminService.login(signInDto.getEmail(), signInDto.getPassword()));
}

@PostMapping("/logout")
Expand All @@ -43,9 +43,9 @@ public CommonResult logout(){
return responseService.getSuccessResult();
}

@PostMapping("/signup")
public CommonResult signup(@Valid @RequestBody AdminDto adminDto) throws Exception {
adminService.signUp(adminDto);
@PostMapping("/join")
public CommonResult join(@Valid @RequestBody AdminDto adminDto) throws Exception {
adminService.join(adminDto);
return responseService.getSuccessResult();
}

Expand Down
22 changes: 10 additions & 12 deletions src/main/java/com/moment/the/admin/dto/AdminDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,25 @@
import javax.validation.constraints.Size;
import java.util.Collections;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Getter @Setter
@NoArgsConstructor @AllArgsConstructor
public class AdminDto {
@Email(message = "Email should be valid")
@NotBlank(message = "id should be valid")
private String adminId;
@Email(message = "email should be valid")
@NotBlank(message = "email should be valid")
private String email;

@NotBlank(message = "password should be valid")
private String adminPwd;
private String password;

@NotBlank(message = "name should be valid")
@Size(min = 3, max = 30)
private String adminName;
private String name;

public AdminDomain toEntity() {
return AdminDomain.builder()
.adminId(this.getAdminId())
.adminPwd(this.getAdminPwd())
.adminName(this.getAdminName())
.email(this.email)
.password(this.password)
.name(this.name)
.roles(Collections.singletonList("ROLE_ADMIN"))
.build();
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/moment/the/admin/dto/SignInDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
@NoArgsConstructor
public class SignInDto {
@NotBlank(message = "id should be valid")
private String adminId;
private String email;
@NotBlank(message = "password should be valid")
private String adminPwd;
private String password;

public AdminDomain toEntity(){
return AdminDomain.builder()
.adminId(this.adminId)
.adminPwd(this.adminPwd)
.email(this.email)
.password(this.password)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@

@Repository
public interface AdminRepository extends JpaRepository<AdminDomain, Long> {
AdminDomain findByAdminId(String adminId);
AdminDomain findByAdminIdAndAdminPwd(String adminId, String password);
AdminDomain findByEmail(String email);
AdminDomain findByEmailAndPassword(String email, String password);
}
4 changes: 2 additions & 2 deletions src/main/java/com/moment/the/admin/service/AdminService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import java.util.Map;

public interface AdminService {
void signUp(AdminDto adminDto) throws Exception;
Map<String, String> loginUser(String id, String password) throws Exception;
void join(AdminDto adminDto) throws Exception;
Map<String, String> login(String id, String password) throws Exception;
void logout();
void withdrawal(SignInDto SignInDto) throws Exception;
}
20 changes: 10 additions & 10 deletions src/main/java/com/moment/the/admin/service/AdminServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,29 @@ public class AdminServiceImpl implements AdminService {
private final JwtUtil jwtUtil;

@Override
public void signUp(AdminDto adminDto) {
if(adminRepository.findByAdminId(adminDto.getAdminId()) != null){
public void join(AdminDto adminDto) {
if(adminRepository.findByEmail(adminDto.getEmail()) != null){
throw new UserAlreadyExistsException();
}
adminDto.setAdminPwd(passwordEncoder.encode(adminDto.getAdminPwd()));
adminDto.setPassword(passwordEncoder.encode(adminDto.getPassword()));
adminRepository.save(adminDto.toEntity());
}

@Override
public Map<String, String> loginUser(String id, String password) {
public Map<String, String> login(String id, String password) {
// 아이디 검증
AdminDomain adminDomain = adminRepository.findByAdminId(id);
AdminDomain adminDomain = adminRepository.findByEmail(id);
if (adminDomain == null) throw new UserNotFoundException();
// 비밀번호 검증
boolean passwordCheck = passwordEncoder.matches(password, adminDomain.getPassword());
if (!passwordCheck) throw new UserNotFoundException();

final String accessToken = jwtUtil.generateAccessToken(adminDomain.getAdminId());
final String refreshJwt = jwtUtil.generateRefreshToken(adminDomain.getAdminId());
final String accessToken = jwtUtil.generateAccessToken(adminDomain.getEmail());
final String refreshJwt = jwtUtil.generateRefreshToken(adminDomain.getEmail());
// token 만료 기간 설정
redisUtil.setDataExpire(refreshJwt, adminDomain.getUsername(), JwtUtil.REFRESH_TOKEN_EXPIRATION_TIME);
Map<String ,String> map = new HashMap<>();
map.put("id", adminDomain.getAdminId());
map.put("id", adminDomain.getEmail());
map.put("accessToken", accessToken); // accessToken 반환
map.put("refreshToken", refreshJwt); // refreshToken 반환

Expand All @@ -67,8 +67,8 @@ public void logout() {
@Override
public void withdrawal(SignInDto signInDto) throws Exception {
// 로그인 된 이메일과 내가 삭제하려는 이메일이 같을 때.
if (getUserEmail().equals(signInDto.getAdminId())) {
AdminDomain adminDomain = adminRepository.findByAdminId(signInDto.getAdminId());
if (getUserEmail().equals(signInDto.getEmail())) {
AdminDomain adminDomain = adminRepository.findByEmail(signInDto.getEmail());
adminRepository.delete(adminDomain);
} else {
throw new Exception("로그인 후 이용해주세요.");
Expand Down
44 changes: 17 additions & 27 deletions src/main/java/com/moment/the/answer/AnswerDomain.java
Original file line number Diff line number Diff line change
@@ -1,51 +1,41 @@
package com.moment.the.answer;



import com.moment.the.admin.AdminDomain;
import com.moment.the.answer.dto.AnswerDto;
import com.moment.the.uncomfortable.UncomfortableEntity;
import com.sun.istack.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import com.moment.the.uncomfortable.UncomfortableDomain;
import lombok.*;

import javax.persistence.*;

import static javax.persistence.FetchType.*;

@Table(name = "Answer")
@Entity
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity @Table(name = "answer")
@Getter @Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED) @AllArgsConstructor
public class AnswerDomain {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "answer_id")
private Long answerIdx;

@Column(length = 1000, nullable = false)
@NotNull
private String answerContent;
@Column(name = "content", length = 1000, nullable = false)
private String content;

@OneToOne(mappedBy = "answerDomain", fetch = LAZY)
@JoinColumn(name = "boardIdx", nullable = false)
private UncomfortableEntity uncomfortableEntity;
@OneToOne(fetch = LAZY)
@JoinColumn(name = "uncomfortable_id", nullable = false)
private UncomfortableDomain uncomfortableDomain;

@ManyToOne(fetch = LAZY)
@JoinColumn(name="writer", nullable = false)
@JoinColumn(name="writer_admin_id", nullable = false)
private AdminDomain adminDomain;

// dirty checking.
public void update(AnswerDto answerDto) {
this.answerContent = answerDto.getContent();
this.content = answerDto.getContent();
}

public void updateTableDomain(UncomfortableEntity uncomfortableEntity){
this.uncomfortableEntity = uncomfortableEntity;
this.uncomfortableEntity.updateAnswerDomain(this);
public void updateTableDomain(UncomfortableDomain uncomfortableDomain){
this.uncomfortableDomain = uncomfortableDomain;
this.uncomfortableDomain.updateAnswerDomain(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


@RestController
@RequestMapping("/v1/top10")
@RequestMapping("/v1/rank")
@RequiredArgsConstructor
public class AnswerController {
private final AnswerService answerService;
Expand All @@ -25,8 +25,8 @@ public class AnswerController {
@ApiImplicitParam(name = "Authorization", value = "로그인 성공 후 access_token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "RefreshToken", value = "로그인 성공 후 refresh_token", required = false, dataType = "String", paramType = "header")
})
public CommonResult save(@RequestBody AnswerDto answerDto, @PathVariable Long boardIdx) throws Exception {
answerService.save(answerDto, boardIdx);
public CommonResult createThisAnswer(@RequestBody AnswerDto answerDto, @PathVariable Long boardIdx) {
answerService.createThisAnswer(answerDto, boardIdx);
return responseService.getSuccessResult();
}

Expand All @@ -35,23 +35,23 @@ public CommonResult save(@RequestBody AnswerDto answerDto, @PathVariable Long bo
@ApiImplicitParam(name = "Authorization", value = "로그인 성공 후 access_token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "RefreshToken", value = "로그인 성공 후 refresh_token", required = false, dataType = "String", paramType = "header")
})
public CommonResult update(@RequestBody AnswerDto answerDto, @PathVariable Long answerIdx) throws Exception {
answerService.update(answerDto, answerIdx);
public CommonResult updateThisAnswer(@RequestBody AnswerDto answerDto, @PathVariable Long answerIdx) {
answerService.updateThisAnswer(answerDto, answerIdx);
return responseService.getSuccessResult();
}

@GetMapping("/answer/{boardIdx}")
public SingleResult<AnswerResDto> view(@PathVariable Long boardIdx) throws Exception{
return responseService.getSingleResult(answerService.view(boardIdx));
public SingleResult<AnswerResDto> getThisAnswer(@PathVariable Long boardIdx) {
return responseService.getSingleResult(answerService.getThisAnswer(boardIdx));
}

@DeleteMapping("/answer/{answerIdx}")
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "로그인 성공 후 access_token", required = true, dataType = "String", paramType = "header"),
@ApiImplicitParam(name = "RefreshToken", value = "로그인 성공 후 refresh_token", required = false, dataType = "String", paramType = "header")
})
public CommonResult delete(@PathVariable Long answerIdx) throws Exception {
answerService.delete(answerIdx);
public CommonResult deleteThisAnswer(@PathVariable Long answerIdx) {
answerService.deleteThisAnswer(answerIdx);
return responseService.getSuccessResult();
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/moment/the/answer/dto/AnswerDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class AnswerDto {

public AnswerDomain toEntity(){
return AnswerDomain.builder()
.answerContent(this.content)
.content(this.content)
.adminDomain(this.adminDomain)
.build();
}
Expand Down
Loading

0 comments on commit 9c223fc

Please sign in to comment.