-
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.
Merge pull request #22 from ecolink-JOIN/feature/term
[Feat] 약관 조회 API 추가
- Loading branch information
Showing
10 changed files
with
164 additions
and
7 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/main/java/com/join/core/auth/controller/TermController.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,38 @@ | ||
package com.join.core.auth.controller; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.join.core.auth.domain.TermInfo; | ||
import com.join.core.auth.domain.UserPrincipal; | ||
import com.join.core.auth.service.TermService; | ||
import com.join.core.common.response.ApiResponse; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.security.SecurityRequirement; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("${api.prefix}") | ||
public class TermController { | ||
|
||
private final TermService termService; | ||
|
||
@Tag(name = "${swagger.tag.sign-up}") | ||
@Operation(summary = "약관 조회 API - 인증 필요", | ||
description = "약관 조회 API - 현재 유저의 동의가 필요한 약관을 조회하는 API입니다.", | ||
security = {@SecurityRequirement(name = "session-token")}) | ||
@PreAuthorize("isAuthenticated()") | ||
@GetMapping("/terms") | ||
public ApiResponse<List<TermInfo.Main>> get(@AuthenticationPrincipal UserPrincipal principal) { | ||
return ApiResponse.ok(termService.getRequiredConsentTerms(principal.getUserId())); | ||
} | ||
|
||
} |
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
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,21 @@ | ||
package com.join.core.auth.domain; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
public class TermInfo { | ||
|
||
private TermInfo() { | ||
} | ||
|
||
@Builder | ||
@Getter | ||
public static class Main { | ||
private final Long id; | ||
private final String version; | ||
private final String title; | ||
private final String content; | ||
private final Term.Type type; | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/join/core/auth/domain/TermInfoMapper.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.auth.domain; | ||
|
||
import org.mapstruct.InjectionStrategy; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.mapstruct.ReportingPolicy; | ||
|
||
@Mapper( | ||
componentModel = "spring", | ||
injectionStrategy = InjectionStrategy.CONSTRUCTOR, | ||
unmappedTargetPolicy = ReportingPolicy.ERROR | ||
) | ||
public interface TermInfoMapper { | ||
|
||
@Mapping(source = "term.key.id", target = "id") | ||
@Mapping(source = "term.key.version", target = "version") | ||
TermInfo.Main of(Term term); | ||
|
||
} |
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
28 changes: 28 additions & 0 deletions
28
src/main/java/com/join/core/auth/repository/TermReaderImpl.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,28 @@ | ||
package com.join.core.auth.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.join.core.auth.domain.Term; | ||
import com.join.core.auth.domain.TermInfo; | ||
import com.join.core.auth.domain.TermInfoMapper; | ||
import com.join.core.auth.service.TermReader; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
@Component | ||
public class TermReaderImpl implements TermReader { | ||
|
||
private final TermRepository termRepository; | ||
private final TermInfoMapper termInfoMapper; | ||
|
||
@Override | ||
public List<TermInfo.Main> getRequiredConsentTerms(Long userId) { | ||
List<Term> terms = termRepository.findRequiredConsentWith(userId); | ||
return terms.stream().map(termInfoMapper::of).toList(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/join/core/auth/repository/TermRepository.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.auth.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import com.join.core.auth.domain.Term; | ||
|
||
public interface TermRepository extends JpaRepository<Term, Term.Key> { | ||
@Query("select t from Term t" | ||
+ " left join TermAgreeHistory ta" | ||
+ " on t = ta.term and ta.user.id = :userId" | ||
+ " where CURRENT_DATE between t.startDate and t.endDate" | ||
+ " and ta is null") | ||
List<Term> findRequiredConsentWith(@Param("userId") Long userId); | ||
} |
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.auth.service; | ||
|
||
import java.util.List; | ||
|
||
import com.join.core.auth.domain.TermInfo; | ||
|
||
public interface TermReader { | ||
|
||
List<TermInfo.Main> getRequiredConsentTerms(Long userId); | ||
|
||
} |
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,23 @@ | ||
package com.join.core.auth.service; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.join.core.auth.domain.TermInfo; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
@Service | ||
public class TermService { | ||
|
||
private final TermReader termReader; | ||
|
||
public List<TermInfo.Main> getRequiredConsentTerms(Long userId) { | ||
return termReader.getRequiredConsentTerms(userId); | ||
} | ||
|
||
} |