-
Notifications
You must be signed in to change notification settings - Fork 0
Task1 #1
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
base: main
Are you sure you want to change the base?
Task1 #1
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /.idea/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.2/apache-maven-3.9.2-bin.zip | ||
| wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>com.dmdev</groupId> | ||
| <artifactId>homework-maven</artifactId> | ||
| <version>1.0.0-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <artifactId>common</artifactId> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.json</groupId> | ||
| <artifactId>json</artifactId> | ||
| <version>20230227</version> | ||
|
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. не должно быть лишних зависимостей в проекте |
||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <properties> | ||
| <maven.compiler.source>15</maven.compiler.source> | ||
| <maven.compiler.target>15</maven.compiler.target> | ||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
|
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. properties тоже наследуются, как и dependency, plugins, etc. Поэтому достаточно определить их лишь раз в parent pom |
||
| </properties> | ||
|
|
||
| </project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package com.dmdev.common.models; | ||
|
|
||
|
|
||
| public class User { | ||
| private String firstName; | ||
| private String lastName; | ||
| private String email; | ||
| private String nickname; | ||
|
|
||
| public User(String firstName, String lastName, String email, String nickname) { | ||
| this.firstName = firstName; | ||
| this.lastName = lastName; | ||
| this.email = email; | ||
| this.nickname = nickname; | ||
| } | ||
|
|
||
| public String getFirstName() { | ||
| return firstName; | ||
| } | ||
|
|
||
| public void setFirstName(String firstName) { | ||
| this.firstName = firstName; | ||
| } | ||
|
|
||
| public String getLastName() { | ||
| return lastName; | ||
| } | ||
|
|
||
| public void setLastName(String lastName) { | ||
| this.lastName = lastName; | ||
| } | ||
|
|
||
| public String getEmail() { | ||
| return email; | ||
| } | ||
|
|
||
| public void setEmail(String email) { | ||
| this.email = email; | ||
| } | ||
|
|
||
| public String getNickname() { | ||
| return nickname; | ||
| } | ||
|
|
||
| public void setNickname(String nickname) { | ||
| this.nickname = nickname; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| package com.dmdev.common.repository; | ||
|
|
||
| import com.dmdev.common.models.User; | ||
| import org.json.JSONException; | ||
| import org.json.JSONObject; | ||
|
|
||
| import java.io.BufferedReader; | ||
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
| import java.net.HttpURLConnection; | ||
| import java.net.URL; | ||
|
|
||
| public class UserRepository { | ||
|
|
||
| public static User getUser(Long id) { | ||
| String url = "http://userrepository.com/api/id/"; | ||
|
|
||
| String response = performGetRequest(url, id); | ||
| User user = processResponse(response); | ||
|
|
||
| System.out.println("Имя: " + user.getFirstName()); | ||
| System.out.println("Фамилия: " + user.getLastName()); | ||
| System.out.println("Email: " + user.getEmail()); | ||
| System.out.println("Никнейм: " + user.getNickname()); | ||
| return user; | ||
| } | ||
|
|
||
| public static String performGetRequest(String url, Long id) { | ||
| StringBuilder responseBuilder = new StringBuilder(); | ||
| try { | ||
| URL apiUrl = new URL(url + id); | ||
|
|
||
| HttpURLConnection connection = (HttpURLConnection) apiUrl.openConnection(); | ||
| connection.setRequestMethod("GET"); | ||
|
|
||
| BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); | ||
| String line; | ||
| while ((line = reader.readLine()) != null) { | ||
| responseBuilder.append(line); | ||
| } | ||
| reader.close(); | ||
|
|
||
| connection.disconnect(); | ||
| } catch (IOException e) { | ||
| System.out.println("Request error: " + e); | ||
| } | ||
|
|
||
| return responseBuilder.toString(); | ||
| } | ||
|
|
||
| private static User processResponse(String response) { | ||
| try { | ||
| JSONObject json = new JSONObject(response); | ||
|
|
||
| String firstName = json.optString("firstName", "Default"); | ||
| String lastName = json.optString("lastName", "Default"); | ||
| String email = json.optString("email", "default@example.com"); | ||
| String nickname = json.optString("nickname", ""); | ||
|
|
||
| return new User(firstName, lastName, email, nickname); | ||
| } catch (JSONException e) { | ||
| e.printStackTrace(); | ||
| return new User("Default", "Default", "default@example.com", ""); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package com.dmdev; | ||
|
|
||
| public class AppIT { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package com.dmdev; | ||
|
|
||
| public class AppTest { | ||
| } |
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.
в репозитории должно быть только то, что находится внутри твоего проекта, Т.е. рутовая помка и все что находится на ее уровне. У тебя почему-то tasks/maven/hw - так не должно быть