Skip to content

Commit

Permalink
Merge pull request #127 from team9502/dev
Browse files Browse the repository at this point in the history
배포
  • Loading branch information
daeundada authored Jun 21, 2024
2 parents 8efbbdb + 70ec387 commit 246d91c
Show file tree
Hide file tree
Showing 11 changed files with 293 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import team9502.sinchulgwinong.domain.scrap.dto.response.JobScrapResponseDTO;
import team9502.sinchulgwinong.domain.scrap.dto.response.ScrapResponseDTO;
import team9502.sinchulgwinong.domain.board.dto.response.BoardListResponseDTO;
import team9502.sinchulgwinong.domain.jobBoard.dto.response.JobBoardListResponseDTO;
import team9502.sinchulgwinong.domain.scrap.dto.response.CpUserScrapListResponseDTO;
import team9502.sinchulgwinong.domain.scrap.service.ScrapService;
import team9502.sinchulgwinong.domain.user.entity.User;
import team9502.sinchulgwinong.global.response.GlobalApiResponse;
import team9502.sinchulgwinong.global.security.UserDetailsImpl;

import java.util.List;

import static team9502.sinchulgwinong.global.response.SuccessCode.*;

@RestController
Expand All @@ -25,9 +24,9 @@ public class ScrapController {
private final ScrapService scrapService;

@PostMapping("/boards/{boardId}")
public ResponseEntity<GlobalApiResponse<Object>> scrapCreateBoard(
public ResponseEntity<GlobalApiResponse<Void>> scrapCreateBoard(
@PathVariable(("boardId")) Long boardId,
@AuthenticationPrincipal UserDetailsImpl userDetails){
@AuthenticationPrincipal UserDetailsImpl userDetails) {

User user = (User) userDetails.getUser();

Expand All @@ -53,27 +52,28 @@ public ResponseEntity<GlobalApiResponse<Object>> scrapCreateBoard(
}

@GetMapping("/boards")
public ResponseEntity<GlobalApiResponse<List<ScrapResponseDTO>>> getAllScraps(

@AuthenticationPrincipal UserDetailsImpl userDetails){
public ResponseEntity<GlobalApiResponse<BoardListResponseDTO>> getAllScraps(
@AuthenticationPrincipal UserDetailsImpl userDetails,
@RequestParam(value = "page", defaultValue = "0") int page,
@RequestParam(value = "size", defaultValue = "4") int size) {

User user = (User) userDetails.getUser();

List<ScrapResponseDTO> scrapResponseDTOS = scrapService.getAllScraps(user);
BoardListResponseDTO boardListResponseDTO = scrapService.getAllScraps(user, page, size);

return ResponseEntity.status(SUCCESS_READ_ALL_SCRAP.getHttpStatus())
.body(
GlobalApiResponse.of(
SUCCESS_READ_ALL_SCRAP.getMessage(),
scrapResponseDTOS
boardListResponseDTO
)
);
}

@PostMapping("/job-boards/{jobBoardId}")
public ResponseEntity<GlobalApiResponse<Object>> scrapCreateJobBoard(
public ResponseEntity<GlobalApiResponse<Void>> scrapCreateJobBoard(
@PathVariable("jobBoardId") Long jobBoardId,
@AuthenticationPrincipal UserDetailsImpl userDetails){
@AuthenticationPrincipal UserDetailsImpl userDetails) {

User user = (User) userDetails.getUser();

Expand All @@ -87,31 +87,79 @@ public ResponseEntity<GlobalApiResponse<Object>> scrapCreateJobBoard(
null
)
);
}
else {
} else {
return ResponseEntity.status(SUCCESS_CREATE_SCRAP.getHttpStatus())
.body(
GlobalApiResponse.of(
SUCCESS_DELETE_SCRAP.getMessage(),
null
)
);
}
}
}

@GetMapping("/job-boards")
public ResponseEntity<GlobalApiResponse<List<JobScrapResponseDTO>>> getAllJobScraps(
@AuthenticationPrincipal UserDetailsImpl userDetails){
public ResponseEntity<GlobalApiResponse<JobBoardListResponseDTO>> getAllJobScraps(
@AuthenticationPrincipal UserDetailsImpl userDetails,
@RequestParam(value = "page", defaultValue = "0") int page,
@RequestParam(value = "size", defaultValue = "4") int size) {

User user = (User) userDetails.getUser();

JobBoardListResponseDTO jobBoardListResponseDTO = scrapService.getAllJobBoards(user, page, size);

return ResponseEntity.status(SUCCESS_READ_ALL_SCRAP.getHttpStatus())
.body(
GlobalApiResponse.of(
SUCCESS_READ_ALL_SCRAP.getMessage(),
jobBoardListResponseDTO
)
);
}

@PostMapping("/cp-user/{cpUserId}")
public ResponseEntity<GlobalApiResponse<Void>> cpUserScrapCreate(
@PathVariable(name = "cpUserId") Long cpUserId,
@AuthenticationPrincipal UserDetailsImpl userDetails) {

User user = (User) userDetails.getUser();

boolean isCreated = scrapService.cpUserScrapCreate(user, cpUserId);

if (isCreated) {
return ResponseEntity.status(SUCCESS_CREATE_SCRAP.getHttpStatus())
.body(
GlobalApiResponse.of(
SUCCESS_CREATE_SCRAP.getMessage(),
null
)
);
} else {
return ResponseEntity.status(SUCCESS_CREATE_SCRAP.getHttpStatus())
.body(
GlobalApiResponse.of(
SUCCESS_DELETE_SCRAP.getMessage(),
null
)
);
}
}

@GetMapping("/cp-user")
public ResponseEntity<GlobalApiResponse<CpUserScrapListResponseDTO>> getAllCpUserScrap(
@AuthenticationPrincipal UserDetailsImpl userDetails,
@RequestParam(value = "page", defaultValue = "0") int page,
@RequestParam(value = "size", defaultValue = "4") int size) {

User user = (User) userDetails.getUser();

List<JobScrapResponseDTO> jobScrapResponseDTOS = scrapService.getAllJobBoards(user);
CpUserScrapListResponseDTO cpUserScrapListResponseDTO = scrapService.getAllCpUserScrap(user, page, size);

return ResponseEntity.status(SUCCESS_READ_ALL_SCRAP.getHttpStatus())
.body(
GlobalApiResponse.of(
SUCCESS_READ_ALL_SCRAP.getMessage(),
jobScrapResponseDTOS
cpUserScrapListResponseDTO
)
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package team9502.sinchulgwinong.domain.scrap.dto.response;

import lombok.Getter;
import team9502.sinchulgwinong.domain.companyUser.dto.response.CpUserProfileResponseDTO;

import java.util.List;

@Getter
public class CpUserScrapListResponseDTO {

private Long totalCpScrapCount;

private int currentPage;

private int totalPages;

private int pageSize;

private List<CpUserProfileResponseDTO> cpUserProfileResponseDTOS;

public CpUserScrapListResponseDTO(
List<CpUserProfileResponseDTO> cpUserProfileResponseDTOS,
Long totalCpScrapCount,
int currentPage,
int totalPages,
int pageSize) {

this.totalCpScrapCount = totalCpScrapCount;
this.currentPage = currentPage;
this.totalPages = totalPages;
this.pageSize = pageSize;
this.cpUserProfileResponseDTOS = cpUserProfileResponseDTOS;
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@Getter
@Entity
public class Scrap {
public class BoardScrap {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package team9502.sinchulgwinong.domain.scrap.entity;

import jakarta.persistence.*;
import lombok.Getter;
import lombok.Setter;
import team9502.sinchulgwinong.domain.companyUser.entity.CompanyUser;
import team9502.sinchulgwinong.domain.user.entity.User;

@Getter
@Entity
public class CpUserScrap {

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

@Setter
@ManyToOne
@JoinColumn(name = "cp_user_id")
private CompanyUser companyUser;

@Setter
@OneToOne
@JoinColumn(name = "userId")
private User user;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package team9502.sinchulgwinong.domain.scrap.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import team9502.sinchulgwinong.domain.scrap.entity.BoardScrap;

public interface BoardScrapsRepository extends JpaRepository<BoardScrap, Long> {

Page<BoardScrap> findByUser_UserId(Long userId, Pageable pageable);

boolean existsByUser_UserIdAndBoard_BoardId(Long userId, Long boardId);

BoardScrap findByUser_UserIdAndBoard_BoardId(Long userId, Long boardId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package team9502.sinchulgwinong.domain.scrap.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import team9502.sinchulgwinong.domain.scrap.entity.CpUserScrap;

public interface CpUserScrapRepository extends JpaRepository<CpUserScrap, Long> {

boolean existsByCompanyUser_CpUserIdAndUser_UserId(Long cpUserId, Long userId);

CpUserScrap findByCompanyUser_CpUserId(Long cpUserId);

Page<CpUserScrap> findByUser_UserId(Long userId, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package team9502.sinchulgwinong.domain.scrap.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import team9502.sinchulgwinong.domain.scrap.entity.JobScrap;

import java.util.List;

public interface JobScrapRepository extends JpaRepository<JobScrap, Long> {

boolean existsByJobBoard_JobBoardIdAndUser_UserId(Long jobBoardId, Long userId);

JobScrap findByJobBoard_JobBoardIdAndUser_UserId(Long jobBoardId, Long userId);
List<JobScrap> findByUser_UserId(Long userId);

Page<JobScrap> findByUser_UserId(Long userId, Pageable pageable);
}

This file was deleted.

Loading

0 comments on commit 246d91c

Please sign in to comment.