-
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.
* refactor: 패키지 변경 (#163) * feat: 학기 엔티티 (#163) * feat: 학기 리포지토리 (#163) * feat: 현재 학기 API (#163) * feat: 현재 학기 API 권한 설정 (#163) * chore: API 설명 추가 (#163)
- Loading branch information
1 parent
c7a435d
commit 2aeb999
Showing
9 changed files
with
112 additions
and
5 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/main/java/com/smunity/server/domain/major/entity/Major.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
27 changes: 27 additions & 0 deletions
27
src/main/java/com/smunity/server/domain/term/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,27 @@ | ||
package com.smunity.server.domain.term.controller; | ||
|
||
import com.smunity.server.domain.term.dto.TermResponseDto; | ||
import com.smunity.server.domain.term.service.TermService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/terms") | ||
@Tag(name = "10 Term API", description = "학기 관련 API") | ||
public class TermController { | ||
|
||
private final TermService termService; | ||
|
||
@GetMapping("/current") | ||
@Operation(summary = "현재 학기 조회", description = "현재 학기를 조회합니다.") | ||
public ResponseEntity<TermResponseDto> readCurrentTerm() { | ||
TermResponseDto responseDto = termService.readCurrentTerm(); | ||
return ResponseEntity.ok(responseDto); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/smunity/server/domain/term/dto/TermResponseDto.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,20 @@ | ||
package com.smunity.server.domain.term.dto; | ||
|
||
import com.smunity.server.global.common.entity.Term; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record TermResponseDto( | ||
Long id, | ||
int year, | ||
String semester | ||
) { | ||
|
||
public static TermResponseDto from(Term term) { | ||
return TermResponseDto.builder() | ||
.id(term.getId()) | ||
.year(term.getYear()) | ||
.semester(term.getSemester().getName()) | ||
.build(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/smunity/server/domain/term/service/TermService.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,24 @@ | ||
package com.smunity.server.domain.term.service; | ||
|
||
import com.smunity.server.domain.term.dto.TermResponseDto; | ||
import com.smunity.server.global.common.entity.Term; | ||
import com.smunity.server.global.common.repository.TermRepository; | ||
import com.smunity.server.global.exception.GeneralException; | ||
import com.smunity.server.global.exception.code.ErrorCode; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class TermService { | ||
|
||
private final TermRepository termRepository; | ||
|
||
public TermResponseDto readCurrentTerm() { | ||
Term term = termRepository.findFirstByOrderByIdDesc() | ||
.orElseThrow(() -> new GeneralException(ErrorCode.TERM_NOT_FOUND)); | ||
return TermResponseDto.from(term); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/smunity/server/global/common/entity/Term.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,22 @@ | ||
package com.smunity.server.global.common.entity; | ||
|
||
import com.smunity.server.global.common.entity.enums.Semester; | ||
import jakarta.persistence.*; | ||
import lombok.Getter; | ||
|
||
@Entity | ||
@Getter | ||
@Table(name = "common_term") | ||
public class Term { | ||
|
||
@Id | ||
@Column(name = "term_id") | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(name = "year_value") | ||
private Integer year; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private Semester semester; | ||
} |
2 changes: 1 addition & 1 deletion
2
...r/domain/major/entity/enums/Semester.java → .../global/common/entity/enums/Semester.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
11 changes: 11 additions & 0 deletions
11
src/main/java/com/smunity/server/global/common/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,11 @@ | ||
package com.smunity.server.global.common.repository; | ||
|
||
import com.smunity.server.global.common.entity.Term; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface TermRepository extends JpaRepository<Term, Long> { | ||
|
||
Optional<Term> findFirstByOrderByIdDesc(); | ||
} |
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