-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: 학과 리스트 반환 api 작성 #14
Open
coke98
wants to merge
1
commit into
GDSC-PKNU-Official:main
Choose a base branch
from
coke98:feature/#10
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,3 +36,4 @@ out/ | |
### VS Code ### | ||
.vscode/ | ||
src/main/resources/application.properties | ||
src/main/resources/application.yml |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/gdsc/pknu/backend/controller/user/MajorListResult.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.gdsc.pknu.backend.controller.user; | ||
|
||
import java.util.List; | ||
import com.gdsc.pknu.backend.domain.major.Major; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class MajorListResult { | ||
|
||
private List<Major> majorList; | ||
|
||
public MajorListResult(List<Major> majorList) { | ||
this.majorList = majorList; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/gdsc/pknu/backend/controller/user/MajorRestController.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,26 @@ | ||
package com.gdsc.pknu.backend.controller.user; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import com.gdsc.pknu.backend.controller.ApiRes; | ||
import com.gdsc.pknu.backend.service.MajorService; | ||
|
||
|
||
@RestController | ||
@RequestMapping("api/major") | ||
public class MajorRestController { | ||
|
||
@Autowired | ||
private final MajorService majorService; | ||
|
||
public MajorRestController(MajorService majorService) { | ||
this.majorService = majorService; | ||
} | ||
|
||
@GetMapping() | ||
public ApiRes<MajorListResult> getMajorList() { | ||
return ApiRes.SUCCESS(new MajorListResult(majorService.getMajorList())); | ||
} | ||
} |
13 changes: 10 additions & 3 deletions
13
...dsc/pknu/backend/domain/member/Major.java → ...gdsc/pknu/backend/domain/major/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
package com.gdsc.pknu.backend.domain.member; | ||
|
||
package com.gdsc.pknu.backend.domain.major; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.*; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Getter | ||
@Builder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
|
||
public class Major { | ||
@Id | ||
@GeneratedValue | ||
@Column(name = "major_id") | ||
private Long id; | ||
|
||
private String majorName; | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/gdsc/pknu/backend/domain/major/MajorRepository.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,8 @@ | ||
package com.gdsc.pknu.backend.domain.major; | ||
|
||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface MajorRepository extends JpaRepository<Major, Long> { | ||
List<Major> findAll(); | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/gdsc/pknu/backend/service/MajorService.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.gdsc.pknu.backend.service; | ||
|
||
import java.util.List; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import com.gdsc.pknu.backend.domain.major.Major; | ||
import com.gdsc.pknu.backend.domain.major.MajorRepository; | ||
|
||
@Service | ||
public class MajorService { | ||
|
||
@Autowired | ||
private final MajorRepository majorRepository; | ||
|
||
public MajorService(MajorRepository majorRepository) { | ||
this.majorRepository = majorRepository; | ||
} | ||
|
||
public List<Major> getMajorList() { | ||
return majorRepository.findAll(); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/test/java/com/gdsc/pknu/backend/controller/MajorRestControllerTest.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,47 @@ | ||
package com.gdsc.pknu.backend.controller; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import com.gdsc.pknu.backend.controller.user.MajorRestController; | ||
import com.gdsc.pknu.backend.domain.major.Major; | ||
import com.gdsc.pknu.backend.service.MajorService; | ||
import static org.mockito.Mockito.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; | ||
|
||
@WebMvcTest(MajorRestController.class) | ||
public class MajorRestControllerTest { | ||
|
||
@Autowired | ||
MockMvc mockMvc; | ||
|
||
@MockBean | ||
MajorService majorService; | ||
|
||
@Test | ||
@DisplayName("학과 목록 불러오기 테스트") | ||
void get_major_list() throws Exception { | ||
|
||
// 서비스 리턴 값 지정 | ||
List<Major> majors = new ArrayList<>(); | ||
majors.add(Major.builder() | ||
.id(1L) | ||
.majorName("기린공학과").build()); | ||
majors.add(Major.builder() | ||
.id(2L) | ||
.majorName("향유고래어학과").build()); | ||
|
||
when(majorService.getMajorList()).thenReturn(majors); | ||
|
||
mockMvc.perform(get("/api/major")) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.response.majorList[1].majorName").value("향유고래어학과")); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
src/test/java/com/gdsc/pknu/backend/domain/major/MajorRepositoryTest.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.gdsc.pknu.backend.domain.major; | ||
|
||
import java.util.List; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
|
||
@DataJpaTest | ||
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) | ||
class MajorRepositoryTest{ | ||
|
||
@Autowired | ||
private MajorRepository majorRepository; | ||
|
||
@Test | ||
@DisplayName("학과 정보 리스트 불러오기") | ||
void get_major_list(){ | ||
// given | ||
|
||
// when | ||
List<Major> majors = majorRepository.findAll(); | ||
// then | ||
assert(majors.size() == 79); | ||
assert(majors.get(78).getMajorName().equals("공공안전경찰학과")); | ||
Comment on lines
+25
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 단언하는 메서드는 |
||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
findAll()
메서드에서 find라는 이름을 보니 nullable한 반환값이 예상되네요.부모클래스의 메서드를 그대로 오버라이드 한건가요?
그런게 아니라면 반환형을 Optional로 사용하거나, 메서드 이름을 get으로 치환하는건 어떨까요?