Skip to content

Commit

Permalink
Refactor UserService and add issue templates
Browse files Browse the repository at this point in the history
UserService's methods have been refactored for more efficient and cleaner code. Issue templates for bug reports and feature requests have been added to streamline and standardize issue reporting. Logging settings have also been revised to only include console output, and an important notice was added to the README on taking backups before editing the hosts file.
  • Loading branch information
MichiBaum committed Jul 19, 2024
1 parent d884486 commit a3eb5b3
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 26 deletions.
38 changes: 38 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
22 changes: 22 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: 'enhancement'
assignees: ''

---

## :rocket: Feature Request

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Build docker images:
docker compose logs ´name´

### Change HOSTS file
*Remember to take Backup before editing your `hosts` file, mistakes there can block your internet access or cause other network-related issues.*


#### Windows

Expand Down
1 change: 0 additions & 1 deletion admin-service/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

<!-- LOG everything at INFO level -->
<root level="info">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</root>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

<!-- LOG everything at INFO level -->
<root level="info">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</root>

Expand Down
1 change: 0 additions & 1 deletion gateway-service/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

<!-- LOG everything at INFO level -->
<root level="info">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</root>

Expand Down
1 change: 0 additions & 1 deletion javadoc-service/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

<!-- LOG everything at INFO level -->
<root level="info">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</root>

Expand Down
1 change: 0 additions & 1 deletion registry-service/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

<!-- LOG everything at INFO level -->
<root level="info">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</root>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package com.michibaum.usermanagement_service

import jakarta.persistence.GeneratedValue
import org.hibernate.annotations.GenericGenerator
import jakarta.persistence.Column
import jakarta.persistence.Entity
import jakarta.persistence.Id
import org.hibernate.annotations.UuidGenerator
import java.util.*

@Entity
data class User (
@Id
@GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "org.hibernate.id.UUIDGenerator")
val id: String,
@UuidGenerator
val id: UUID,

@Column(nullable = false, unique = true)
val username: String,
Expand All @@ -22,7 +21,7 @@ data class User (
@Column(nullable = false)
val password: String
) {
constructor() : this("", "", "", "") {
constructor() : this(UUID.randomUUID(), "", "", "") {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,27 @@ package com.michibaum.usermanagement_service

import org.springframework.security.crypto.password.PasswordEncoder
import org.springframework.stereotype.Service
import java.util.*

@Service
class UserService(
private val userRepository: UserRepository,
private val passwordEncoder: PasswordEncoder
) {

fun getUser(id: String) =
userRepository.findById(id)
.convertToNullable()
fun getUser(id: String) = findUserById(id)

fun update(id: String, updateUserDto: UpdateUserDto): User? =
userRepository.findById(id)
.convertToNullable()
this.findUserById(id)
?.copy(
username = updateUserDto.username,
email = updateUserDto.email,
password = encodePassword(updateUserDto.password)
password = passwordEncoder.encode(updateUserDto.password)
)
?.let { userRepository.save(it) }

fun encodePassword(password: String): String =
passwordEncoder.encode(password)
private fun findUserById(id: String) = userRepository.findById(id).orElseNull()

}
}

private fun <T> Optional<T>.orElseNull(): T? = this.orElse(null)
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,9 @@ class UsermanagementController (

fun convertUserToDto(user: User?) =
user?.let {
ReturnUserDto(user.id, user.username, user.email)
ReturnUserDto(user.id.toString(), user.username, user.email)
}

fun <T> Optional<T>.convertToNullable(): T? =
this.get()

fun <T> toResponseEntity(nullableEntity: T?): ResponseEntity<T> =
nullableEntity?.let {
ResponseEntity.ok(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

<!-- LOG everything at INFO level -->
<root level="info">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</root>

Expand Down
1 change: 0 additions & 1 deletion website-service/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

<!-- LOG everything at INFO level -->
<root level="info">
<appender-ref ref="RollingFile" />
<appender-ref ref="Console" />
</root>

Expand Down

0 comments on commit a3eb5b3

Please sign in to comment.