Skip to content
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

Debug and style ReviewPage #46

Merged
merged 26 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9c93343
delete old user controller method and write a different one to return…
nora-kauczor Nov 6, 2024
ecd6ba1
update user controller
nora-kauczor Nov 6, 2024
e7d4750
make sure userId stays a string in frontend
nora-kauczor Nov 6, 2024
dc6325a
use time zoned date when activating vocab: write method getTodayTimeZ…
nora-kauczor Nov 6, 2024
c839ffc
adjsut security config to allow access to /api/vocab/auth/name to get…
nora-kauczor Nov 6, 2024
7765047
write tests for getUserId method
nora-kauczor Nov 6, 2024
116a3e9
debug getTodaysVocabs function
nora-kauczor Nov 6, 2024
f8c24ee
enhance code of App.tsx
nora-kauczor Nov 6, 2024
8e4ed65
add state variable vocabsToReviewLoaded to avoid HomePage renders whe…
nora-kauczor Nov 6, 2024
6de0065
work on vocabs to review and conditional rendering of homepage
nora-kauczor Nov 6, 2024
87d7662
debug call of vocabsToReview and rendering of HomePage
nora-kauczor Nov 7, 2024
2e8c349
streamline getInputWithoutExtraSpaces function
nora-kauczor Nov 7, 2024
65a7303
write getWordWithoutArticle function and use it in checkAnswer functi…
nora-kauczor Nov 7, 2024
f915f86
make app name in Header clickable to navigate to Homepage
nora-kauczor Nov 7, 2024
97576f7
write getWordWithoutBrackets function in ReviewPage and use it in che…
nora-kauczor Nov 7, 2024
4ecc760
move ReviewPage's util functions to util directory
nora-kauczor Nov 7, 2024
8fecf0e
write getWordWithoutBracketsIncludingContent function and use it in g…
nora-kauczor Nov 7, 2024
36b86a0
write util function to get right or left side of the slash if there i…
nora-kauczor Nov 7, 2024
29ddb7d
move getRightAnswers function to utils folder
nora-kauczor Nov 7, 2024
aa68e5e
use useEffect to get next Vocabulary or go back to HomePage when revi…
nora-kauczor Nov 7, 2024
d7d5051
streamline usage of ZonedDateTime in VocabService's activation methods
nora-kauczor Nov 7, 2024
1d1de5e
move utils folder into ReviewPage folder
nora-kauczor Nov 7, 2024
8a88ed2
streamline return statement of CalendarWeek
nora-kauczor Nov 7, 2024
acadffd
remove console.error from updateVocabsToReview since it is not necessary
nora-kauczor Nov 8, 2024
7dd3ed9
style ReviewPage and CardContainer, delete height attribute of App's css
nora-kauczor Nov 8, 2024
342d9de
remove unnecessary lines
nora-kauczor Nov 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.example.backend.security;


public record AppUser(String id,
String name,
String avatarUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public DefaultSecurityFilterChain securityFilterChain(HttpSecurity httpSecurity)
.requestMatchers("/api/vocab").authenticated()
.requestMatchers("/api/vocab/login").permitAll()
.requestMatchers("/api/vocab/auth").permitAll()
.requestMatchers("/api/vocab/auth/name").permitAll()
.requestMatchers("/api/vocab/**").authenticated()
.requestMatchers("/api/calendar").authenticated()
.anyRequest().permitAll())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.AllArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.core.user.OAuth2User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -14,14 +15,22 @@ public class UserController {

private final UserRepo userRepo;


@GetMapping
public AppUser getUser(@AuthenticationPrincipal OAuth2User user) {
public String getUserId(){
String userId = SecurityContextHolder
.getContext()
.getAuthentication()
.getName();
if (userId.equals("anonymousUser")) {return "";}
return userId;
}

@GetMapping("/name")
public AppUser getUserName(@AuthenticationPrincipal OAuth2User user) {
if
( user == null) {
( user == null) {
return new AppUser("NotFound", "", null, null);
}
return userRepo.findById(user.getName()).orElseThrow();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.ZonedDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -36,7 +37,8 @@ public Vocab deactivateVocab(String id, String userName) throws IdNotFoundExcept

public Vocab activateVocab(String id, String userName) throws IdNotFoundException {
Vocab vocab = vocabRepo.findById(id).orElseThrow(() -> new IdNotFoundException("ID not found."));
List<LocalDate> dates = generateDates(LocalDate.now());
LocalDate today = ZonedDateTime.now().toLocalDate();
List<LocalDate> dates = generateDates(today);
vocab.getDatesPerUser().put(userName, dates);
return vocabRepo.save(vocab);
}
Expand All @@ -59,7 +61,9 @@ public Vocab createVocab(VocabDTOCreate vocabDTO, String userName) throws Langua
public Vocab createAndActivateVocab(VocabDTOCreate vocabDTO, String userName) throws LanguageNotFoundException {
Language language = Language.getEnumByString(vocabDTO.language());
Map<String, List<LocalDate>> datesPerUser = new HashMap<>();
List<LocalDate> dates = generateDates(LocalDate.now());
LocalDate today = ZonedDateTime.now().toLocalDate();
System.out.println(today.getClass().getName());
List<LocalDate> dates = generateDates(today);
datesPerUser.put(userName, dates);
Vocab newVocab = new Vocab(null, vocabDTO.word(), vocabDTO.translation(),
vocabDTO.info(), language, datesPerUser, userName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;

import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.oidcLogin;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

Expand All @@ -22,12 +23,29 @@ class UserControllerTest {
@Autowired
private UserRepo userRepo;

@Test
void getUserId_shouldReturnUserId_whenCalled_ifUserIsLoggedIn() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/api/vocab/auth")
.with(user("12345").roles("USER")))
.andExpect(status().isOk())
.andExpect(content().string("12345"));
}

@Test
void getUserId_shouldReturnEmptyString_whenCalled_ifUserIsNotLoggedIn() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/api/vocab/auth"))
.andExpect(status().isOk())
.andExpect(content().string(""));
}



@DirtiesContext
@Test
void getUser_shouldReturn200AndUserObject_whenCalled_ifUserIsLoggedIn() throws Exception {
void getUserName_shouldReturn200AndUserObject_whenCalled_ifUserIsLoggedIn() throws Exception {
AppUser testUser = new AppUser("user", "Hans", null, null);
userRepo.save(testUser);
mvc.perform(MockMvcRequestBuilders.get("/api/vocab/auth")
mvc.perform(MockMvcRequestBuilders.get("/api/vocab/auth/name")
.with(oidcLogin()
.userInfoToken(token -> token.claim("login", "Hans"))))
.andExpect(status().isOk())
Expand All @@ -38,8 +56,8 @@ void getUser_shouldReturn200AndUserObject_whenCalled_ifUserIsLoggedIn() throws E

@DirtiesContext
@Test
void getUser_shouldReturn200AndDummyUserObject_whenCalled_ifUserIsNotLoggedIn() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/api/vocab/auth"))
void getUserName_shouldReturn200AndDummyUserObject_whenCalled_ifUserIsNotLoggedIn() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/api/vocab/auth/name"))
.andExpect(status().isOk())
.andExpect(content().json("""
{"id":"NotFound","name":"","avatarUrl":null,"authority":null}
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/App.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#app {
height: 100vh;
width: 100%;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}


Loading