diff --git a/.gitignore b/.gitignore index c9097f5..16e4df3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ __pycache__ node_modules data client/package-lock.json -client/yarn.lock \ No newline at end of file +client/yarn.lock +Tinder-Clone.pdf \ No newline at end of file diff --git a/README.md b/README.md index ab8330f..5d5aea5 100644 --- a/README.md +++ b/README.md @@ -1 +1,13 @@ -Tinder-Clone +# Tinder-Clone + +Αυτό το repository είναι περιέχει την δεύτερη εργασία που πραγματοποίηθηκε για το μάθημα <<Ηλεκτρονικό Εμπόριο>>, όπως και το εργαστηριακό μέρος του μαθήματος <<Προγραμματισμός Κινητών>>. +Ο σκοπός της εργασίας ητάν η δημιουργία μίας ιστοσελίδας με σκόπο γνωριμίων (σαν το Tinder), όπως και την αντιστοίχη Android εφαρμογή του. + +## Απαραίτητα προγραμμάτα + +Για την εκτέλεση της εφαρμογής, χρείαζεται να υπάρχει εγκαταστημένο Docker. Κατα προτίμησης, έχει δοκιμαστεί πλήρως σε Linux σύστημα και θα έπρεπε να δουλεύει το ίδιο καλά και σε MacOS. Σε Windows, όμως, είναι αβέβαιο εάν δουλεύει. Για την εγκατάσταση του Docker, έχει φτιαχτεί αυτομάτο scriptακη που δουλεύει σε [Debian](https://www.debian.org/distrib/) συστήματα (όπως [Ubuntu](https://ubuntu.com/download/desktop), [Kali](https://www.kali.org/get-kali/) κτλ), όπως και σε [Arch](https://archlinux.org/download/) συστήματα (όπως [Manjaro](https://manjaro.org/download/)). +Επιπρόσθετα, για την Android εφαρμογή θα πρέπει να υπάρχει και το [AndroidStudio](https://developer.android.com/studio) κατεβασμένο. + +## Επιπλέον πληροφορίες + +Για επιπλέον πληροφορίες, πατήστε [εδώ](Tinder-Clone.adoc). diff --git a/Tinder-Clone-Android/.gitignore b/Tinder-Clone-Android/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/Tinder-Clone-Android/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/Tinder-Clone-Android/app/.gitignore b/Tinder-Clone-Android/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/Tinder-Clone-Android/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/Tinder-Clone-Android/app/build.gradle b/Tinder-Clone-Android/app/build.gradle new file mode 100644 index 0000000..d74191e --- /dev/null +++ b/Tinder-Clone-Android/app/build.gradle @@ -0,0 +1,48 @@ +plugins { + id 'com.android.application' +} + +android { + compileSdkVersion 30 + buildToolsVersion "30.0.3" + + defaultConfig { + applicationId "com.example.tinder_clone_android" + minSdkVersion 27 + targetSdkVersion 30 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + buildFeatures { + viewBinding true + } +} + +dependencies { + implementation 'androidx.appcompat:appcompat:1.3.0' + implementation 'com.google.android.material:material:1.3.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + implementation 'androidx.annotation:annotation:1.2.0' + implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1' + implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' + + implementation 'com.squareup.retrofit2:retrofit:2.4.0' + implementation 'com.squareup.retrofit2:converter-gson:2.4.0' + implementation 'com.squareup.picasso:picasso:2.71828' +} \ No newline at end of file diff --git a/Tinder-Clone-Android/app/proguard-rules.pro b/Tinder-Clone-Android/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/Tinder-Clone-Android/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/Tinder-Clone-Android/app/src/androidTest/java/com/example/tinder_clone_android/ExampleInstrumentedTest.java b/Tinder-Clone-Android/app/src/androidTest/java/com/example/tinder_clone_android/ExampleInstrumentedTest.java new file mode 100644 index 0000000..249da5d --- /dev/null +++ b/Tinder-Clone-Android/app/src/androidTest/java/com/example/tinder_clone_android/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.tinder_clone_android; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.example.tinder_clone_android", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/Tinder-Clone-Android/app/src/main/AndroidManifest.xml b/Tinder-Clone-Android/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..41c088e --- /dev/null +++ b/Tinder-Clone-Android/app/src/main/AndroidManifest.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Tinder-Clone-Android/app/src/main/java/com/example/TinderCloneAdapter.java b/Tinder-Clone-Android/app/src/main/java/com/example/TinderCloneAdapter.java new file mode 100644 index 0000000..5da80a2 --- /dev/null +++ b/Tinder-Clone-Android/app/src/main/java/com/example/TinderCloneAdapter.java @@ -0,0 +1,93 @@ +package com.example; + +import android.annotation.SuppressLint; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.example.tinder_clone_android.R; +import com.example.tinder_clone_android.json_api.User; +import com.squareup.picasso.Picasso; + +import org.jetbrains.annotations.NotNull; + +import java.time.LocalDate; +import java.time.Period; +import java.util.ArrayList; + +public class TinderCloneAdapter extends RecyclerView.Adapter { + private final ArrayList localDataSet; + + public TinderCloneAdapter(ArrayList localDataSet) { + this.localDataSet = localDataSet; + } + + @NonNull + @NotNull + @Override + public ViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.list_item, parent, false); + + return new ViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull @NotNull ViewHolder holder, int position) { + holder.bind(localDataSet.get(position)); + } + + @Override + public int getItemCount() { + return localDataSet.size(); + } + + public static class ViewHolder extends RecyclerView.ViewHolder { + private ImageView imageView; + private TextView name; + private TextView surname; + private TextView age; + private TextView height; + private TextView weight; + private TextView eyes; + private TextView hair; + + @SuppressLint("SetTextI18n") + public void bind(User user) { + + Picasso.get() + .load("http://192.168.1.3:5000/img/".concat(user.getPfp())) + .error(R.drawable.ic_launcher_background).into(imageView); + + name.setText(user.getName()); + surname.setText(user.getSurname()); + age.setText(Period.between(LocalDate + .parse(user.getBirthday()), LocalDate.now()).getYears() + " years old"); + height.setText(user.getHeight() + "cm"); + weight.setText(user.getWeight() + "kg"); + eyes.setText(user.getEyeColour() + " eyes, "); + hair.setText(user.getHairColour() + " hair"); + } + + public ViewHolder(@NonNull @NotNull View itemView) { + super(itemView); + setReferences(itemView); + } + + private void setReferences(View itemView) { + imageView = itemView.findViewById(R.id.profile_pic); + name = itemView.findViewById(R.id.name); + surname = itemView.findViewById(R.id.surname); + age = itemView.findViewById(R.id.age); + height = itemView.findViewById(R.id.height); + weight = itemView.findViewById(R.id.weight); + eyes = itemView.findViewById(R.id.eyes); + hair = itemView.findViewById(R.id.hair); + } + } +} \ No newline at end of file diff --git a/Tinder-Clone-Android/app/src/main/java/com/example/tinder_clone_android/MainActivity.java b/Tinder-Clone-Android/app/src/main/java/com/example/tinder_clone_android/MainActivity.java new file mode 100644 index 0000000..570951f --- /dev/null +++ b/Tinder-Clone-Android/app/src/main/java/com/example/tinder_clone_android/MainActivity.java @@ -0,0 +1,73 @@ +package com.example.tinder_clone_android; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import android.annotation.SuppressLint; +import android.os.Bundle; +import android.widget.ImageView; +import android.widget.TableLayout; +import android.widget.TableRow; +import android.widget.TextView; + +import com.example.TinderCloneAdapter; +import com.example.tinder_clone_android.json_api.RestApi; +import com.example.tinder_clone_android.json_api.User; +import com.example.tinder_clone_android.json_api.UserList; +import com.squareup.picasso.Picasso; + +import java.time.LocalDate; +import java.time.Period; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import retrofit2.Retrofit; +import retrofit2.converter.gson.GsonConverterFactory; + +public class MainActivity extends AppCompatActivity { + public static MainActivity Instance; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + Instance = this; + + Retrofit retrofit = new Retrofit.Builder() + .baseUrl("http://192.168.1.3:5000/") + .addConverterFactory(GsonConverterFactory.create()) + .build(); + + RestApi restApi = retrofit.create(RestApi.class); + + Call call = restApi.getUsers(); + + call.enqueue(new Callback() { + @SuppressLint("SetTextI18n") + @Override + public void onResponse(Call call, Response response) { + if (!response.isSuccessful()) { + System.err.printf("*** Code: %s\n", response.code()); + return; + } + + UserList userList = response.body(); + assert userList != null; + + RecyclerView recyclerView = findViewById(R.id.recycler_view); + TinderCloneAdapter tinderCloneAdapter = + new TinderCloneAdapter(userList.getUserList()); + recyclerView.setAdapter(tinderCloneAdapter); + recyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.Instance)); + } + + @Override + public void onFailure(Call call, Throwable t) { + System.err.printf("*** %s\n", t.getMessage()); + } + }); + } +} \ No newline at end of file diff --git a/Tinder-Clone-Android/app/src/main/java/com/example/tinder_clone_android/json_api/Ping.java b/Tinder-Clone-Android/app/src/main/java/com/example/tinder_clone_android/json_api/Ping.java new file mode 100644 index 0000000..6aca8ca --- /dev/null +++ b/Tinder-Clone-Android/app/src/main/java/com/example/tinder_clone_android/json_api/Ping.java @@ -0,0 +1,9 @@ +package com.example.tinder_clone_android.json_api; + +public class Ping { + private String text; + + public String getText() { + return text; + } +} diff --git a/Tinder-Clone-Android/app/src/main/java/com/example/tinder_clone_android/json_api/RestApi.java b/Tinder-Clone-Android/app/src/main/java/com/example/tinder_clone_android/json_api/RestApi.java new file mode 100644 index 0000000..204dddd --- /dev/null +++ b/Tinder-Clone-Android/app/src/main/java/com/example/tinder_clone_android/json_api/RestApi.java @@ -0,0 +1,12 @@ +package com.example.tinder_clone_android.json_api; + +import retrofit2.Call; +import retrofit2.http.GET; + +public interface RestApi { + @GET("ping") + Call getPing(); + + @GET("/") + Call getUsers(); +} diff --git a/Tinder-Clone-Android/app/src/main/java/com/example/tinder_clone_android/json_api/User.java b/Tinder-Clone-Android/app/src/main/java/com/example/tinder_clone_android/json_api/User.java new file mode 100644 index 0000000..f92c3eb --- /dev/null +++ b/Tinder-Clone-Android/app/src/main/java/com/example/tinder_clone_android/json_api/User.java @@ -0,0 +1,208 @@ +package com.example.tinder_clone_android.json_api; + +import com.google.gson.annotations.SerializedName; + +public class User { + @SerializedName("_id") + private String userID; + private String email; + private String username; + private String name; + private String surname; + private String password; + private String birthday; + private String gender; + private String weight; + private String height; + @SerializedName("hair_colour") + private String hairColour; + @SerializedName("eye_colour") + private String eyeColour; + @SerializedName("sexual_orientation") + private String sexualOrientation; + private String education; + private boolean smoker; + private boolean drinker; + private boolean children; + private String status; + private String bio; + private String pfp; + private String photos; + private String type; + + public String getUserID() { + return userID; + } + + public void setUserID(String userID) { + this.userID = userID; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getSurname() { + return surname; + } + + public void setSurname(String surname) { + this.surname = surname; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getBirthday() { + return birthday; + } + + public void setBirthday(String birthday) { + this.birthday = birthday; + } + + public String getGender() { + return gender; + } + + public void setGender(String gender) { + this.gender = gender; + } + + public String getWeight() { + return weight; + } + + public void setWeight(String weight) { + this.weight = weight; + } + + public String getHeight() { + return height; + } + + public void setHeight(String height) { + this.height = height; + } + + public String getHairColour() { + return hairColour; + } + + public void setHairColour(String hairColour) { + this.hairColour = hairColour; + } + + public String getEyeColour() { + return eyeColour; + } + + public void setEyeColour(String eyeColour) { + this.eyeColour = eyeColour; + } + + public String getSexualOrientation() { + return sexualOrientation; + } + + public void setSexualOrientation(String sexualOrientation) { + this.sexualOrientation = sexualOrientation; + } + + public String getEducation() { + return education; + } + + public void setEducation(String education) { + this.education = education; + } + + public boolean isSmoker() { + return smoker; + } + + public void setSmoker(boolean smoker) { + this.smoker = smoker; + } + + public boolean isDrinker() { + return drinker; + } + + public void setDrinker(boolean drinker) { + this.drinker = drinker; + } + + public boolean isChildren() { + return children; + } + + public void setChildren(boolean children) { + this.children = children; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getBio() { + return bio; + } + + public void setBio(String bio) { + this.bio = bio; + } + + public String getPfp() { + return pfp; + } + + public void setPfp(String pfp) { + this.pfp = pfp; + } + + public String getPhotos() { + return photos; + } + + public void setPhotos(String photos) { + this.photos = photos; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } +} diff --git a/Tinder-Clone-Android/app/src/main/java/com/example/tinder_clone_android/json_api/UserList.java b/Tinder-Clone-Android/app/src/main/java/com/example/tinder_clone_android/json_api/UserList.java new file mode 100644 index 0000000..a26b7ef --- /dev/null +++ b/Tinder-Clone-Android/app/src/main/java/com/example/tinder_clone_android/json_api/UserList.java @@ -0,0 +1,18 @@ +package com.example.tinder_clone_android.json_api; + +import com.google.gson.annotations.SerializedName; + +import java.util.ArrayList; + +public class UserList { + @SerializedName("users") + private ArrayList userList; + + public ArrayList getUserList() { + return userList; + } + + public void setUserList(ArrayList userList) { + this.userList = userList; + } +} diff --git a/Tinder-Clone-Android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/Tinder-Clone-Android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/Tinder-Clone-Android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Tinder-Clone-Android/app/src/main/res/drawable/ic_launcher_background.xml b/Tinder-Clone-Android/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/Tinder-Clone-Android/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tinder-Clone-Android/app/src/main/res/layout/activity_main.xml b/Tinder-Clone-Android/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..b1659c9 --- /dev/null +++ b/Tinder-Clone-Android/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/Tinder-Clone-Android/app/src/main/res/layout/list_item.xml b/Tinder-Clone-Android/app/src/main/res/layout/list_item.xml new file mode 100644 index 0000000..d40a302 --- /dev/null +++ b/Tinder-Clone-Android/app/src/main/res/layout/list_item.xml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Tinder-Clone-Android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/Tinder-Clone-Android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..eca70cf --- /dev/null +++ b/Tinder-Clone-Android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/Tinder-Clone-Android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/Tinder-Clone-Android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..eca70cf --- /dev/null +++ b/Tinder-Clone-Android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/Tinder-Clone-Android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/Tinder-Clone-Android/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..a571e60 Binary files /dev/null and b/Tinder-Clone-Android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/Tinder-Clone-Android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/Tinder-Clone-Android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png new file mode 100644 index 0000000..61da551 Binary files /dev/null and b/Tinder-Clone-Android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/Tinder-Clone-Android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/Tinder-Clone-Android/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..c41dd28 Binary files /dev/null and b/Tinder-Clone-Android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/Tinder-Clone-Android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/Tinder-Clone-Android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png new file mode 100644 index 0000000..db5080a Binary files /dev/null and b/Tinder-Clone-Android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/Tinder-Clone-Android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/Tinder-Clone-Android/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..6dba46d Binary files /dev/null and b/Tinder-Clone-Android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/Tinder-Clone-Android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/Tinder-Clone-Android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png new file mode 100644 index 0000000..da31a87 Binary files /dev/null and b/Tinder-Clone-Android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/Tinder-Clone-Android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/Tinder-Clone-Android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..15ac681 Binary files /dev/null and b/Tinder-Clone-Android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/Tinder-Clone-Android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/Tinder-Clone-Android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..b216f2d Binary files /dev/null and b/Tinder-Clone-Android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/Tinder-Clone-Android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/Tinder-Clone-Android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..f25a419 Binary files /dev/null and b/Tinder-Clone-Android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/Tinder-Clone-Android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/Tinder-Clone-Android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..e96783c Binary files /dev/null and b/Tinder-Clone-Android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/Tinder-Clone-Android/app/src/main/res/values-night/themes.xml b/Tinder-Clone-Android/app/src/main/res/values-night/themes.xml new file mode 100644 index 0000000..0d50534 --- /dev/null +++ b/Tinder-Clone-Android/app/src/main/res/values-night/themes.xml @@ -0,0 +1,16 @@ + + + + \ No newline at end of file diff --git a/Tinder-Clone-Android/app/src/main/res/values/colors.xml b/Tinder-Clone-Android/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..f8c6127 --- /dev/null +++ b/Tinder-Clone-Android/app/src/main/res/values/colors.xml @@ -0,0 +1,10 @@ + + + #FFBB86FC + #FF6200EE + #FF3700B3 + #FF03DAC5 + #FF018786 + #FF000000 + #FFFFFFFF + \ No newline at end of file diff --git a/Tinder-Clone-Android/app/src/main/res/values/dimens.xml b/Tinder-Clone-Android/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..e00c2dd --- /dev/null +++ b/Tinder-Clone-Android/app/src/main/res/values/dimens.xml @@ -0,0 +1,5 @@ + + + 16dp + 16dp + \ No newline at end of file diff --git a/Tinder-Clone-Android/app/src/main/res/values/strings.xml b/Tinder-Clone-Android/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..0cd6e90 --- /dev/null +++ b/Tinder-Clone-Android/app/src/main/res/values/strings.xml @@ -0,0 +1,13 @@ + + Tinder-Clone-Android + LoginActivity + Email + Password + Sign in or register + Sign in + "Welcome !" + Not a valid username + Password must be >5 characters + "Login failed" + Picture + \ No newline at end of file diff --git a/Tinder-Clone-Android/app/src/main/res/values/themes.xml b/Tinder-Clone-Android/app/src/main/res/values/themes.xml new file mode 100644 index 0000000..080562a --- /dev/null +++ b/Tinder-Clone-Android/app/src/main/res/values/themes.xml @@ -0,0 +1,16 @@ + + + + \ No newline at end of file diff --git a/Tinder-Clone-Android/app/src/test/java/com/example/tinder_clone_android/ExampleUnitTest.java b/Tinder-Clone-Android/app/src/test/java/com/example/tinder_clone_android/ExampleUnitTest.java new file mode 100644 index 0000000..63ea617 --- /dev/null +++ b/Tinder-Clone-Android/app/src/test/java/com/example/tinder_clone_android/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.example.tinder_clone_android; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/Tinder-Clone-Android/build.gradle b/Tinder-Clone-Android/build.gradle new file mode 100644 index 0000000..9ade2a7 --- /dev/null +++ b/Tinder-Clone-Android/build.gradle @@ -0,0 +1,25 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +buildscript { + repositories { + google() + mavenCentral() + } + dependencies { + classpath "com.android.tools.build:gradle:4.2.1" + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + google() + mavenCentral() + jcenter() // Warning: this repository is going to shut down soon + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} \ No newline at end of file diff --git a/Tinder-Clone-Android/gradle.properties b/Tinder-Clone-Android/gradle.properties new file mode 100644 index 0000000..6826e61 --- /dev/null +++ b/Tinder-Clone-Android/gradle.properties @@ -0,0 +1,17 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app"s APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true \ No newline at end of file diff --git a/Tinder-Clone-Android/gradle/wrapper/gradle-wrapper.jar b/Tinder-Clone-Android/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..f6b961f Binary files /dev/null and b/Tinder-Clone-Android/gradle/wrapper/gradle-wrapper.jar differ diff --git a/Tinder-Clone-Android/gradle/wrapper/gradle-wrapper.properties b/Tinder-Clone-Android/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..eb2a07a --- /dev/null +++ b/Tinder-Clone-Android/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Thu Jun 10 15:09:40 EEST 2021 +distributionBase=GRADLE_USER_HOME +distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip +distributionPath=wrapper/dists +zipStorePath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME diff --git a/Tinder-Clone-Android/gradlew b/Tinder-Clone-Android/gradlew new file mode 100755 index 0000000..cccdd3d --- /dev/null +++ b/Tinder-Clone-Android/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/Tinder-Clone-Android/gradlew.bat b/Tinder-Clone-Android/gradlew.bat new file mode 100644 index 0000000..e95643d --- /dev/null +++ b/Tinder-Clone-Android/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/Tinder-Clone-Android/settings.gradle b/Tinder-Clone-Android/settings.gradle new file mode 100644 index 0000000..e54f327 --- /dev/null +++ b/Tinder-Clone-Android/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = "Tinder-Clone-Android" +include ':app' diff --git a/Tinder-Clone.adoc b/Tinder-Clone.adoc new file mode 100644 index 0000000..8a5fd7e --- /dev/null +++ b/Tinder-Clone.adoc @@ -0,0 +1,224 @@ += Εφαρμογή Γνωριμιών +:toc: +:toc-title: +:source-highlighter: rouge +:source-language: js + +.ΔΕΥΤΕΡΗ ΕΡΓΑΣΙΑ ΣΤΟ ΜΑΘΗΜΑ ΗΛΕΚΤΡΟΝΙΚΟ ΕΜΠΟΡΙΟ +[NOTE] +**** +[.text-center] +Αυτό το έγγραφο είναι το φύλλο αναφόρας της εργασίας στα μαθήματα "Ηλεκτρονικό Εμπόριο και Επιχειρηματικότητα" και "Τεχνολογιά και Προγραμματισμός Κινητών Συσκευών" +**** + +Ιάκωβος Μαστρογιαννόπουλος - 711242017102 + +Τυμοτέους Λέοναρντ Στεφάνιακ - 711171012 + +== Εισαγωγή + +Αυτή είναι η κοινή εργασία που εκπονήθηκε για τα μάθημα "Ηλεκτρονικό Εμπόριο και Επιχειρηματικότητα" και "Τεχνολογιά και Προγραμματισμός Κινητών Συσκευών" που είχε θέμα μία ιστοσελίδα και Android εφαρμογή γνωριμίας. Οι τεχνολογίες που επιλέχθηκαν για την υλοποίηση του πρότζεκτ είναι οι εξής: + + * Για την ιστοσελίδα, χρησιμοποίηθηκε η https://vuejs.org/[**VueJS**], όπου είναι ένα framework της https://nodejs.org/en/[**NodeJS**], ένω η γλώσσα που γράφτηκαν τα scripts ήταν η https://www.typescriptlang.org/[**TypeScript**]. + * Για την Android εφαρμόγη, χρησιμοποίηθηκε το https://developer.android.com/studio[**AndroidStudio**], με την γλώσσα προεπιλογής την https://www.java.com/en/[**Java**]. + * Για το REST API, χρησιμοποίηθηκε η https://www.python.org/[**Python**], με συγκεκρίμενο framework το https://flask.palletsprojects.com/en/2.0.x/[**Flask**]. + * Για την αποθήκευση των δεδομένων σε μια βάση, επιλέχθηκε η https://www.mongodb.com/[**MongoDB**], η οποία είναι μια μόντερνα, noSQL βάση δεδομένων, σχεδιασμένη για την επερχόμενη Cloud εποχή. + * Για την ευκολία της εγκατάστασης της εφαρμογής, χρησιμοποίηθηκε ως έξτρα το https://docs.docker.com/engine/swarm/[**Docker Swarm**], δουλεύοντας σε Single Node. + +=== Γενικές πληροφορίες για την αρχική σελίδα + +Η VueJS χωρίζει κάθε σελίδα της σε ένα διαφορετικό https://vuejs.org/v2/guide/components.html[**component**], το οποίο με λίγα λόγια θυμίζει το layout του AndroidStudio και μπορεί να ενσωματωθεί σε αλλά components ως template. Αλλό ένα κοινό χαρακτηριστικό της VueJS με το Android είναι ότι έχει https://vuejs.org/v2/guide/instance.html[**Circle of Life**]. + +Για την εφαρμόγη, δημιουργήθηκαν εφτά κύρια components και τρία δευτερεύουσα που ο σκοπός τους είναι να δουλεύουν ως templates με κοινό κώδικα. Για την αντιστοίχηση component και url, χρησιμοποιήθηκε το https://router.vuejs.org/[**Vue Router**] το οποίο βρίσκεται στο αρχείο *index.ts*. Συγκεκριμένα, ο κώδικας είναι ο εξής: + +[source] +-- +const routes: Array = [ + { + path: '/', + name: 'Users', + component: Users + }, + { + path: '/settings', + name: 'Account', + component: Account + }, + { + path: '/login', + name: 'Login', + component: Login + }, + { + path: '/prime', + name: 'Prime', + component: Prime + }, + { + path: '/profile/:id', + name: 'Profile', + component: Profile + }, + { + path: '/contact/:id', + name: 'Contact', + component: Contact + }, + { + path: '/paypal', + name: 'Paypal', + component: Paypal + } +] +-- + +Με αλλά λόγια, άμα ο χρηστής πληκτρολογήσει στον browser του το URL *http://localhost:8080/* θα τον πάει στην αρχική οθόνη που του εμφανίζει όλους τους χρήστες. + +Σε αυτή την σελίδα, ένας συνδεδεμένος χρήστης μπορεί να δει τους άλλους χρήστες. Ένας δωρεάν χρήστης βλέπει τα εξής: + +image::img/free_users.png[] + +Να παρατηρηθεί ότι ένας απλός χρηστής δεν μπορεί να δει τα filters και του επιστρέφεται μία λίστα από περιορισμένα άτομα (τρία στο σύνολο). Ενάς χρήστης που έχει την prime έκδοση, δηλαδή έχει subscription στην εφαρμόγη, θα του εμφανίζει επιτυχώς όλες τις πληροφορίες. + +image::img/filters.png[] + +image::img/premium_users.png[] + +== Ανάλυση κώδικα + +=== Εμφάνιση χωρίς filters + +==== VueJS + +Αρχικά, όταν φορτώνει η σελίδα, εμφανίζει όλους τους χρήστες. Αυτό γίνεται με σύνδεση σε REST API μέσω της βιβλιοθήκης https://github.com/axios/axios[**axios**] της NodeJS. + +Στην δημιουργία της ιστοσελίδας, χρησιμοποιείται η εξής μέθοδος: + +[source] +-- + axios.get(this.path).then((res) => { + if (this.$session.get('user').type === 'free') { + for (let i = 0; i < 3; i++) { + this.users.push({ + id: res.data.users[i]._id, + pfp: res.data.users[i].pfp, + username: res.data.users[i].username, + email: res.data.users[i].email, + name: res.data.users[i].name, + surname: res.data.users[i].surname, + birthday: res.data.users[i].birthday, + bio: res.data.users[i].bio, + gender: res.data.users[i].gender, + weight: res.data.users[i].weight, + height: res.data.users[i].height, + eye_colour: res.data.users[i].eye_colour, + hair_colour: res.data.users[i].hair_colour + }) + } + } else { + res.data.users.forEach(user => { + this.users.push({ + id: user._id, + pfp: user.pfp, + username: user.username, + email: user.email, + name: user.name, + surname: user.surname, + birthday: user.birthday, + bio: user.bio, + gender: user.gender, + weight: user.weight, + height: user.height, + eye_colour: user.eye_colour, + hair_colour: user.hair_colour + }) + }) + } + } + ) + } +-- + +Όπου ελέγχει άμα ο χρηστής έχει την δωρεάν έκδοση, και εάν ναι, του δείχνει μόνο τρεις. + +==== Python + +Το REST API, δέχεται το GET request του axios και του επεξεργάζεται τα δεδομένα. + +[source,python] +-- +@app.route("/", methods=['GET']) +@cross_origin() +-- + +Στο παρακάτω configuration, ρυθμίζεται ότι όποτε χτυπήθει στο **localhost:5000/** GET request, θα κάνει τους εξής υπολογίσμους. + +[source,python] +-- +def all_users(): + response_object = {} + response_object['users'] = get_users(mongo.db.users.find()) + return jsonify(response_object) +-- + +Ουσιαστικά, βρίσκει όλους τους χρήστες που είναι αποθηκευμένοι στην mongoDB, παιρνεί τα δεδομενά τους και τα στέλνει ως πληροφορίες σε μορφή JSON πίσω στο axios. + +Η get_users() το μόνο που κάνει είναι να γεμίζει μία λίστα με τους χρηστές και να την γυρίζει πίσω. + +=== Φιλτραρισμένη αναζήτηση + +Στην φιλτραρισμένη αναζήτηση, ο premium χρήστης μπορεί να χρησιμοποιήσει τα φίλτρα για να δει αλλούς χρήστες με τα επιθυμητά του χαρακτηριστικά. Για να φορτωθούν τα δεδομένα στον κώδικα, χρησιμοποίηθηκε η jQuery. + +Ουσιαστικά, δημιουργείτε μία μεταβλητή query για να φτιαχτεί αυτόματα το filter. Ένα δείγμα του κώδικα: + +[source] +-- +if (min_weight != null || max_weight != null) { + query = query.concat('"weight": {') + add_comma = true // Για τα επόμενα, να βάλει κόμμα + query = (min_weight != null) ? query.concat(`"$gte": ${min_weight}`) : query + query = (max_weight != null) ? query.concat(`${(min_weight != null) ? ',' : ''}"$lte": ${max_weight}`) : query + query = query.concat('}') +} +-- + +Τέλος, κάνει ένα POST request μέσω του axios. + +[source] +-- + axios.post(this.path, payload).then((res) => { + this.users = [] + res.data.users.forEach(user => { + this.users.push({ + id: user._id, + pfp: user.pfp, + username: user.username, + email: user.email, + name: user.name, + surname: user.surname, + birthday: user.birthday, + bio: user.bio, + gender: user.gender, + weight: user.weight, + height: user.height, + eye_colour: user.eye_colour, + hair_colour: user.hair_colour + }) + }) + }) +-- + +Από την άλλη πλευρά, το REST API δεν έχει τροποποίηθει πάρα πολύ. + +[source,python] +-- +@app.route("/", methods=['GET', 'POST']) +@cross_origin() +def all_users(): + response_object = {} + + if request.method == 'GET': + response_object['users'] = get_users(mongo.db.users.find()) + elif request.method == 'POST': + post_data = request.get_json() + search_filter = post_data.get('filter') + response_object['users'] = get_users(mongo.db.users.find(search_filter)) + + return jsonify(response_object) +-- + +Εάν το search_filter είναι αδείο, τότε η find() επιστρέφει όλους τους χρήστες όπως και πριν. \ No newline at end of file diff --git a/backend/app.py b/backend/app.py index ee5181d..ca7b6e6 100644 --- a/backend/app.py +++ b/backend/app.py @@ -21,17 +21,11 @@ CORS(app, resources={r'/*': {'origins': '*'}}) -# Sanity check route -@app.route('/ping', methods=['GET']) -def ping_pong(): - return jsonify("pong!") - - # Routing @app.route('/login', methods=['PUT']) @cross_origin() def login(): - response_object = {'status': 'success'} + response_object = {} post_data = request.get_json() user = mongo.db.users.find_one({"email": post_data['email']}) @@ -39,10 +33,8 @@ def login(): if post_data['password'] == user['password']: response_object['message'] = 'Logged in successfully!' response_object['user'] = user - else: response_object['message'] = 'Wrong password! Try again...' - else: response_object['message'] = 'Email is wrong' @@ -52,7 +44,7 @@ def login(): @app.route('/register', methods=['POST']) @cross_origin() def register(): - response_object = {'status': 'success'} + response_object = {} post_data = request.get_json() email = post_data.get('email') @@ -65,12 +57,17 @@ def register(): 'surname': post_data.get('surname'), 'password': post_data.get('password'), 'birthday': post_data.get('birthday'), + 'gender': post_data.get('gender'), + 'weight': int(post_data.get('weight')), + 'height': int(post_data.get('height')), + 'hair_colour': post_data.get('hair_colour'), + 'eye_colour': post_data.get('eye_colour'), + 'bio': post_data.get('bio'), 'pfp': 'default.jpg', 'type': 'free' }) response_object['message'] = 'User made!' - else: response_object['message'] = 'Email already exists' @@ -80,7 +77,7 @@ def register(): @app.route('/user/', methods=['PUT', 'GET']) @cross_origin() def single_user(user_id): - response_object = {'status': 'success'} + response_object = {} if request.method == 'GET': response_object['user'] = mongo.db.users.find_one({"_id": user_id}) @@ -92,38 +89,58 @@ def single_user(user_id): "$set": { 'name': post_data.get('name'), 'surname': post_data.get('surname'), + 'email': post_data.get('email'), 'birthday': post_data.get('birthday'), 'gender': post_data.get('gender'), - 'weight': post_data.get('weight'), - 'height': post_data.get('height'), + 'weight': int(post_data.get('weight')), + 'height': int(post_data.get('height')), 'hair_colour': post_data.get('hair_colour'), 'eye_colour': post_data.get('eye_colour'), - 'sexual_orientation': post_data.get('sexual_orientation'), - 'education': post_data.get('education'), - 'smoker': post_data.get('smoker'), - 'drinker': post_data.get('drinker'), - 'children': post_data.get('children'), - 'status': post_data.get('status') + 'bio': post_data.get('bio') } }) - response_object['message'] = "Your info updated!" + response_object['message'] = "Your info has been updated!" return jsonify(response_object) -@app.route("/", methods=['GET']) +@app.route('/referral/') @cross_origin() -def all_users(): - response_object = {'status': 'success'} +def check_code(code): + response_object = {} + + if mongo.db.users.find_one({"username": code}) is not None: + response_object['message'] = 'OK' + + else: + response_object['message'] = 'NOT FOUND' + + return jsonify(response_object) + + +def get_users(users): query = [] - for user in mongo.db.users.find(): + for user in users: del user['password'] - del user['_id'] query.append(user) - response_object['users'] = query + return query + + +@app.route("/", methods=['GET', 'POST']) +@cross_origin() +def all_users(): + response_object = {} + + if request.method == 'GET': + response_object['users'] = get_users(mongo.db.users.find()) + elif request.method == 'POST': + post_data = request.get_json() + search_filter = post_data.get('filter') + response_object['users'] = get_users(mongo.db.users.find(search_filter)) + return jsonify(response_object) @@ -146,7 +163,15 @@ def save_image(filename): } }) - return jsonify({'status': 'success'}) + +@app.route("/prime/", methods=["PUT"]) +@cross_origin() +def prime_user(user_id): + mongo.db.users.update_one({"_id": user_id}, { + '$set': { + 'type': 'premium' + } + }) if __name__ == '__main__': diff --git a/client/public/index.html b/client/public/index.html index 748a164..418b37c 100644 --- a/client/public/index.html +++ b/client/public/index.html @@ -1,19 +1,54 @@ - + + + + + - - - Tinder Clone + + MatchBox - + + +
+ + diff --git a/client/public/matchbox.ico b/client/public/matchbox.ico new file mode 100644 index 0000000..131e4c5 Binary files /dev/null and b/client/public/matchbox.ico differ diff --git a/client/src/App.vue b/client/src/App.vue index 5f555d9..717ae75 100644 --- a/client/src/App.vue +++ b/client/src/App.vue @@ -1,14 +1,16 @@