Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix #16

Merged
merged 6 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@
@RequestMapping("/admin")
@RequiredArgsConstructor
@Slf4j
@Tag(name = "관리자 기능")
@Tag(name = "관리자")
public class AdminController {

private final AdminServiceImpl adminService;

@Operation(summary = "회원 요청 목록 확인하기")
@Operation(summary = "요청 목록 확인")
@GetMapping("")
public ResponseEntity<ApiResponse<List<AdminCheckUserDto>>> checkUsers() {
List<AdminCheckUserDto> dtoList = adminService.checkUser();

return ResponseEntity.ok(ApiResponse.ok(dtoList));
}

@Operation(summary = "회원 요청 수락하기")
@Operation(summary = "회원요청 수락")
@PostMapping("/{id}")
public ResponseEntity<ApiResponse<Long>> registerUsers(@PathVariable("id") Long id) {
Long registerId = adminService.registerUsers(id);

return ResponseEntity.ok(ApiResponse.updated(registerId));
}

@Operation(summary = "회원 요청 거부하기")
@Operation(summary = "회원요청 거부")
@DeleteMapping("/{id}")
public ResponseEntity<ApiResponse<Long>> refuseUsers(@PathVariable("id") Long id) {
Long refusedId = adminService.refuseUsers(id);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/kr/tgwing/tech/admin/dto/AdminCheckUserDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
@NoArgsConstructor
@AllArgsConstructor
public class AdminCheckUserDto {
private Long id;
private String studentId;
private Long studentId;
private String studentNumber;
private String email;
private String name;
private String phoneNumber;
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/kr/tgwing/tech/admin/service/AdminServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ public List<AdminCheckUserDto> checkUser() {
}

@Transactional
public Long registerUsers(Long id) {
TempUser notUser = tempUserRepository.findById(id).orElseThrow(UserNotFoundException::new);
public Long registerUsers(Long studentId) {
TempUser notUser = tempUserRepository.findById(studentId).orElseThrow(UserNotFoundException::new);
User user = notUser.toUser(notUser);
tempUserRepository.deleteById(id);
tempUserRepository.deleteById(studentId);

user.setRole("ROLE_USER");
userRepository.save(user);

return user.getId();
return user.getStudentId();
}

public Long refuseUsers(Long id) {
TempUser user = tempUserRepository.findById(id).orElseThrow(UserNotFoundException::new);
userRepository.deleteById(user.getId());
public Long refuseUsers(Long studentId) {
TempUser user = tempUserRepository.findById(studentId).orElseThrow(UserNotFoundException::new);
userRepository.deleteById(user.getStudentId());

return user.getId();
return user.getStudentId();
}
}
10 changes: 8 additions & 2 deletions src/main/java/kr/tgwing/tech/blog/entity/HashTagEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@
@Table(name = "hashtag")
public class HashTagEntity {

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

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

// @Column(name = "creator_id")
// @JoinColumn(referencedColumnName = "student_id", table = "student")
// private Long creatorId;

@OneToMany(mappedBy = "hashtag")
@Builder.Default
private Set<PostTagEntity> postTags = new HashSet<>();
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/kr/tgwing/tech/blog/entity/PostEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Table(name="post")
@Table(name="blog")
public class PostEntity extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@JoinColumn(referencedColumnName = "id", table = "user")
@JoinColumn(referencedColumnName = "student_id", table = "student")
private Long writer;
@Column(nullable = false)
private String title;
@Column(nullable = false)
private String content;

@Column(name = "thumbnail_url")
private String thumbnail;
private int replyCount;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@AllArgsConstructor
@Builder
@IdClass(PostTagId.class)
@Table(name = "post_hashtag")
@Table(name = "blog_hashtag")
public class PostTagEntity extends BaseEntity {

@Id
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/kr/tgwing/tech/blog/entity/ReplyEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "reply")
@Table(name = "blog_comment_reply")
public class ReplyEntity extends BaseEntity {

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ private Page<PostEntity> getAllPosts(PageRequest pageRequest) { // 모든 공지
}

@Override
public PostDto createPost(PostCreationDto requestDto, String utilStudentId) // 공지 생성하기
public PostDto createPost(PostCreationDto requestDto, String studentNumber) // 공지 생성하기
{
// 글을 작성할 user 조회
Optional<User> byStudentId = userRepository.findByStudentId(utilStudentId);
Optional<User> byStudentId = userRepository.findByStudentNumber(studentNumber);
User userEntity = byStudentId.orElseThrow(UserNotFoundException::new);

// 현재 사용자와 요청 시 들어온 writer가 같은지 확인
if (!Objects.equals(userEntity.getStudentId(), utilStudentId)) {
if (!Objects.equals(userEntity.getStudentId(), studentNumber)) {
throw new WrongPostRequestException();
}

Expand All @@ -89,7 +89,7 @@ public PostDto createPost(PostCreationDto requestDto, String utilStudentId) //
//getHashtag - 요청으로 들어온 해시태그 집합을 데이터베이스에 블로그 연관 테이블, 해시태그 테이블에 저장 및 엔티티 집합 반환
Set<HashTagEntity> hashtags = getHashtag(requestDto.getHashtags());
PostEntity postEntity = PostCreationDto.toEntity(requestDto);
postEntity.setWriter(userEntity.getId());
postEntity.setWriter(userEntity.getStudentId());
PostEntity savedEntity = postRepository.save(postEntity);

hashtags.forEach(tag -> {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/kr/tgwing/tech/common/BaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
public abstract class BaseEntity {

@CreatedDate
@Column(name = "regdate", updatable = false)
@Column(name = "created_at", updatable = false)
private LocalDateTime regDate;

@LastModifiedDate
@Column(name ="moddate" )
@Column(name ="updated_at")
private LocalDateTime modDate;

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import kr.tgwing.tech.blog.exception.reply.ReplyBadRequestException;
import kr.tgwing.tech.blog.exception.reply.ReplyForbiddenException;
import kr.tgwing.tech.blog.exception.reply.ReplyNotFoundException;
import kr.tgwing.tech.project.exception.ProjectNotFoundException;
import kr.tgwing.tech.user.exception.*;
import org.springframework.http.HttpStatus;

Expand All @@ -18,6 +19,7 @@ public class ExceptionMapper { // 예외 객체 -> 예외 상태로 바꿔주는
setUpUserException();
setUpPostException();
setUpReplyException();
setUpProjectException();
// setUpReplyException();
}

Expand Down Expand Up @@ -58,6 +60,11 @@ private static void setUpReplyException() {
ExceptionSituation.of("요청한 사용자에게 권한이 없습니다.", HttpStatus.FORBIDDEN, 5502));
}

private static void setUpProjectException() {
mapper.put(ProjectNotFoundException.class,
ExceptionSituation.of("찾고자 하는 프로젝트가 존재하지 않습니다.", HttpStatus.NOT_FOUND, 6600));
}


public static ExceptionSituation getSituationOf(Exception exception) {
return mapper.get(exception.getClass());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kr.tgwing.tech.common;
package kr.tgwing.tech.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.EnableCaching;
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/kr/tgwing/tech/config/TestDataLoader.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kr.tgwing.tech.config;

import java.sql.Date;
import java.time.LocalDate;

import kr.tgwing.tech.user.dto.registerdto.UserDTO;
import org.springframework.boot.CommandLineRunner;
Expand All @@ -26,20 +27,20 @@ public CommandLineRunner loadTestData(UserService userService,
ReplyRepository replyRepository) {
return args -> {
userService.register(UserDTO.builder()
.studentId("2018000000")
.studentNumber("2018000000")
.phoneNumber("01000000000")
.email("[email protected]")
.name("늙은이")
.password("12345678")
.birth(Date.valueOf("1999-01-01"))
.birth(LocalDate.parse("1999-01-01"))
.build());
userService.register(UserDTO.builder()
.studentId("2022000000")
.studentNumber("2022000000")
.phoneNumber("01011111111")
.email("[email protected]")
.name("젊은이")
.password("12345678")
.birth(Date.valueOf("2003-01-01"))
.birth(LocalDate.parse("2003-01-01"))
.build());
postRepository.save(PostEntity.builder()
.writer(1L)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package kr.tgwing.tech.project.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import kr.tgwing.tech.common.ApiResponse;
import kr.tgwing.tech.project.dto.ProjectBriefDTO;
import kr.tgwing.tech.project.dto.ProjectCreateDTO;
import kr.tgwing.tech.project.dto.ProjectDetailDTO;
import kr.tgwing.tech.project.dto.ProjectUpdateDTO;
import kr.tgwing.tech.project.exception.BadRequestException;
import kr.tgwing.tech.project.exception.NotFoundException;
import kr.tgwing.tech.project.service.ProjectServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -16,50 +17,49 @@

import java.util.List;

@Tag(name = "프로젝트")
@RestController
@RequiredArgsConstructor
@RequestMapping("/project")
@Slf4j
public class ProjectController {
private final ProjectServiceImpl projectServiceImpl;

@GetMapping("/projects")
@Operation(summary = "프로젝트 전체 조회")
@GetMapping("")
public ResponseEntity<?> getProjects(){
List<ProjectBriefDTO> projects = projectServiceImpl.getProjects();
return ResponseEntity.ok(projects);
return ResponseEntity.ok(ApiResponse.ok(projects));
}

@GetMapping("/projects/{project_id}")
public ResponseEntity<?> getOneProject(@PathVariable("project_id") Long project_id) throws NotFoundException{
@Operation(summary = "프로젝트 상세 조회")
@GetMapping("/{project_id}")
public ResponseEntity<?> getOneProject(@PathVariable("project_id") Long project_id){
ProjectDetailDTO project = projectServiceImpl.getOneProject(project_id);
if(project == null){
throw new NotFoundException("개별 프로젝트 가져오기 - 찾을 수 없음");
}
return ResponseEntity.ok(project);
}

return ResponseEntity.ok(ApiResponse.ok(project));
}

@PostMapping("/projects")
public ResponseEntity<?> postProject(@Valid @RequestBody ProjectCreateDTO projectCreateDTO, BindingResult bindingResult) throws BadRequestException {
if(bindingResult.hasErrors()){
throw new BadRequestException("프로젝트 생성 - 잘못된 정보 입력");
}
@Operation(summary = "프로젝트 생성")
@PostMapping("")
public ResponseEntity<?> postProject(
@Valid @RequestBody ProjectCreateDTO projectCreateDTO) {
Long projectId = projectServiceImpl.createProjects(projectCreateDTO);
return ResponseEntity.ok(projectId);
return ResponseEntity.ok(ApiResponse.created(projectId));
}

@PutMapping("/projects/{project_id}")
public ResponseEntity<?> updateProject(@PathVariable("project_id") Long project_id, @Valid @RequestBody ProjectUpdateDTO projectUpdateDTO, BindingResult bindingResult) throws NotFoundException, BadRequestException{
if(bindingResult.hasErrors()){
throw new BadRequestException("프로젝트 수정 - 잘못된 정보 입력");
}
@Operation(summary = "프로젝트 수정")
@PutMapping("/{project_id}")
public ResponseEntity<?> updateProject(
@PathVariable("project_id") Long project_id,
@Valid @RequestBody ProjectUpdateDTO projectUpdateDTO){
Long projectId = projectServiceImpl.updateProject(projectUpdateDTO, project_id);
return ResponseEntity.ok(projectId);
return ResponseEntity.ok(ApiResponse.updated(projectId));
}

@DeleteMapping("/projects/{project_id}")
@Operation(summary = "프로젝트 삭제")
@DeleteMapping("/{project_id}")
public ResponseEntity<?> deleteProject(@PathVariable("project_id") Long project_id){
projectServiceImpl.deleteProject(project_id);
return ResponseEntity.ok("delete ok");
return ResponseEntity.ok(ApiResponse.delete(project_id));
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package kr.tgwing.tech.project.domain.Enum;

public enum DevRole {
public enum Part {
LEADER("LEADER"),
PM("PM"),
FRONT("FRONT"),
Expand All @@ -9,7 +9,7 @@ public enum DevRole {

private String value;

DevRole(String value) {
Part(String value) {
this.value = value;
}
}
Loading