fix : setting page refactoring complete
This commit is contained in:
@@ -78,19 +78,18 @@ public class UserServiceImpl implements UserService {
|
|||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public UserResponse updateUser(UserUpdate userUpdate, UserAuth userAuth){
|
public UserResponse updateUser(UserUpdate userUpdate, UserAuth userAuth){
|
||||||
User user = userRepository.findById(userAuth.getId()).orElseThrow(() -> new CustomException(Error.USER_NOT_FOUND));
|
User user = userRepository.findById(userAuth.getId()).orElseThrow(() -> {throw new CustomException(Error.USER_NOT_FOUND);});
|
||||||
|
|
||||||
if(userUpdate.getEmail() != null){
|
if(userUpdate.getEmail() != null){
|
||||||
userRepository.findAllByEmail(userUpdate.getEmail())
|
userRepository.findAllByEmail(userUpdate.getEmail())
|
||||||
.stream().filter(found -> !found.getId().equals(userRepository.findById(user.getId())))
|
.stream().filter(found -> !found.getId().equals(user.getId()))
|
||||||
.findAny().ifPresent(found -> new CustomException(Error.DUPLICATE_EMAIL));
|
.findFirst().ifPresent(found ->{throw new CustomException(Error.DUPLICATE_EMAIL);} );
|
||||||
user.changeEmail(userUpdate.getEmail());
|
user.changeEmail(userUpdate.getEmail());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(userUpdate.getUsername() != null){
|
if(userUpdate.getUsername() != null){
|
||||||
userRepository.findAllByUsername(userUpdate.getUsername())
|
userRepository.findAllByUsername(userUpdate.getUsername())
|
||||||
.stream().filter(found -> !found.getId().equals(userRepository.findById(user.getId())))
|
.stream().filter(found -> !found.getId().equals(user.getId()))
|
||||||
.findAny().ifPresent(found -> new CustomException(Error.DUPLICATE_EMAIL));
|
.findFirst().ifPresent(found -> {throw new CustomException(Error.DUPLICATE_USERNAME);});
|
||||||
user.changeUsername(userUpdate.getUsername());
|
user.changeUsername(userUpdate.getUsername());
|
||||||
}
|
}
|
||||||
if(userUpdate.getPassword() != null){
|
if(userUpdate.getPassword() != null){
|
||||||
|
|||||||
@@ -1,13 +1,4 @@
|
|||||||
import axios, {AxiosResponse} from "axios";
|
import axios, {AxiosResponse} from "axios";
|
||||||
import { useStore } from "vuex";
|
|
||||||
|
|
||||||
//TODO
|
|
||||||
//임시방편 watch로 바라보는게 더 좋다고함. watch로 감시하자. Token
|
|
||||||
const getToken = () => {
|
|
||||||
let test = useStore().getters.getToken;
|
|
||||||
console.log(test)
|
|
||||||
return test;
|
|
||||||
}
|
|
||||||
|
|
||||||
const axiosService = axios.create({
|
const axiosService = axios.create({
|
||||||
baseURL: import.meta.env.VITE_BASE_URL,
|
baseURL: import.meta.env.VITE_BASE_URL,
|
||||||
@@ -32,8 +23,6 @@ const getCurrentUser = async (): Promise<AxiosResponse> => {
|
|||||||
|
|
||||||
const updateUser = async (user: object): Promise<AxiosResponse> => {
|
const updateUser = async (user: object): Promise<AxiosResponse> => {
|
||||||
let currentToken = localStorage.getItem("token");
|
let currentToken = localStorage.getItem("token");
|
||||||
console.log(user);
|
|
||||||
console.log(currentToken);
|
|
||||||
return axiosService.put('/api/user', {user}, {
|
return axiosService.put('/api/user', {user}, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: "TOKEN " + currentToken,
|
Authorization: "TOKEN " + currentToken,
|
||||||
|
|||||||
@@ -8,6 +8,13 @@
|
|||||||
<h1 class="text-xs-center">Your Settings</h1>
|
<h1 class="text-xs-center">Your Settings</h1>
|
||||||
|
|
||||||
<form>
|
<form>
|
||||||
|
<ul class="error-messages" v-if="emailDuplicate">
|
||||||
|
<li align="left">email has already been taken</li>
|
||||||
|
</ul>
|
||||||
|
<ul class="error-messages" v-if="usernameDuplicate">
|
||||||
|
<li align="left">username has already been taken</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<fieldset class="form-group">
|
<fieldset class="form-group">
|
||||||
<input class="form-control" type="text" placeholder="URL of profile picture" v-model="user.image">
|
<input class="form-control" type="text" placeholder="URL of profile picture" v-model="user.image">
|
||||||
@@ -45,7 +52,7 @@
|
|||||||
import { getCurrentUser, updateUser } from "@/api";
|
import { getCurrentUser, updateUser } from "@/api";
|
||||||
import { useStore } from "vuex";
|
import { useStore } from "vuex";
|
||||||
import router from "@/router";
|
import router from "@/router";
|
||||||
import { onMounted, reactive } from "vue";
|
import {onMounted, reactive, ref} from "vue";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "TheSetting",
|
name: "TheSetting",
|
||||||
@@ -61,31 +68,44 @@ export default {
|
|||||||
const password = "";
|
const password = "";
|
||||||
const store = useStore();
|
const store = useStore();
|
||||||
|
|
||||||
const getUser = (getuser: { bio: string; email: string; username: string; image: string; }) => {
|
const emailDuplicate = ref(false);
|
||||||
|
const usernameDuplicate = ref(false);
|
||||||
|
|
||||||
|
const getUser = async (getuser: { bio: string; email: string; username: string; image: string; }) => {
|
||||||
user.bio = getuser.bio
|
user.bio = getuser.bio
|
||||||
user.email = getuser.email
|
user.email = getuser.email
|
||||||
user.username = getuser.username
|
user.username = getuser.username
|
||||||
user.image = getuser.image
|
user.image = getuser.image
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const showEmailError = () => {
|
||||||
|
emailDuplicate.value = true;
|
||||||
|
usernameDuplicate.value = false;
|
||||||
|
};
|
||||||
|
const showUsernameError = () => {
|
||||||
|
usernameDuplicate.value = true;
|
||||||
|
emailDuplicate.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
const setUser = async () => {
|
const setUser = async () => {
|
||||||
try{
|
try{
|
||||||
console.log(await updateUser(user));
|
|
||||||
/*
|
|
||||||
const { data } = await updateUser(user);
|
const { data } = await updateUser(user);
|
||||||
store.dispatch("LOGIN", data.user);
|
await store.dispatch("LOGIN", data.user);
|
||||||
router.push({
|
await router.push({
|
||||||
name: 'Profile',
|
name: 'Profile',
|
||||||
params: {username: data.user.username}
|
params: {username: data.user.username}
|
||||||
})*/
|
})
|
||||||
}catch(error:any){
|
}catch(error: any){
|
||||||
// Todo Error처리
|
|
||||||
const code = error.response.data.errors.code;
|
const code = error.response.data.errors.code;
|
||||||
console.log(code);
|
if(code == "DUPLICATE_EMAIL"){
|
||||||
|
showEmailError();
|
||||||
|
}else if(code == "DUPLICATE_USERNAME"){
|
||||||
|
showUsernameError();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const logout = () =>{
|
const logout = async () =>{
|
||||||
store.dispatch("LOGOUT").then(()=>{
|
store.dispatch("LOGOUT").then(()=>{
|
||||||
router.push({name: "Home"});
|
router.push({name: "Home"});
|
||||||
})
|
})
|
||||||
@@ -95,15 +115,17 @@ export default {
|
|||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
try {
|
try {
|
||||||
const { data } = await getCurrentUser();
|
const { data } = await getCurrentUser();
|
||||||
store.dispatch("LOGIN", data.user)
|
await store.dispatch("LOGIN", data.user)
|
||||||
getUser(data.user);
|
getUser(data.user);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
//TODO error처리
|
const code = error.response.data.errors.code;
|
||||||
console.log(error);
|
if(code == "EMAIL_NULL_OR_INVALID"){
|
||||||
|
await router.push({name:"home"});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return {user, password, url, getUser, setUser, logout};
|
return {user, password, url, emailDuplicate, usernameDuplicate, getUser, setUser, logout};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user