Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/sunoWeek6' into weekly
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/team1/BE/seamless/repository/ProjectRepository.java
#	src/main/java/team1/BE/seamless/repository/UserRepository.java
#	src/main/java/team1/BE/seamless/util/auth/SecurityConfig.java
  • Loading branch information
Kdonghs committed Oct 11, 2024
2 parents 0da636e + c952ced commit ece7790
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 79 deletions.
35 changes: 34 additions & 1 deletion src/main/java/team1/BE/seamless/DTO/MemberResponseDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,41 @@ public class MemberResponseDTO {

private String message;

public MemberResponseDTO(String message) {
private String name;

private String role;

private String email;

public MemberResponseDTO(String message, String name, String role, String email) {
this.message = message;
this.name = name;
this.role = role;
this.email = email;
}

public String getRole() {
return role;
}

public void setRole(String role) {
this.role = role;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getMessage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ public AttendUrlController(AttendURLService attendURLService) {
* less)
*/
@Operation(summary = "팀원초대 링크 생성")
@PostMapping("/api/project/{project_id}/invite-link")
@PostMapping("/api/project/{project_id}/invite-link/{user-id}")
public SingleResult<String> generateInviteLink(HttpServletRequest req,
@Valid @PathVariable("project_id") Long projectId) {
return new SingleResult<>(attendURLService.generateAttendURL(req, projectId));
@Valid @PathVariable("project_id") Long projectId,
@Valid @PathVariable("user-id") Long userId) {
return new SingleResult<>(attendURLService.generateAttendURL(req, projectId, userId));
}
}
37 changes: 23 additions & 14 deletions src/main/java/team1/BE/seamless/controller/MemberController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand All @@ -13,12 +14,15 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import team1.BE.seamless.DTO.MemberRequestDTO;
import team1.BE.seamless.DTO.MemberResponseDTO;
import team1.BE.seamless.entity.MemberEntity;
import team1.BE.seamless.service.MemberService;
import team1.BE.seamless.util.page.PageMapper;
import team1.BE.seamless.util.page.PageResult;
import team1.BE.seamless.util.page.SingleResult;

import java.lang.reflect.Member;


@Tag(name = "팀원 관리")
@RequestMapping("/api/project/{project_id}/member")
Expand All @@ -34,43 +38,48 @@ public class MemberController {

@Operation(summary = "팀원 개별 조회")
@GetMapping("/{member_id}")
public SingleResult<MemberEntity> getMember(@Valid @PathVariable("project_id") Long projectId,
@Valid @PathVariable("member_id") Long memberId) {
return new SingleResult<>(memberService.getMember(projectId, memberId));
public SingleResult<MemberResponseDTO> getMember(@Valid @PathVariable("project_id") Long projectId,
@Valid @PathVariable("member_id") Long memberId,
HttpServletRequest req) {
return new SingleResult<>(memberService.getMember(projectId, memberId, req));
}

@Operation(summary = "팀원 전체 조회")
@GetMapping
public PageResult<MemberEntity> getMemberList(@Valid @PathVariable("project_id") Long projectId,
@Valid MemberRequestDTO.getMemberList memberListRequestDTO) {
@Valid MemberRequestDTO.getMemberList memberListRequestDTO,
HttpServletRequest req) {
return PageMapper.toPageResult(
memberService.getMemberList(projectId, memberListRequestDTO));
memberService.getMemberList(projectId, memberListRequestDTO, req));
}


@Operation(summary = "새 팀원 추가")
@PostMapping
public SingleResult<MemberEntity> createMember(
public SingleResult<MemberResponseDTO> createMember(
@PathVariable("project_id") Long projectId,
@Valid @RequestBody MemberRequestDTO.CreateMember Create) {
return new SingleResult<>(memberService.createMember(projectId, Create));
@Valid @RequestBody MemberRequestDTO.CreateMember Create,
HttpServletRequest req) {
return new SingleResult<>(memberService.createMember(projectId, Create, req));
}

@Operation(summary = "팀원 정보 수정")
@PutMapping("/{member_id}")
public SingleResult<MemberEntity> updateMember(
public SingleResult<MemberResponseDTO> updateMember(
@PathVariable("project_id") Long projectId,
@PathVariable("member_id") Long memberId
, @RequestBody MemberRequestDTO.UpdateMember update) {
return new SingleResult<>(memberService.updateMember(projectId, memberId, update));
, @RequestBody MemberRequestDTO.UpdateMember update,
HttpServletRequest req) {
return new SingleResult<>(memberService.updateMember(projectId, memberId, update, req));
}

@Operation(summary = "팀원 삭제")
@DeleteMapping("/{member_id}")
public SingleResult<MemberEntity> deleteMember(
public SingleResult<MemberResponseDTO> deleteMember(
@PathVariable("project_id") Long projectId,
@PathVariable("member_id") Long memberId) {
@PathVariable("member_id") Long memberId,
HttpServletRequest req) {

return new SingleResult<>(memberService.deleteMember(projectId, memberId));
return new SingleResult<>(memberService.deleteMember(projectId, memberId, req));
}
}
5 changes: 4 additions & 1 deletion src/main/java/team1/BE/seamless/init/InitData.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ public class InitData {
private final ProjectCreator projectCreator;
private final UserCreator userCreator;
private final OptionCreator optionCreator;
private final MemberCreator memberCreator;

@Autowired
public InitData(TestCreator testCreator, ProjectCreator projectCreator, UserCreator userCreator,
OptionCreator optionCreator) {
OptionCreator optionCreator, MemberCreator memberCreator) {
this.testCreator = testCreator;
this.projectCreator = projectCreator;
this.userCreator = userCreator;
this.optionCreator = optionCreator;
this.memberCreator = memberCreator;
}

@PostConstruct
Expand All @@ -30,5 +32,6 @@ public void init() {
userCreator.creator();
optionCreator.creator();
projectCreator.creator();
memberCreator.creator();
}
}
30 changes: 30 additions & 0 deletions src/main/java/team1/BE/seamless/init/MemberCreator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package team1.BE.seamless.init;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import team1.BE.seamless.DTO.MemberRequestDTO;
import team1.BE.seamless.service.MemberService;

@Component
public class MemberCreator {

private final MemberService memberService;

@Autowired
public MemberCreator(MemberService memberService) {
this.memberService = memberService;
}

public void creator() {
// 테스트용으로 request데이터 생성
MemberRequestDTO.CreateMember member1 = new MemberRequestDTO.CreateMember("권순호","MEMBER","ex1@gmail.com","exURL1");
memberService.createMember(1L, member1); // HttpServletRequest는 null 처리가 안돼서 테스트용으로 새로운 create만듦

MemberRequestDTO.CreateMember member2 = new MemberRequestDTO.CreateMember("김동혁","USER","ex2@gmail.com","exURL2");
memberService.createMember(1L, member2); // HttpServletRequest는 null 처리가 안돼서 테스트용으로 새로운 create만듦

MemberRequestDTO.CreateMember member3 = new MemberRequestDTO.CreateMember("김도헌","MEMBER","ex3@gmail.com","exURL3");
memberService.createMember(1L, member3); // HttpServletRequest는 null 처리가 안돼서 테스트용으로 새로운 create만듦
}

}
29 changes: 29 additions & 0 deletions src/main/java/team1/BE/seamless/mapper/MemberMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.springframework.stereotype.Component;
import team1.BE.seamless.DTO.MemberRequestDTO.CreateMember;
import team1.BE.seamless.DTO.MemberRequestDTO.UpdateMember;
import team1.BE.seamless.DTO.MemberResponseDTO;
import team1.BE.seamless.entity.MemberEntity;
import team1.BE.seamless.entity.ProjectEntity;

Expand All @@ -28,4 +29,32 @@ public MemberEntity toUpdate(MemberEntity member, UpdateMember update) {
return member;
}

public MemberResponseDTO toGetResponseDTO(MemberEntity memberEntity) {
return new MemberResponseDTO("성공적으로 조회되었습니다.",
memberEntity.getName(),
memberEntity.getRole(),
memberEntity.getEmail());
}

public MemberResponseDTO toDeleteResponseDTO(MemberEntity memberEntity) {
return new MemberResponseDTO("성공적으로 삭제되었습니다.",
memberEntity.getName(),
memberEntity.getRole(),
memberEntity.getEmail());
}

public MemberResponseDTO toCreateResponseDTO(MemberEntity memberEntity) {
return new MemberResponseDTO("성공적으로 생성되었습니다.",
memberEntity.getName(),
memberEntity.getRole(),
memberEntity.getEmail());
}

public MemberResponseDTO toPutResponseDTO(MemberEntity memberEntity) {
return new MemberResponseDTO("성공적으로 수정되었습니다.",
memberEntity.getName(),
memberEntity.getRole(),
memberEntity.getEmail());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
@Repository
public interface MemberRepository extends JpaRepository<MemberEntity, Long> {

Optional<MemberEntity> findByIdAndProjectEntityIdAndIsDeleteFalse(Long id, Long projectId);

Page<MemberEntity> findAllByProjectEntityIdAndIsDeleteFalse(Long projectId, Pageable pageable);

Optional<MemberEntity> findByProjectEntityIdAndEmailAndIsDeleteFalse(Long projectId, String email);

Optional<MemberEntity> findByProjectEntityIdAndIdAndIsDeleteFalse(Long projectId, Long memberId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@
@Repository
public interface ProjectRepository extends JpaRepository<ProjectEntity, Long> {

Page<ProjectPeriod> findAllByIsDeletedFalse(Pageable pageable);

Optional<ProjectEntity> findByIdAndUserEntityEmailAndIsDeletedFalse(Long id, String email);

Page<ProjectEntity> findAllByUserEntityEmailAndIsDeletedFalse(Pageable pageable, String email);

Optional<ProjectEntity> findByIdAndIsDeletedFalse(Long id);

Page<ProjectPeriod> findByUserEntityEmailAndIsDeletedFalse(Pageable pageable, String email);

Optional<ProjectEntity> findByIdAndUserEntityIdAndIsDeletedFalse(Long projectId, Long userId);

}
19 changes: 16 additions & 3 deletions src/main/java/team1/BE/seamless/service/AttendURLService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import team1.BE.seamless.entity.ProjectEntity;
import team1.BE.seamless.entity.enums.Role;
import team1.BE.seamless.repository.ProjectRepository;
import team1.BE.seamless.util.auth.AesEncrypt;
import team1.BE.seamless.util.auth.ParsingPram;
Expand All @@ -29,11 +30,23 @@ public AttendURLService(ProjectRepository projectRepository, ParsingPram parsing
this.aesEncrypt = aesEncrypt;
}

public String generateAttendURL(HttpServletRequest req, @Valid Long projectId) {
ProjectEntity project = projectRepository.findByIdAndUserEntityEmailAndIsDeletedFalse(projectId,
parsingPram.getEmail(req))
public String generateAttendURL(HttpServletRequest req, @Valid Long projectId, @Valid Long userId) {
// ProjectEntity project = projectRepository.findByIdAndUserEntityEmailAndIsDeletedFalse(projectId,
// parsingPram.getEmail(req)) 토큰에서 이메일 찾는 로직 테스트 안 돼서, 일단 프로젝트 id+유저id 로 찾는 로직으로 해놓음(추후 다시 수정 예정)
ProjectEntity project = projectRepository.findByIdAndUserEntityIdAndIsDeletedFalse(projectId,userId)
.orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "프로젝트가 존재하지 않음"));

// 현재 시간이 프로젝트 종료 기한을 넘어섰는지 체크
// if (project.getEndDate().isBefore(LocalDateTime.now())) {
// throw new BaseHandler(HttpStatus.BAD_REQUEST, "프로젝트는 종료되었습니다.");
// } 프로젝트 initData에 EndDate 설정이 안되어있어서 지금 테스트하면 오류걸림 그래서 주석처리 해놓음ㅇㅇ

// 팀장인지 확인(팀원인지 굳이 한번 더 확인하지 않음. 팀장인지만 검증.)
if (parsingPram.getRole(req).equals(Role.USER.toString())) {
throw new BaseHandler(HttpStatus.UNAUTHORIZED,"생성 권한이 없습니다.");
}


// 코드는 프로젝트id + exp로 구성
// exp는 1일로 가정
String code = aesEncrypt.encrypt(
Expand Down
Loading

0 comments on commit ece7790

Please sign in to comment.