Skip to content

Commit 7dada40

Browse files
integrated handeling for isActive, lastLoginAt, createdAt, updatedAt
1 parent cf98c48 commit 7dada40

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package de.tum.aet.devops25.usersvc;
2+
3+
import org.openapitools.jackson.nullable.JsonNullableModule;
4+
import org.springframework.context.annotation.Bean;
5+
import org.springframework.context.annotation.Configuration;
6+
7+
import com.fasterxml.jackson.databind.ObjectMapper;
8+
import com.fasterxml.jackson.databind.SerializationFeature;
9+
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
10+
11+
@Configuration
12+
public class JacksonConfig {
13+
14+
@Bean
15+
public ObjectMapper objectMapper() {
16+
ObjectMapper mapper = new ObjectMapper();
17+
mapper.registerModule(new JavaTimeModule());
18+
mapper.registerModule(new JsonNullableModule());
19+
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
20+
return mapper;
21+
}
22+
}

user-svc/src/main/java/de/tum/aet/devops25/usersvc/UserController.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,14 @@ public ResponseEntity<LoginResponse> login(@RequestBody LoginRequest loginReques
119119
}
120120

121121
// Update lastLoginAt
122-
user.setLastLoginAt(OffsetDateTime.now());
123-
userRepository.save(user);
122+
OffsetDateTime loginTime = OffsetDateTime.now();
123+
System.out.println("=== LOGIN DEBUG ===");
124+
System.out.println("Before update - lastLoginAt: " + user.getLastLoginAt());
125+
user.setLastLoginAt(loginTime);
126+
System.out.println("Setting lastLoginAt in database to: " + loginTime);
127+
UserEntity savedUser = userRepository.save(user);
128+
System.out.println("After save - lastLoginAt: " + savedUser.getLastLoginAt());
129+
System.out.println("=== END LOGIN DEBUG ===");
124130

125131
// Generate JWT
126132
SecretKey key = Keys.hmacShaKeyFor(JWT_SECRET.getBytes());
@@ -145,6 +151,10 @@ public ResponseEntity<User> getProfile() {
145151

146152
UserEntity userEntity = userOpt.get();
147153

154+
System.out.println("=== PROFILE DEBUG ===");
155+
System.out.println("Retrieved from DB - lastLoginAt: " + userEntity.getLastLoginAt());
156+
System.out.println("=== END PROFILE DEBUG ===");
157+
148158
// Map to API User model
149159
User user = new User()
150160
.id(userEntity.getId())
@@ -156,6 +166,15 @@ public ResponseEntity<User> getProfile() {
156166
.createdAt(userEntity.getCreatedAt())
157167
.updatedAt(userEntity.getUpdatedAt());
158168

169+
// Handle lastLoginAt properly using the correct method
170+
if (userEntity.getLastLoginAt() != null) {
171+
// Use the method that takes OffsetDateTime directly
172+
user.lastLoginAt(userEntity.getLastLoginAt());
173+
System.out.println("Setting lastLoginAt to: " + userEntity.getLastLoginAt());
174+
} else {
175+
System.out.println("lastLoginAt is null in entity");
176+
}
177+
159178
return ResponseEntity.ok(user);
160179
}
161180

0 commit comments

Comments
 (0)