Refactor BFF Package Structure #64
@ -1,4 +1,4 @@
|
|||||||
package se.su.dsv.studentportalen.bff.frontend.profile;
|
package se.su.dsv.studentportalen.bff.controller;
|
||||||
|
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||||
@ -6,14 +6,26 @@ import org.springframework.security.oauth2.core.user.OAuth2User;
|
|||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import se.su.dsv.studentportalen.bff.dto.response.ProfileResponse;
|
||||||
|
import se.su.dsv.studentportalen.bff.service.ProfileService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* REST controller for user profile operations.
|
||||||
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(produces = MediaType.APPLICATION_JSON_VALUE)
|
@RequestMapping(produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
public class ProfileController {
|
public class ProfileController {
|
||||||
|
|
||||||
|
private final ProfileService service;
|
||||||
|
|
||||||
|
public ProfileController(ProfileService service) {
|
||||||
|
this.service = service;
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/profile")
|
@GetMapping("/profile")
|
||||||
public Profile getProfile(
|
public ProfileResponse getProfile(
|
||||||
@AuthenticationPrincipal(errorOnInvalidType = true) OAuth2User currentUser)
|
@AuthenticationPrincipal(errorOnInvalidType = true) OAuth2User currentUser)
|
||||||
{
|
{
|
||||||
return new Profile(currentUser.getAttribute("name"), Profile.Language.ENGLISH);
|
return service.getProfile(currentUser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
package se.su.dsv.studentportalen.bff.service;
|
||||||
|
|
||||||
|
import org.springframework.security.oauth2.core.user.OAuth2User;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import se.su.dsv.studentportalen.bff.dto.response.ProfileResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service for user profile operations.
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class ProfileService {
|
||||||
|
|
||||||
|
public ProfileResponse getProfile(OAuth2User currentUser) {
|
||||||
|
String name = currentUser.getAttribute("name");
|
||||||
|
return new ProfileResponse(name, ProfileResponse.Language.ENGLISH);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user