-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feat] 인증 기능 추가
- Loading branch information
Showing
23 changed files
with
445 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/com/join/core/common/exception/impl/BadRequestException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.join.core.common.exception.impl; | ||
|
||
import com.join.core.common.exception.ErrorCode; | ||
import com.join.core.common.exception.GeneralException; | ||
|
||
public class BadRequestException extends GeneralException { | ||
|
||
public BadRequestException(ErrorCode errorCode) { | ||
super(errorCode); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.join.core.proof.constant; | ||
|
||
public enum ProofStatus { | ||
|
||
PENDING, | ||
APPROVED, | ||
REJECTED | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
package com.join.core.proof.constant; | ||
|
||
public enum ProofType { | ||
PHOTO, TIMER | ||
PHOTO, TIMER; | ||
|
||
public boolean isPhotoType() { | ||
return this == PHOTO; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/com/join/core/proof/controller/ProofController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.join.core.proof.controller; | ||
|
||
import com.join.core.auth.domain.UserPrincipal; | ||
import com.join.core.common.response.ApiResponse; | ||
import com.join.core.proof.controller.specification.ProofControllerSpecification; | ||
import com.join.core.proof.dto.request.CreateProofRequest; | ||
import com.join.core.proof.dto.response.CreateProofResponse; | ||
import com.join.core.proof.service.ProofService; | ||
import com.join.core.proof.service.dto.CreateProofCommand; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("${api.prefix}/study/{studyToken}/meetings/{meetingNo}/proof") | ||
public class ProofController implements ProofControllerSpecification { | ||
|
||
private final ProofService proofService; | ||
|
||
@PreAuthorize("isAuthenticated()") | ||
@PostMapping | ||
public ApiResponse<CreateProofResponse> createProof( | ||
@AuthenticationPrincipal UserPrincipal userPrincipal, | ||
@PathVariable String studyToken, | ||
@PathVariable Integer meetingNo, | ||
@Valid @RequestBody CreateProofRequest createProofRequest | ||
) { | ||
return ApiResponse.created( | ||
proofService.createProof(new CreateProofCommand( | ||
createProofRequest.proofType(), | ||
createProofRequest.proofPhotoUrl(), | ||
userPrincipal.getAvatarId(), | ||
studyToken, | ||
meetingNo, | ||
createProofRequest.provenDate() | ||
)) | ||
); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/join/core/proof/controller/specification/ProofControllerSpecification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.join.core.proof.controller.specification; | ||
|
||
import com.join.core.auth.domain.UserPrincipal; | ||
import com.join.core.common.response.ApiResponse; | ||
import com.join.core.proof.dto.request.CreateProofRequest; | ||
import com.join.core.proof.dto.response.CreateProofResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
|
||
public interface ProofControllerSpecification { | ||
|
||
@Tag(name = "${swagger.tag.proof}") | ||
@Operation(summary = "회차 인증 - 인증 필수", | ||
description = "회차 인증 - 인증 필수", | ||
security = {@SecurityRequirement(name = "session-token")}) | ||
ApiResponse<CreateProofResponse> createProof( | ||
@AuthenticationPrincipal UserPrincipal userPrincipal, | ||
@PathVariable String studyToken, | ||
@PathVariable Integer meetingNo, | ||
@Valid @RequestBody CreateProofRequest createProofRequest | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.join.core.proof.domain; | ||
|
||
import com.join.core.file.domain.ImageFile; | ||
import com.join.core.file.domain.SinglePhoto; | ||
import jakarta.persistence.Embedded; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.validation.Valid; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Entity | ||
public class ProofPhoto implements SinglePhoto { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Valid | ||
@NotNull | ||
@Embedded | ||
private ImageFile file; | ||
|
||
public ProofPhoto(ImageFile file) { | ||
this.file = file; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/join/core/proof/dto/request/CreateProofRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.join.core.proof.dto.request; | ||
|
||
import com.join.core.proof.constant.ProofType; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record CreateProofRequest( | ||
@NotNull ProofType proofType, | ||
String proofPhotoUrl, | ||
@NotNull LocalDateTime provenDate) { | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/join/core/proof/dto/response/CreateProofResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.join.core.proof.dto.response; | ||
|
||
import com.join.core.proof.constant.ProofType; | ||
import lombok.Builder; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Builder | ||
public record CreateProofResponse( | ||
Long id, | ||
ProofType proofType, | ||
String proofPhotoUrl, | ||
LocalDateTime provenDate | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.join.core.proof.mapper; | ||
|
||
import com.join.core.avatar.domain.Avatar; | ||
import com.join.core.meeting.domain.Meeting; | ||
import com.join.core.proof.constant.ProofStatus; | ||
import com.join.core.proof.domain.Proof; | ||
import com.join.core.proof.domain.ProofPhoto; | ||
import com.join.core.proof.dto.response.CreateProofResponse; | ||
import com.join.core.proof.service.dto.CreateProofCommand; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ProofMapper { | ||
|
||
public Proof toEntity(CreateProofCommand command, Avatar avatar, Meeting meeting, ProofPhoto photo) { | ||
return Proof.builder() | ||
.type(command.proofType()) | ||
.provenDate(command.provenDate()) | ||
.avatar(avatar) | ||
.meeting(meeting) | ||
.photo(photo) | ||
.proofStatus(ProofStatus.PENDING) | ||
.build(); | ||
} | ||
|
||
public CreateProofResponse toResponse(Proof proof) { | ||
return CreateProofResponse.builder() | ||
.id(proof.getId()) | ||
.proofType(proof.getType()) | ||
.proofPhotoUrl(proof.getPhoto().getFile().getUrl()) | ||
.provenDate(proof.getProvenDate()) | ||
.build(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/join/core/proof/repository/ProofReaderImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.join.core.proof.repository; | ||
|
||
import com.join.core.proof.constant.ProofStatus; | ||
import com.join.core.proof.service.ProofReader; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class ProofReaderImpl implements ProofReader { | ||
|
||
private final ProofRepository proofRepository; | ||
|
||
@Override | ||
public boolean hasOngoingProof(Long avatarId, Long meetingId) { | ||
return proofRepository.existsByAvatarIdAndMeetingIdAndProofStatus(avatarId, meetingId, ProofStatus.PENDING) || | ||
proofRepository.existsByAvatarIdAndMeetingIdAndProofStatus(avatarId, meetingId, ProofStatus.APPROVED); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/join/core/proof/repository/ProofRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.join.core.proof.repository; | ||
|
||
import com.join.core.proof.constant.ProofStatus; | ||
import com.join.core.proof.domain.Proof; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ProofRepository extends JpaRepository<Proof, Long> { | ||
|
||
boolean existsByAvatarIdAndMeetingIdAndProofStatus(Long avatarId, Long meetingId, ProofStatus proofStatus); | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/join/core/proof/repository/ProofStoreImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.join.core.proof.repository; | ||
|
||
import com.join.core.proof.domain.Proof; | ||
import com.join.core.proof.service.ProofStore; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class ProofStoreImpl implements ProofStore { | ||
|
||
private final ProofRepository proofRepository; | ||
|
||
@Override | ||
public Proof save(Proof proof) { | ||
return proofRepository.save(proof); | ||
} | ||
} |
Oops, something went wrong.