Skip to content

Commit

Permalink
Merge pull request #256 from team9502/dev
Browse files Browse the repository at this point in the history
๋ฐฐํฌ
  • Loading branch information
daeundada authored Jun 30, 2024
2 parents 481b582 + 3d05547 commit 5e45753
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import team9502.sinchulgwinong.domain.companyUser.dto.request.CpUserDeleteRequestDTO;
import team9502.sinchulgwinong.domain.companyUser.dto.request.CpUserPasswordUpdateRequestDTO;
import team9502.sinchulgwinong.domain.companyUser.dto.request.CpUserProfileUpdateRequestDTO;
import team9502.sinchulgwinong.domain.companyUser.dto.response.CpUserPageResponseDTO;
Expand Down Expand Up @@ -217,4 +218,38 @@ public ResponseEntity<GlobalApiResponse<Void>> usePointsForBanner(
)
);
}

@DeleteMapping
@Operation(summary = "๊ธฐ์—… ํšŒ์› ํƒˆํ‡ด", description = "๊ธฐ์—… ํšŒ์›์„ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "๊ธฐ์—… ํšŒ์› ํƒˆํ‡ด ์„ฑ๊ณต",
content = @Content(mediaType = "application/json",
examples = @ExampleObject(value = "{\"message\": \"๊ธฐ์—… ํšŒ์› ํƒˆํ‡ด ์„ฑ๊ณต\", \"data\": null }"))),
@ApiResponse(responseCode = "400", description = "์š”์ฒญ ์ฒ˜๋ฆฌ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ",
content = @Content(mediaType = "application/json",
examples = {
@ExampleObject(name = "๋น„๋ฐ€๋ฒˆํ˜ธ ๋ถˆ์ผ์น˜",
value = "{\"message\": \"์ž…๋ ฅํ•œ ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ๊ธฐ์กด ๋น„๋ฐ€๋ฒˆํ˜ธ์™€ ์ผ์น˜ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.\", \"data\": null }"),
@ExampleObject(name = "์ž˜๋ชป๋œ ์‚ฌ์šฉ์ž ์œ ํ˜•",
value = "{\"message\": \"์ž˜๋ชป๋œ ์‚ฌ์šฉ์ž ์œ ํ˜•์ž…๋‹ˆ๋‹ค.\", \"data\": null }")
})),
@ApiResponse(responseCode = "404", description = "์‚ฌ์šฉ์ž๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Œ",
content = @Content(mediaType = "application/json",
examples = @ExampleObject(value = "{\"message\": \"์‚ฌ์šฉ์ž๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.\", \"data\": null }"))),
@ApiResponse(responseCode = "500", description = "์„œ๋ฒ„ ๋‚ด๋ถ€ ์˜ค๋ฅ˜",
content = @Content(mediaType = "application/json",
examples = @ExampleObject(value = "{\"message\": \"์„œ๋ฒ„ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.\", \"data\": null }")))
})
public ResponseEntity<GlobalApiResponse<Void>> deleteCompanyUser(
@AuthenticationPrincipal UserDetailsImpl userDetails,
@RequestBody CpUserDeleteRequestDTO requestDTO) {

cpUserService.deleteCpUser(userDetails.getCpUserId(), requestDTO);

return ResponseEntity.status(SUCCESS_CP_USER_DELETED.getHttpStatus())
.body(
GlobalApiResponse.of(
SUCCESS_CP_USER_DELETED.getMessage(),
null));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package team9502.sinchulgwinong.domain.companyUser.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class CpUserDeleteRequestDTO {

@Schema(description = "๊ธฐ์—… ํšŒ์› ๋น„๋ฐ€๋ฒˆํ˜ธ", example = "Password1!")
private String password;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import jakarta.persistence.*;
import lombok.*;
import team9502.sinchulgwinong.domain.jobBoard.entity.JobBoard;
import team9502.sinchulgwinong.domain.point.CommonPoint;
import team9502.sinchulgwinong.domain.point.entity.Point;
import team9502.sinchulgwinong.global.entity.BaseTimeEntity;

import java.time.LocalDate;
import java.util.List;

@Entity
@Getter
Expand Down Expand Up @@ -71,6 +73,9 @@ public class CompanyUser extends BaseTimeEntity implements CommonPoint {
@Column(nullable = false)
private Integer viewCount = 0;

@OneToMany(mappedBy = "companyUser", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
private List<JobBoard> jobBoards;

public void incrementViewCount() {
this.viewCount++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import team9502.sinchulgwinong.domain.companyUser.dto.request.CpUserDeleteRequestDTO;
import team9502.sinchulgwinong.domain.companyUser.dto.request.CpUserPasswordUpdateRequestDTO;
import team9502.sinchulgwinong.domain.companyUser.dto.request.CpUserProfileUpdateRequestDTO;
import team9502.sinchulgwinong.domain.companyUser.dto.response.CpUserPageResponseDTO;
Expand All @@ -14,6 +15,7 @@
import team9502.sinchulgwinong.domain.companyUser.entity.CompanyUser;
import team9502.sinchulgwinong.domain.companyUser.repository.CompanyUserRepository;
import team9502.sinchulgwinong.domain.email.service.EmailVerificationService;
import team9502.sinchulgwinong.domain.jobBoard.repository.JobBoardRepository;
import team9502.sinchulgwinong.domain.point.enums.UpType;
import team9502.sinchulgwinong.domain.point.service.PointService;
import team9502.sinchulgwinong.global.exception.ApiException;
Expand All @@ -31,6 +33,7 @@ public class CpUserService {
private final PasswordEncoder passwordEncoder;
private final EmailVerificationService emailVerificationService;
private final PointService pointService;
private final JobBoardRepository jobBoardRepository;

@Transactional
public CpUserProfileResponseDTO getCpUserProfile(Long cpUserId) {
Expand Down Expand Up @@ -152,4 +155,21 @@ private CpUserResponseDTO convertToDTO(CompanyUser companyUser) {
companyUser.getViewCount()
);
}

@Transactional
public void deleteCpUser(Long cpUserId, CpUserDeleteRequestDTO requestDTO) {

CompanyUser companyUser = companyUserRepository.findById(cpUserId)
.orElseThrow(() -> new ApiException(ErrorCode.COMPANY_USER_NOT_FOUND));

if (!passwordEncoder.matches(requestDTO.getPassword(), companyUser.getCpPassword())) {
throw new ApiException(ErrorCode.PASSWORD_MISMATCH);
}

jobBoardRepository.deleteAll(companyUser.getJobBoards());

pointService.deletePointData(companyUser.getPoint());

companyUserRepository.delete(companyUser);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public enum SuccessCode {
SUCCESS_CP_USER_PROFILE_UPDATED(HttpStatus.OK, "๊ธฐ์—…(ํšŒ์›) ํ”„๋กœํ•„ ์ˆ˜์ • ์„ฑ๊ณต"),
SUCCESS_CP_USER_PASSWORD_UPDATED(HttpStatus.OK, "๊ธฐ์—…(ํšŒ์›) ๋น„๋ฐ€๋ฒˆํ˜ธ ์ˆ˜์ • ์„ฑ๊ณต"),
SUCCESS_CP_USER_ALL_READ(HttpStatus.OK, "๊ธฐ์—…(ํšŒ์›) ์ „์ฒด ์กฐํšŒ ์„ฑ๊ณต"),
SUCCESS_CP_USER_DELETED(HttpStatus.OK, "๊ธฐ์—…(ํšŒ์›) ํšŒ์› ํƒˆํ‡ด ์„ฑ๊ณต"),

//Chat
SUCCESS_CREATE_CHAT_ROOM(HttpStatus.CREATED, "์ฑ„ํŒ…๋ฐฉ ์ƒ์„ฑ ์„ฑ๊ณต"),
Expand Down

0 comments on commit 5e45753

Please sign in to comment.